Push sensordata to MQTT

  • Platform information:
    • Hardware: RaspberryPi
    • OS: Debian 10
    • Java Runtime Environment: OpenJDK 1.8
    • openHAB version: 2.5.0

I have a Fibaro multisensor that reports temperature and light and I would like to push that data to my MQTT server so I can store values in my database.

My MQTT connection seems to be working, I get published data in my eventlog. But I want to publish to the topic. Almost all tutorials I find is either taking data from MQTT into OpenHAB or sending ON/OFF commands. The rule part of what I want to do is something like this:

rule "Send temperature to mqtt"
when
  Item Sensor1Temperature received command
then
  MQTT_data.sendCommand("temperature,sensor=DiningRoom value=<sensordata> <timestamp in epoch>")
end

MQTT_data is my channel for MQTT defined as this:

String MQTT_data "MQTT to influx" {channel="mqtt:systemBroker:LocalMQTT:tempData"}

The Sensor1Temperature is defined as this in my .things file and works fine

Number:Temperature Sensor1Temperature "Sensor1 temperatur" {channel="zwave:device:251be14f:node15:sensor_temperature"}

So if anyone has any pointers to an example I would appreciate it.

Try using a profile found in the doc’s here:

And your Thing definition?

Are you aware of the MQTT Action? https://www.openhab.org/v2.5/addons/bindings/mqtt.generic/#rule-actions

Are you aware that OH can write to InfluxDB directly? https://www.openhab.org/v2.5/addons/persistence/influxdb/

Normally that would make sense but in this case the original Channel is using a UoM and OP need to also supply the timestamp.

Sorry for slow response, haven’t had the time this week have a look at this.

The MQTT Action looks promising, I will give it a try.

The InfluxDB presistance module is probably not what I want, the sensor readings will end up in Grafana in the end so I want to properly format the data.

Just about everyone in this forum who uses InfluxDB or MySQL users Grafana for charting. I do this myself with nothing between OH and InfluxDB.

It’s a time series database, how much additional formatting do you require?

Search the forum for graphana and you will see dozens of examples people are using just oh persistence and graphana.