diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/README.md b/bundles/org.openhab.binding.mqtt.homeassistant/README.md
index 6a6a74f661744..ff5fb7cc4f889 100644
--- a/bundles/org.openhab.binding.mqtt.homeassistant/README.md
+++ b/bundles/org.openhab.binding.mqtt.homeassistant/README.md
@@ -17,19 +17,17 @@ You can also manually create a Thing, and provide the individual component topic
- [Binary Sensor](https://www.home-assistant.io/integrations/binary_sensor.mqtt/)
- [Button](https://www.home-assistant.io/integrations/button.mqtt/)
- [Camera](https://www.home-assistant.io/integrations/camera.mqtt/)
- JSON attributes and Base64 encoding are not supported.
+ Base64 encoding is not supported.
- [Climate](https://www.home-assistant.io/integrations/climate.mqtt/)
- [Cover](https://www.home-assistant.io/integrations/cover.mqtt/)
- [Device Trigger](https://www.home-assistant.io/integrations/device_trigger.mqtt/)
-- [Fan](https://www.home-assistant.io/integrations/fan.mqtt/)
- JSON attributes are not supported.
+- [Fan](https://www.home-assistant.io/integrations/fan.mqtt/)
- [Light](https://www.home-assistant.io/integrations/light.mqtt/)
- [Lock](https://www.home-assistant.io/integrations/lock.mqtt/)
- [Number](https://www.home-assistant.io/integrations/number.mqtt/)
- [Scene](https://www.home-assistant.io/integrations/scene.mqtt/)
- [Select](https://www.home-assistant.io/integrations/select.mqtt/)
-- [Sensor](https://www.home-assistant.io/integrations/sensor.mqtt/)
- JSON attributes are not supported.
+- [Sensor](https://www.home-assistant.io/integrations/sensor.mqtt/)
- [Switch](https://www.home-assistant.io/integrations/switch.mqtt/)
- [Update](https://www.home-assistant.io/integrations/update.mqtt/)
This is a special component, that will show up as additional properties on the Thing, and add a button on the Thing to initiate an OTA update.
diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Camera.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Camera.java
index 6bfe3ad98b2bb..58351a2eee2e7 100644
--- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Camera.java
+++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Camera.java
@@ -13,10 +13,14 @@
package org.openhab.binding.mqtt.homeassistant.internal.component;
import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.mqtt.generic.values.ImageValue;
+import org.openhab.binding.mqtt.generic.values.TextValue;
import org.openhab.binding.mqtt.homeassistant.internal.ComponentChannelType;
import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
+import com.google.gson.annotations.SerializedName;
+
/**
* A MQTT camera, following the https://www.home-assistant.io/components/camera.mqtt/ specification.
*
@@ -26,7 +30,8 @@
*/
@NonNullByDefault
public class Camera extends AbstractComponent {
- public static final String CAMERA_CHANNEL_ID = "camera"; // Randomly chosen channel "ID"
+ public static final String CAMERA_CHANNEL_ID = "camera";
+ public static final String JSON_ATTRIBUTES_CHANNEL_ID = "json-attributes";
/**
* Configuration class for MQTT component
@@ -37,6 +42,11 @@ static class ChannelConfiguration extends AbstractChannelConfiguration {
}
protected String topic = "";
+
+ @SerializedName("json_attributes_template")
+ protected @Nullable String jsonAttributesTemplate;
+ @SerializedName("json_attributes_topic")
+ protected @Nullable String jsonAttributesTopic;
}
public Camera(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) {
@@ -46,6 +56,14 @@ public Camera(ComponentFactory.ComponentConfiguration componentConfiguration, bo
buildChannel(CAMERA_CHANNEL_ID, ComponentChannelType.IMAGE, value, getName(),
componentConfiguration.getUpdateListener()).stateTopic(channelConfiguration.topic).build();
+
+ if (channelConfiguration.jsonAttributesTemplate != null) {
+ buildChannel(JSON_ATTRIBUTES_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(), "JSON Attributes",
+ componentConfiguration.getUpdateListener())
+ .stateTopic(channelConfiguration.jsonAttributesTopic, channelConfiguration.jsonAttributesTemplate)
+ .build();
+ }
+
finalizeChannels();
}
}
diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Fan.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Fan.java
index ec10103926e80..1fab6a775142d 100644
--- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Fan.java
+++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Fan.java
@@ -48,6 +48,7 @@ public class Fan extends AbstractComponent implements
public static final String PRESET_MODE_CHANNEL_ID = "preset-mode";
public static final String OSCILLATION_CHANNEL_ID = "oscillation";
public static final String DIRECTION_CHANNEL_ID = "direction";
+ public static final String JSON_ATTRIBUTES_CHANNEL_ID = "json-attributes";
/**
* Configuration class for MQTT component
@@ -115,6 +116,10 @@ static class ChannelConfiguration extends AbstractChannelConfiguration {
protected int speedRangeMax = 100;
@SerializedName("speed_range_min")
protected int speedRangeMin = 1;
+ @SerializedName("json_attributes_template")
+ protected @Nullable String jsonAttributesTemplate;
+ @SerializedName("json_attributes_topic")
+ protected @Nullable String jsonAttributesTopic;
}
private final OnOffValue onOffValue;
@@ -195,6 +200,14 @@ public Fan(ComponentFactory.ComponentConfiguration componentConfiguration, boole
channelConfiguration.getQos(), channelConfiguration.directionCommandTemplate)
.inferOptimistic(channelConfiguration.optimistic).build();
}
+
+ if (channelConfiguration.jsonAttributesTemplate != null) {
+ buildChannel(JSON_ATTRIBUTES_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(), "JSON Attributes",
+ componentConfiguration.getUpdateListener())
+ .stateTopic(channelConfiguration.jsonAttributesTopic, channelConfiguration.jsonAttributesTemplate)
+ .build();
+ }
+
finalizeChannels();
}
diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Sensor.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Sensor.java
index 2320019b871d8..9060e063b5c1a 100644
--- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Sensor.java
+++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Sensor.java
@@ -36,6 +36,8 @@
@NonNullByDefault
public class Sensor extends AbstractComponent {
public static final String SENSOR_CHANNEL_ID = "sensor"; // Randomly chosen channel "ID"
+ public static final String JSON_ATTRIBUTES_CHANNEL_ID = "json-attributes";
+
private static final Pattern TRIGGER_ICONS = Pattern.compile("^mdi:(toggle|gesture).*$");
/**
@@ -96,6 +98,13 @@ public Sensor(ComponentFactory.ComponentConfiguration componentConfiguration, bo
buildChannel(SENSOR_CHANNEL_ID, type, value, getName(), getListener(componentConfiguration, value))
.stateTopic(channelConfiguration.stateTopic, channelConfiguration.getValueTemplate())//
.trigger(trigger).build();
+
+ if (channelConfiguration.jsonAttributesTemplate != null) {
+ buildChannel(JSON_ATTRIBUTES_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(), "JSON Attributes",
+ componentConfiguration.getUpdateListener())
+ .stateTopic(channelConfiguration.jsonAttributesTopic, channelConfiguration.jsonAttributesTemplate)
+ .build();
+ }
finalizeChannels();
}