-
Notifications
You must be signed in to change notification settings - Fork 13
ebusd mqtt fhem
I'm using FHEM as home automatisation server.
One of my FHEM's tasks is to receive and store informations about states and temperatures of my Weishaupt heating system published by ebusd.
In the past I polled these messages from FHEM with a 10-seconds-timer over an ECMD device connected to ebusd's tcp-command-interface.
Now I've found a better way to get the informations: ebusd's ability to connect a MQTT-broker and publish informations.
The latest version of ebusd is able to connect a MQTT-broker. (link)
I've tried a lot to get the best setup for my needs...
Here are the MQTT related options of ebusd I'm using:
-
--mqtthost=localhost
This is the default - the MQTT-broker is running on the same system. -
--mqttport=1883
This is the default MQTT-port. -
--mqtttopic=ebusd/%circuit/%name/%field
The default for this option is just to set the ebusd prefex, /%circuit/%name will be added automatically by ebusd. This means that ebusd publishes each of it's defined messages as single MQTT-topic containing all of the message's fields. The subscriber has to devide the message-structure to the single information he wants.
I am setting the topic path including the additional parameter %field. This means that ebusd publishes each single field of any defined message as single MQTT-topic. Now it is possible to subscribe a single field and so it is much easier to get the field's value. -
--mqttjson
I played around with this option to publish in JSON format. The disadvantage was that I had to post-process the received messages in FHEM to get the wanted information. I was using FHEM's expandJASON module.
Till now, I'm not using this option.
The MQTT device provides the connection to the MQTT-broker.
My definition in FHEM looks like this:
defmod Mosquitto MQTT localhost:1883
attr Mosquitto room Mosquitto
The subscribtion of a MQTT-topic is done by FHEM's module MQTT_DEVICE. The definition in FHEM for the subscription of the topic ebus/global/uptime looks like this:
defmod mqtt.ebusd.global.uptime MQTT_DEVICE
attr mqtt.ebusd.global.uptime IODev Mosquitto
attr mqtt.ebusd.global.uptime room Mosquitto
attr mqtt.ebusd.global.uptime subscribeReading_value ebusd/global/uptime
attr mqtt.ebusd.global.uptime stateFormat value
attr mqtt.ebusd.global.uptime event-on-change-reading value
Lets have a closer look to the definition:
defmod mqtt.ebusd.global.uptime MQTT_DEVICE
attr mqtt.ebusd.global.uptime IODev Mosquitto
attr mqtt.ebusd.global.uptime room Mosquitto
This is the standard, nothing special to explain.
attr mqtt.ebusd.global.uptime subscribeReading_value ebusd/global/uptime
The attribute subscribeReading defines the MQTT-topic to subscribe.
!Attention!: the name "value" after the underscore "_" of the attribute defines the target reading the MQTT_DEVICE copies the received data to. In this case the name of the reading is "value". The reading "value" will contain the data.
attr mqtt.ebusd.global.uptime stateFormat value
The attribute stateFormat with the value "value" will display the reading "value" as state of the device.
attr mqtt.ebusd.global.uptime event-on-change-reading value
This attribute will setup the device to signal the change event only if the value of the reading "value" has changed.
I.e. if FHEM is logging this reading with FileLog new entries are only added when the reading's value has changed.
These are many attributes to set, many line to enter for each MQTT_Device...
So I created a kind of template of a MQTT_Device I just have to copy.
defmod mqtt.ebusd.template MQTT_DEVICE
attr mqtt.ebusd.template IODev Mosquitto
attr mqtt.ebusd.template event-on-change-reading value
attr mqtt.ebusd.template room Mosquitto
attr mqtt.ebusd.template stateFormat value
attr mqtt.ebusd.template subscribeReading_value ebusd/
Now you can copy the template in FHEM's command line and edit the subscription in the browser:
copy mqtt.ebusd.template mqtt.ebusd.hc1.Set.SetTemp