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? http://192.168.10.8/cgi-bin/json.cgi?set=on turns it on, http://192.168.10.8/cgi-bin/json.cgi?set=off turns it off, and http://192.168.10.8/cgi-bin/json.cgi?get=state returns the state {“state”:“on”} or {“state”:“off”}

default.items

Switch	KanKun1 "Wifi Switch" (GF_Living) { http=">[ON:GET:http://192.168.10.8/cgi-bin/json.cgi?set=on] >[OFF:GET:http://192.168.10.8/cgi-bin/json.cgi?set=off]" }

default.sitemap

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:http://192.168.10.8/cgi-bin/json.cgi?set=on] >[OFF:GET:http://192.168.10.8/cgi-bin/json.cgi?set=off] <[http://192.168.10.8/cgi-bin/json.cgi?get=state:30000:JSONPATH($.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"
when
	Item kankun3 received update ON
then
	sendHttpGetRequest("http://192.168.0.166/cgi-bin/relay.cgi?on")
end

rule "kankun3 OFF"
when
	Item kankun3 received update OFF
then
	sendHttpGetRequest("http://192.168.0.166/cgi-bin/relay.cgi?off")
end

Probably a terrible way to do things but it works…