Page 1 of 1

Read Kankun Wifi Smart switch status

Posted: Saturday 07 March 2015 22:23
by dijkdj
I have a nice Wifi Switch from Kankun.

I want to see its status. When I open http://192.168.1.54/cgi-bin/relay.cgi?state . I get "ON" back.

I need a sample LUA script that ask for the state of the wifiswitch and changes the status accordingly. I hope you can help me

Re: Read Kankun Wifi Smart switch status

Posted: Friday 01 May 2015 12:26
by wmn79
I bet you have already got it up and running, but otherwise, check the post here https://plus.google.com/112354434499704 ... SYcpXi3Y83. I used that to get the switches available in domoticz.

Re: Read Kankun Wifi Smart switch status

Posted: Friday 01 May 2015 22:31
by ThinkPad
Maybe you can use parts of my script: http://domoticz.com/forum/viewtopic.php ... 741#p40343
I do a kind of similar thing with a ESP8266 that serves a webpage.

Re: Read Kankun Wifi Smart switch status

Posted: Saturday 02 May 2015 0:48
by dijkdj
Hi Thinkpad. How can I update the switch status without really switching?

Re: Read Kankun Wifi Smart switch status

Posted: Saturday 02 May 2015 9:46
by ThinkPad
Not possible, as far as i know. But what happens when you switch it 'On' in Domoticz when it is already turned on? Nothing i guess?

Re: Read Kankun Wifi Smart switch status

Posted: Wednesday 06 May 2015 8:43
by dijkdj
That is true, nothing happens. Just want domoticz to show the same state as the switch is. The same way Hue lights do.

Re: Read Kankun Wifi Smart switch status

Posted: Saturday 03 September 2016 21:39
by madrian
Hi,

I am new here. This is easy as pie.

1,
Create a Dummy On/Off switch.

On Action:
http://192.168.1.22/cgi-bin/json.cgi?set=on
Off Action:
http://192.168.1.22/cgi-bin/json.cgi?set=off

2,
Create a bash script somewhere on your Domoticz server.

I put mine on my Raspberry Pi in /home/pi/ directory:


pi@raspberrypi:~/$nano /home/pi/domoticz_checkstatus.sh

Code: Select all

#!/bin/bash
#Adrian Mihalko - mihalko.eu
#

KANKUNIP="192.168.1.22"
DOMOTICZIP="192.168.1.14"

STATUS=$( curl "http://"$KANKUNIP"/cgi-bin/json.cgi?get=state" |  egrep -m 1 '"state"' | awk -F '"' '{ print $4 }')

#echo "$STATUS"

if [[ "$STATUS" == "on" ]]
then 
    #echo "Set switch status: ON"
    curl "http://"$DOMOTICZIP":8080/json.htm?type=command&param=udevice&idx=4&nvalue=1"
else 
    #echo "Set switch status: OFF"
    curl "http://"$DOMOTICZIP":8080/json.htm?type=command&param=udevice&idx=4&nvalue=0"
fi
Modify IP's......

Set correct chmod:

pi@raspberrypi:~/$ chmod +x domoticz_checkstatus.sh

Now create a new crontab job and let run our script every minute:

* * * * * /home/pi/scripts/domoticz_checkstatus.sh

Done. :)

From now, If you turn off your Kankun elsewhere than in Domoticz, then switch status in Domoticz will be changed to off mode too.