Need help with a simple rule

I have a KanKun wifi smart plug and I have a switch setup to turn it on and off and it works great, but if I open the openHAB website on a different device the state of the switch always defaults to OFF, even if the switch is ON. How do I setup a rule to check the status of switch? turns it on, turns it off, and returns the state {“state”:“on”} or {“state”:“off”}


Switch	KanKun1 "Wifi Switch" (GF_Living) { http=">[ON:GET:] >[OFF:GET:]" }


Switch item=KanKun1

This the first thing I have setup with openHAB and it was straight forward until I needed to check for the state of the switch.

Any help would be greatly appreciated.

You have to set not only out but also in for http binding, something like

http="">[ON:GET:] >[OFF:GET:] <[$.state)]"

should do it, maybe you have to test another transformation service, like REGEX or Java Script.

Be aware, that the binding definition above calls the address every 30 seconds, so the item Status could be not up-to-date if you open the UI.

Normally the item status should be set to the last sent status from openHAB automatically, except you set autoupdate=false for this item (which you did not…), I have no idea why this does’nt happen…

Adding this here as it may help others. I struggled to get the http binding working with Openhab2, as such I was able to get the switches working through rules.

rule "kankun3 ON"
	Item kankun3 received update ON

rule "kankun3 OFF"
	Item kankun3 received update OFF

Probably a terrible way to do things but it works…