Taking hardware switch feedback

Hello guys,

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.

Thank you for your reply. will changing the state also send the command bound to the item? or will just change the state in the GUI?

Hey Rich,

I got this settings from an another topic,
Switch or_office_music_status “Music Switch [MAP(switch.map):%s]” (Music) {http=">[ON:POST:] >[OFF:POST:] <[]", autoupdate=“false”}
But do no understand how to use the XSLT thing in the inbound massage.

state just changes the state within OH. command will cause the new state/command to be forwarded to the bindings.


I tried following,
item setting,

Switch DL_Series_9       "Device 7"       		(gDL, Lights)["Switchable"]{ http=">[ON:GET:] >[OFF:GET:]" }
Switch DL_Series_10       				(gDL, Lights){http="<[]"}

Rules setting:

rule "demo feedback 1"
		Item DL_Series_10 received command
		if(received command == ON)
			 postupdate(DL_Series_9, ON) 
			 postupdate(DL_Series_9, OFF)

Transformation: saved in the folder : transform as Switcch1.map


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.

Hey there,

Can anyone please give some suggestion??
Thanks in advance.