[SOLVED] Mqtt Temp and humidity setup

Im trying to setup temp and humidity on my OH and Im stuck.

I bought a ESP8266 and a DHT11 and successfully flashed it with a temp, humi and mqtt config

The ESP its talking to my broker:
$ mosquitto_sub -h localhost -t WeatherStation
temperature: 20.00 C ;Humidity: 26.00%
temperature: 20.00 C ;Humidity: 32.00%
temperature: 20.00 C ;Humidity: 27.00%
temperature: 20.00 C ;Humidity: 26.00%

OH and the ESP are connected:
openhabian@openHABianPi:/var/log/mosquitto$ tail -f *
1513723790: New connection from on port 1883.
1513723790: New client connected from as ESP8266Client-f39e (c1, k15).
1513723794: New connection from on port 1883.

Number humidity “humidity [%.1f%%]” {mqtt="<[localhost:WeatherStation:state:default]"} <<< Im lost here


Frame label=“Temp_humdity” {
Text item=humidty

The mqtt.cnf is default, everything is commented out except the broker (localhost.url)

Thanks for any help!


If your payload on the topic WeatherStation is:
temperature: 20.00 C ;Humidity: 26.00%

Then You’ll be needing a string item, or to do a transform on the values to pull out the two numbers.

What you should actually be doing with your ESP8266 is posting:
WeatherStation\temperature then the value of 20.00
WeatherStation\humidity then the value of 26.00
It’s two publish calls to mqtt.

So if you did your sub again as
mosquitto_sub -h localhost -t WeatherStation# -v
you should see:
WeatherStation\temperature 20.00
WeatherStation\humidity 26.0

That;s if you want to roll your own code for MQTT publishing.

But I’d recommend using the Homie framework. I have a blog post here where I do this + a contact sensor. But you can see the temp/humidity code. https://www.geekzone.co.nz/davidcole/8960

1 Like

Thanks everyone! Got it figured out. The above to post were of great help.


what is the solution?

I am able to see Humidity and Temperature value at Broker… but values are not appearing in my openhab panel.

my OH & Broker are running on same raspberry pi and DH11 sensor configured on ESP8266.

Even, I can see temperature in my panel ( even though it is shown 2-4 Degree less :slight_smile: ), but Humidity value s not reflecting.

Number humidity {mqtt="<[MQTT:/feeds/humidity:state:default]"}

#Number temperature "temp [%.1f]" {mqtt="<[MQTT:/feeds/temperature:state:default]"}

sitemap TestSiteMap label="Test Site-Map"
                Switch item=test label="LED"
                Text item=Temperature valuecolor=[>35="orange",>20="green",<=20="orange"]
                Text item=Humidity

Please suggest

It is not good practice to have your MQTT topics starting with /
it should be feeds/temperature NOT /feeds/temperature

Hello guys,

I’m trying to set up a BME280 Temperature, Pressure and Humidity sensor to readout on OpenHab2. I have been playing with the set u for a few days but fail to get the sensor readings to display in OH…any pointers and do i have to process the sensor data somewhere and pass it on to OH or can the mqtt read the data and separate it automatically within OH?

This it the ESP-01 consol out put from the BME280 (ESP-01 running Tasmota and set up as a generic module with SDA and SCL on GPIO0 and GPIO2) and outputs readings every 5 minutes:

06:29:24 MQT: tele/mastertemp/STATE = {"Time":"2018-05-17T06:29:24","Uptime":"0T00:40:17","Vcc":3.555,"Wifi":{"AP":1,"SSId":"ChrisS7","RSSI":96,"APMac":"62:F1:89:56:90:BC"}}
06:29:24 MQT: tele/mastertemp/SENSOR = {"Time":"2018-05-17T06:29:24","BME280":{"Temperature":23.2,"Humidity":70.6,"Pressure":1016.3},"TempUnit":"C"}

Here is my Sitemap settings:

            Text item=Sensor_MasterTemperature          label="Master Temperature"    icon="temperature"
            Text item=Sensor_MasterHumidity             label="Master Humidity"       icon="humidity"
            Text item=Sensor_MasterPressure             label="Master Pressure"       icon="pressure"

Here is my Items file:

Number   Sensor_MasterTemperature    "Master Bedroom [%.1f °C]"   <temperature> (gSensorTemperature)  { mqtt="<[broker:tele/mastertemp/sensor:state:default]" }
Number   Sensor_MasterHumidity        "Master Bedroom [%.1f %%]"   <humidity>    (gSensorHumidity)     { mqtt="<[broker:tele/mastertemp/sensor:state:default]" }
Number   Sensor_MasterPressure        "Master Bedroom [%.1f bar]"  <pressure>    (gSensorPressure)     { mqtt="<[broker:tele/mastertemp/sensor:state:default]" }

Here is the SONOFF module Info page:
MQTT Host "my ddns/ip address
MQTT Port 1883
MQTT Client & Fallback Topic DVES_CFCC3E
MQTT User openhabian
MQTT Topic mastertemp
MQTT Group Topic sonoffs
MQTT Full Topic cmnd/mastertemp/

Also monitoring MQTT.fx and subscribed to the topic: “tele/mastertemp/SENSOR” I see this output every 5 minutes:


Any assistance would save the last few hairs that I have left :slight_smile:
Than you & regards

You need to use the JSONPATH transform to extracct values from the json sent by you tasmota. And the topics are case sensitive.

Number   Sensor_MasterTemperature    "Master Bedroom [%.1f °C]"   <temperature> (gSensorTemperature)  { mqtt="<[broker:tele/mastertemp/SENSOR:state:JSONPATH($.BME280.Temperature)]" }
Number   Sensor_MasterHumidity       "Master Bedroom [%.1f %%]"   <humidity>    (gSensorHumidity)     { mqtt="<[broker:tele/mastertemp/SENSOR:state:JSONPATH($.BME280.Humidity)]" }
Number   Sensor_MasterPressure       "Master Bedroom [%.1f bar]"  <pressure>    (gSensorPressure)     { mqtt="<[broker:tele/mastertemp/SENSOR:state:JSONPATH($.BME280.Pressure)]" }

You are my hero yet again Vincent!! cant thank you enough for this an all your other help :):grinning:

No problems,
This was in the docs, though…
Please mark the thread as solved. Thanks

Sure but how to do that as I cant find any options to set a “Solved” flag…?

Mark the reply that solved your problem with the solved tag
Little tick box
It’s located just under the reply


Hi Vincent,

No tick marks on the post that solved the question…see screen shot?

image removed to save space on the server.

I realize now that you are not the one that created the topic a while ago. That’s why, only the topic creator gets a tick mark…
Enjoy openHAB


Hi VIncent, after a couple of days trialing the new room sensor settings in OH I noticed that when a sensor is offline or down that the UI does not update the readings again and continues to display the last readings from the sensor until a system reboot and then all sensor readings are back to a null state until any active sensors send out their data. How would I make the UI automatically update ? would it be something like autoupdate=“true” (although i tried this and it doesnt seem work in this case.

{ mqtt="<[broker:tele/mastertemp/SENSOR:state:JSONPATH($.BME280.Temperature)]", autoupdate="true" }


OH will display the last value received

To restore the values when OH restarts you will need to set up persistence (I recommend mapdb for the restore at startup)

The autoupdate option is for another purpose. You don’t need it in this case.

Why does your sensor goes off line??
You don’t need to restart the system, just the sensor

If you are receiving values from your sensor every 5 minutes for example, you could install the expire binding and set-up the binding to set the value to 0 after 11 minutes just in case you missed 1 broadcast (Unlikely with mqtt but your never know)

Install the expire binding and your item would be:
{ mqtt="<[broker:tele/mastertemp/SENSOR:state:JSONPATH($.BME280.Temperature)]", expire="11m, 0" }
After 11 minutes if no data has been received the state will be 0
Then you will know that your sensor has gone offline and needs a kick.

But why does it goes offline in the first place?


Thank you Vincent,

I’m still in “testing mode” for my system, so I’m working on setting up all the UI and adding sensors and switches etc while I’m away from home. So I have set up the room sensors in the UI and here with me I have 5 x BME280, power supplies, ESP-01 that I will assembly in to each room climate sensors to be installed when I next return home. After starting up these 5 sensors to test the new UI additions I see that the readings are retained in the UI after I have powered of the test sensors.
Actually you hit the nail on the head…I want the system UI to be able to show me if any of them go offline or are down…the Expire binding will do the job. You helped me with that EXPIRE in my other post to have a timed switch so I should have thought about that…but the more I do the more I learn.
Thank you once again :grinning:

THanx for the heads up about mapdb!

I did some searching on this topic, so in general all i have to do is install the mapdb persistence and then add the file in to the “persistence” folder like this:

Strategies {
        default = everyUpdate

Items {
        // persist all items on every change and restore them from the db at startup
        * : strategy = everyChange, restoreOnStartup

Will that also stop the other issue that I have always had on a system reboot that all the lights and power sockets all restart with the bulb and socket icons being “on” state?

The lights and socket will be restored to the state they were at last reboot

The Items will be restored to their previous state but that state will not be punished it to the devices so I don’t think this will solve that problem.

  1. Are you using QOS of 1 or 2 in the mqtt settings of either the device or OH?
  2. Are you using retain true in the mqtt settings of either the device or OH?

Restarting OH should not affect the states of your devices.

If you wanted it to you can use a system started rule to send the command so your lights match the restored state. Put them all in agreement Group and use a rule like:

rule "Restore lights"
    System started
    Lights.members.forEach[ light | light.sendCommand(light.previousState) ]

Another thing to watch out for is the restoreOnStartup will not restart the expire timers. Use the same role as above with

ExpireItems.members.forEach[ i | i.postUpdate(i.state) ]