I have the following setup.
OH2 running on Raspberry pi3.
Sevral relays connected to ESP.
Right now I can toggle the state of the relay from the openhab GUI, and from the Hardware switch(3-way switch) as well, but I want to take feedback in GUI, if the Equipment is turned ON or OFF from the hardware switch.
I would like to use HTTP binding for the same.
I can send the state of the hardware switch by requesting a HTTP request from the browser.
So, I need openhab to send the request to my esp server after every 1 second, and to change the state of the item according to the message received.
Thanks in advance for the help.
Typically when users on this forum are using ESP they use MQTT for communication with the device and then the device can publish the change in state on a STATE topic.
HTTP makes this much more complicated because you have to implement polling (like you describe) or implement HTTP POST and PUT commands on the ESP.
There are many firmwares for ESPs that support MQTT out of the box, ESPeasy is one I think.
To address your specific questions, look at the HTTP binding and/or the sendHTTP* Actions. With the Binding you can configure it to poll every second and with the Actions you can write a Rule that triggers every second.
Second this. I have many esp’s doing switches, contacts, motion, heatpumps etc. and MQTT is super fast, easy and lightweight. Very very reliable IMO.
I use the subpubclient library on esp and arduino eth shields. It is a little more advanced than some of the options like ESPeasy but VERY flexible and powerful if you are halfway decent with code/googling.
rule "demo feedback 1"
when
Item DL_Series_10 received command
then
if(received command == ON)
{
postupdate(DL_Series_9, ON)
}
else
{
postupdate(DL_Series_9, OFF)
}
end
Transformation: saved in the folder : transform as Switcch1.map
ON=1
OFF=0
This does not work, and when I call the link from the browser it sends 0 and 1 accordingly.
Can you guys suggest any changes in the code.
Plus one more question is I used DL_Series_10 without the label but still it shows in my GUI.