I would like to add a sensor based on an ESP to my openHAB2 installation. The sensor sends this topic/message to the mosquitto-broker on my RasPi 3:
/esp12 T=18.50
/esp12 H=47.10
/esp12 HIC=17.64
The MQTT broker is running after the installation via PaperUI->Configuration->Things->Add
MQTT Broker ONLINE
MQTT Broker
mqtt:broker:mqtt-broker
To the MQTT item I added a channel in PaperUI
ESP1 Temperatur
mqtt:broker:mqtt-broker:ESP1_TEMP
with these settings
Topic /esp12
Separator character =
And finally I set a mqtt.sitemap
sitemap mqtt {
Frame {
Default item=ESP1_TEMP
}
}
After saving the sitemap, this is the logfile:
2019-01-24 21:29:34.588 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘mqtt.sitemap’
But there is no output if I look on mqtt sitemap in BasicUI. What do I miss??? Please give me instructions hot to configure my openHAB2 in order to display the temperature and humidity from this sensor. If there is a better format of the message payload, please tell me, I know how to modify the ESP firmware.
You shouldn’t add channels to the broker thing, since this one is acting as a bridge (it is the bridge.
For your ESP you should have added a generic mqtt thing with the three channels, the thing should connect to the bridge.
All that is Documented.
You didn’t show any created item which has a linked channel. You need them in order to show anything on a sitemap.
Remove this channel. This is a channel on the broker thing. It won’t work.
You need to add an MQTT generic thing
Settings - Things - + - MQTT Binding - MQTT Generic Thing
Name it
Give it a human readable ID
Open it
Add a text/string channel
stateTopic = /esp12
Save
Create a string item called esp12_String
Link it to the channel
Create a number item called esp12_Temp
Create a number item called esp12_Hum
Create a number item called esp12_HIC
Create a rules
A files in the rules folder called esp12.rules
rule "esp12 transform"
when
Item esp12_String changed
then
val esp12String = esp12_String.state.toString
val valueType = esp12String.split("=").get(0)
val value = esp12String.split("=").get(1)
if (valueType == "T") esp12_Temp.postUpdate(value)
if (valueType == "H") esp12_Hum.postUpdate(value)
if (ValueType == "HIC") esp12_HIC.postUpdate(value)
end
Now I would really recommend that you change your ESP code to change the topics that it sends.
For temp use the topic esp12/temp and the number only as payload
For hum use the topi esp12/hum…
…
Then you can create 3 number channels in your MQTT thing, each with the relevant state topic
and link the channel to the relevant item directly.
No need for the string channel and the string item
No need for the rulle
Thanks a lot for the quick reply!!! (@vzorglub and @opus
I think now I got it. The problem was the confusion I have about things, bindings, items and all together. I know it in principle, but I think I did not get it completely into my brain, deep enough…
What did I do to get if working?
First I changed the topic/payload of MQTT to give
/esp12/T 18.40
/esp12/H 47.60
/esp12/HIC 17.54
Then added the thing in PaperUI as mentioned and created 3 channels of type Number and added them in the sitemap, which reads now:
sitemap mqtt {
Frame {
Default item=mqtt_topic_ESP1_ID_ESP1_TEMP label=“Temperature [%.1f °C]”
Default item=mqtt_topic_ESP1_ID_ESP1_H label=“Humidity [%.1f %%]”
Default item=mqtt_topic_ESP1_ID_ESP1_HID label=“Humidity Index [%.1f °C]”
}
}