If you are interested to publish all item states from openHAB2 to the MQTT Broker, you could use the MQTT-EventBus solution:
- Setup your broker connection with the
$OPENHAB_CONF/services/mqtt.cfg
($OPENHAB_CONF
=/opt/openhab/conf
in your case)
mqb.url=tcp://localhost:1883
mqb.clientId=openhab
- Define within
$OPENHAB_CONF/services/mqtt-eventbus.cfg
your publishing settings
(and optionally, your subscribing):
broker=mqb
statePublishTopic=openhab/out/${item}/state
commandPublishTopic=openhab/out/${item}/command
stateSubscribeTopic=openhab/in/${item}/state
commandSubscribeTopic=openhab/in/${item}/command
This will send the state of every $item to a separate topic. Keep in mind that this is a massive link. It will “connect” the entire Event Bus of openHAB2 to the Broker.
For persistence, I recommend using a 2-tier solution as @rlkoshak wrote here: Good Tutorial On Persistence (RRD4J and JDBC-MYSQL)? - #5 by rlkoshak.
- mapdb for everyChange & restoreOnStartup (set as the default persistence service)
- Influxdb for everyChange to be used with Grafana
- Optionally, a 3rd tier with MySQL would be nice also but heavy
MQTT persistence doesn’t really store historical data. It’s only used for publishing states of selected items to the broker.
It has the advantage of fine tuning the mqtt.persist
to define a strategy of what to “persist” (put the items for which you want to publish the state in a group, then persist the group members)