Hello everybody, I’m able to start with OpenHAB2 and follow the official tutorials, but…
I’m trying to do the following, and I’m not sure where to start or is it even possible…
I have a DHT11 sensor connected to an Arduino and I can get readings on the Raspberry Pi through USB pySerial connection, OpenHAB2 is configured and everything seems to work even the myopenhab account,
now, is it possible to add the sensor as a “thing” and get its readings remotely through myopenhab? and how?
Probably easier to get your python code to push the dht11 values to mqtt and then use the mqtt binding to read it. Something I’ve done a lot on my OH v1 system.
Ok, so I followed your suggestion and now I have temperature and humidity readings being published to a MQTT topic every two seconds and I can read them from MQTT.fx
Also I have “MQTT Binding” installed in openHAB2,
But not sure where to go from here, How can I add a “thing” that displays those readings in openHAB2?
So you added the mqtt binding, then went and made an item (in a config file file) and then made a entry in a sitemap?
Or did you get access to the mqtt item from somewhere else (I might learn off you here).
ie: items:
Number bm2_humidity “Humidity [%.1f%%]” (g_bm,g_bm2,g_bm2_humidity,g_humidity) {mqtt=“<[frodo:3a7c72e125cc/humidity:state:default]”}
frodo being the name of my mosquitto broker.
then in the home.sitemap I have:
Text item=bm2_humidity icon=“water”
But this means if I go to BasicUI I have to add sitemap=home - or set the default to my home sitemap
What I’ve done was:
0- Installed MQTT Binding from paperUI (as well as bunch of other bindings like Yahoo weather and the cloud connector)
1- used “uugear” to be able to send sensors readings from Arduino to Pi (USB connection), then “paho.mqtt” to be able to publish the readings to a MQTT topic from within a single python script
2- I made sure mosquitto is running, and I can publish and subscribe successfully (used MQTT.fx for this), I configured mqtt.cfg from /etc/openhab2/services by adding the line
aNameForTheBroker.url=tcp://mosquittoServerIPaddress:1883
3- then I added an .item file in /etc/openhab2/items with the following lines
Number temperature “Temperature [%.1f]” {mqtt="<[aNameForTheBroker:temp_mqtt:state:default]"}
Number humidity “Humidity [%.1f]” {mqtt="<[aNameForTheBroker:hum_mqtt:state:default]"}
Number dist “Distance [%.1f]” {mqtt="<[aNameForTheBroker:dis_mqtt:state:default]"}
4- Tried to add things using config files but couldn’t do that, so I used the Yahoo Weather thing instead, and linked its channels to the items I made earlier,
5- ran the python script, and voila… control page started to update accordingly…
I restarted the Pi and now openHAB2 doesn’t seem to be able to pick the published data like it did before.
bad luck I guess, not sure what’ve done wrong…
Never missed with sitemaps as I don’t really understand them yet…
This is where you’ve started to go off track. The MQTT is an OH1.x binding, therefore it doesn’t work with the OH2 concept of Things (and therefore you can’t use PaperUI for it).
After step 3 you should be able to see the updates come through in the log, you will need to create a sitemap if you wish to have a UI to see these values.
I found the problem preventing openHAB2 from reading the published values after a restart of the Raspberry pi (by examining the log thanks to “danielwalters86”)…
It was just that openHAB was starting before mosquitto and therefore wasn’t able to open the MQTT connections, simply by restarting openHAB while mosquitto is running solves the problem…