-
Notifications
You must be signed in to change notification settings - Fork 7
HOWTO: MQTT Sensors
This page describes legacy code. To find out how it is currently done, jump here.
IMPORTANT: see Current vs. Legacy Code Base
Configuration below pertains to sensors conforming to DZ Edge Device specification. If you're just starting, you probably want to use the ESPHome or Home Assistant integration instead. Also, take a look at MQTT: Useful Tools, Bits and Pieces.
Configuring MQTT sensors is similar to other factory based configurations (1-Wire and XBee). Here's a working example:
<!-- MQTT Device Factory. You can have more than one if you have several brokers. -->
<bean id="mqtt-device-factory"
class="net.sf.dz3.view.mqtt.v1.MqttDeviceFactory"
destroy-method="powerOff">
<!-- Broker host -->
<constructor-arg index="0" value="mqt.broker.host" />
<!-- Root topic - publish -->
<constructor-arg index="1" value="/hcc/instance" />
<!-- Root topic - subscribe -->
<constructor-arg index="2" value="/hcc/sensor" />
</bean>
<bean id="mqtt_sensor-289E0279A201039B" factory-bean="mqtt-device-factory"
factory-method="getSensor">
<constructor-arg value="289E0279A201039B" />
</bean>
Below is the JSON that DZ expects. mandatory fields are entity_type=sensor
, name
, and
signal
. DZ doesn't care about the topic as long as it is under
${root-topic-subscribe}/
- it parses JSON for data.
{
"device_id": "ESP8266-00621CC5",
"entity_type": "sensor",
"name": "289E0279A201039B",
"signal": 23.87,
"signature": "T289E0279A201039B"
}
You might want to explore hcc-esp32 if you're feeling adventurous. Or, rather, ESPHome, or, as a last resort, Home Assistant integrations.