Thermometer

Hello boys, I need realize a thermometer to misure water temperature, I want use esp8266 and send result over wifi to openhab installed on a raspberry, someone can suggest me the right way to proceed ,
Thank

Make your ESP do a POST call to your OpenHAB REST API:

Sensor -> ESP -> POST -> OpenHAB

Or have your OpenHab poll and make a GET to ESP (you need to setup the ESP with a web server):

OpenHAB -> GET -> ESP

1 Like

I consider polling as not state-of-the-art and as the only way to go, if there’s not a direct one! :wink:
I’d add my personal favourite especially, as it is very lightweight and fast: MQTT

So @Stefano_Bordini:

  1. the REST API: https://docs.openhab.org/configuration/restdocs.html
  2. the MQTT: https://docs.openhab.org/addons/bindings/mqtt1/readme.html

ad 1)
it is simple to do, just POST the value to the itemname

Number My_Item "Water temperature [%.1f °C]"

curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "24.4" "http://ip_openHAB_host:8080/rest/items/My_Item"

this one updates the Item My_Item with 24.4.

ad 2)
you have to setup an MQTT server (if not already running) and configure openHAB to use that one.
and you use on your ESP

Number My_Item "Water temperature [%.1f °C]"   { mqtt="<[broker:openHAB/sensors/My_Item:state:default]" }

mosquitto_pub -h ip_openHAB_host -u 'user' -P 'pass' -t 'openHAB/sensors/My_Item/state' -m '24.4'

this one updates the Item My_Item with 24.4.

1 Like

He’s talking about an ESP8266, a microcontroller. There won’t be curl there :wink:

1 Like

just for demonstration - taken out of the docs… :wink:

I want try to use MQTT i do make server MQTT in Raspberry or in ESP8266?
Sorry my newbies

No biggie.
See here. Seems like a decent for bringing MQTT and ESP together:

And then both parties (openHAB and your sensor) have to use MQTT server (called broker). If you’re running oh2 on a pi and using openHABian, just go sudo openhabian-config and there you can install ‘mosquitto’, which is said broker.

I’m using MQTT a lot, because it is lightweight and there many devices talking MQTT ootb. I’m running my broker on my NAS (Synology, there’s a package for mosquitto)

For a start into MQTT:


and

1 Like

Work thanks to all,last question is possible connect 2 different esp8266 to the same broker

yes, of Course! But please read the whole MQTT Essentials, it will tell you: every client has to have a different clientID. And if the esp8266 is attached to a sensor or actuator, please make sure, each one has a different topic, so you can distinguish them.

tnx