PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)

The only thing i could think of, is that i not provide the Target variable messes with things

I’ve sent my data dump to ImperiHome at their request so they can see why it doesn’t and what they can do on their end. We may get a clue from that.

I got the fourth unit working but I had to allocate it a different IP address, it simply refused to work with the one I tried.[/quote]

Update: The fourth switch is a case of the incredible shifting MAC. I got it working at the address I wanted. This morning I moved the switch to another room and it stopped working. Fiddling with my router showed the IP did not get allocated because the switch had changed its MAC!!! I unplugged/plugged back in and the MAC reverted the “correct” value and it got the right IP address. So I unplugged it again and when I plugged it back in the MAC had once again shifted to the earlier value so the IP did not get allocated.

I’ve written to the eBay supplier in hopes I can get a replacement.

That is odd indeed, i have reset and hard-reset my test switch serval times,
The mac address never changed.
But openwrt supports virtual mac adresses which you can set, or even better use client id instead of mac

for static IP

ssh to the Switch:

edit /etc/config/network

it should look like this

config interface 'wwan'
        option proto 'dhcp'

remove "option proto ‘dhcp’

and put somethings like this:

config interface 'wwan'
        option proto 'static'
        option ipaddr '1.1.1.1'
        option netmask '255.255.255.0'

where 1.1.1.1 is the ip adress you would like it to get :wink:

or to hard-set the mac adress
edit /etc/config/wireless
and add macaddr option

config wifi-iface
        option device 'radio0'
        option macaddr xx:xx:xx:xx:xx:xx

Thanks.

It is strange as the other three appear to be fine.

I’m not a UNIX type so I appreciate the step-by-step :slight_smile: I may do that depending on whether or not the vendor helps out :slight_smile:

[quote=“nullx8, post:43, topic:188358”]That is odd indeed, i have reset and hard-reset my test switch serval times,
The mac address never changed.
But openwrt supports virtual mac adresses which you can set, or even better use client id instead of mac

for static IP

ssh to the Switch:

edit /etc/config/network

it should look like this

config interface 'wwan'
        option proto 'dhcp'

remove "option proto ‘dhcp’

and put somethings like this:

config interface 'wwan'
        option proto 'static'
        option ipaddr '1.1.1.1'
        option netmask '255.255.255.0'

where 1.1.1.1 is the ip adress you would like it to get :wink:

or to hard-set the mac adress
edit /etc/config/wireless
and add macaddr option

config wifi-iface option device 'radio0' option macaddr xx:xx:xx:xx:xx:xx [/quote]

I ended up doing this, setting a Fixed IP and freezing the MAC

Thanks
John

Quote from: stefaanbolle on August 10, 2015, 11:33:07 pm
Could your plugin be modified so it can read status/control openhab switches, which can also be controlled/read with REST calls?
This would make an excellent link from Vera to Openhab (and not vice versa as existing today via an openhab binding)

thats a good idea … i played with openHAB … but iam allergic to Java (unless its in my Cup)
i made something semilar already as vera controller … (php based)

i’ll install openHAB somewhere to test …
give me a few days :wink:

Hi Nullx8
Did you have any change to look into controlling Openhab items via REST API already?

could you replace this files on your vera and test with Imperihome of it does show now properly ?

Sorry, no joy, still doesn’t see the device.
John

Can somebody help me… I don’t really know what I am doing wrong…

I use WinSCP in SCP mode
1- I create the directory in /www /cgi-bin
2- I create this file json.cgi with Win SCP and copy the following…


#!/bin/sh
echo “Content-Type: application/json”
echo “Cache-Control: no-cache, must-revalidate”
echo “Expires: Sat, 26 Jul 1997 05:00:00 GMT”
echo

RELAY_CTRL=/sys/class/leds/tp-link:blue:relay/brightness
LINKQ = iw dev wlan0 link | grep signal

case “$QUERY_STRING” in
state)
case “cat $RELAY_CTRL” in
0) STATE=“0”
;;

  1. STATE=“1”
    ;;
    esac
    ;;
    on)
    echo 1 > $RELAY_CTRL
    STATE=“1”
    ;;
    off)
    echo 0 > $RELAY_CTRL
    STATE=“0”
    ;;
    esac
    echo “{"state":$STATE,"link":"iw dev wlan0 link | grep signal ","uptime":"23:50"}”

3- I checked the wireless file, here what I have…

/etc/config/wireless

config wifi-device ‘radio0’
option type ‘mac80211’
option hwmode ‘11ng’
option path ‘platform/ar933x_wmac’
option htmode ‘HT20’
list ht_capab ‘SHORT-GI-20’
list ht_capab ‘SHORT-GI-40’
list ht_capab ‘RX-STBC1’
list ht_capab ‘DSSS_CCK-40’
option disabled ‘0’
option country ‘CN’
option channel ‘1’

config wifi-iface
option device ‘radio0’
option network ‘wwan’
option ssid ‘XXXXXXX’
option mode ‘sta’
option encryption ‘psk2’
option key ‘XXXXXXX’

4- I checked /etc/config/network, here what I have…

config interface ‘loopback’
option ifname ‘lo’
option proto ‘static’
option ipaddr ‘127.0.0.1’
option netmask ‘255.0.0.0’

config globals ‘globals’
option ula_prefix ‘fd5a:5111:fb4a::/48’

config interface ‘lan’
option ifname ‘eth0’
option type ‘bridge’
option proto ‘static’
option ipaddr ‘192.168.10.253’
option netmask ‘255.255.255.0’
option ip6assign ‘60’

config interface ‘wwan’
option proto ‘static’
option ipaddr ‘192.168.1.XXX’
option gateway ‘192.168.1.1’
option netmask ‘255.255.255.0’

I did an update with my Vera Edge… to get the latest apps…

I create a device… and I put the IP adress… you can see in the files below what I have with the device…

NOTE: I can control the device with my iPhone… I can not with Vera Edge…

One more thing I like to talk about… as soon as I try to connect those small K switch… I loose my IP address from my router… instead I receive IP address from the switches… All my computers, cellulars, iPad loose their IP’s address… and received a bad IP giving by the switches 192.168.22.240 “I think” and a router dress 192.168.22.53 instead of 192.168.1.1. Even if I disconnect the switches and remove the apps from my I phone I still have that bug. The only way I can get it back on my network was to give a static IP and on the 2 PC’s I had to remove the network driver and reinstall it. I even did a factory reset on my router and I was given the same IP’s address… what a mess. I try to reconnect those switches two times and the problems came back each time…
Anybody knows anything about it…

Note: I try to connect threw a SSID from my router…

Hey Nullx8
Did you already have any change to look into controlling Openhab items via REST API?
I’m trying to sync openhab with vera switches by combining both bindings to 1 openhab switch, but the feedbacks of the nikobus binding are not correct.
The only option I see now is having the vera send immediate commands to openhab via the openhab REST interface.
For this I need a virtual vera switch which reads openhab switch statuses and writes openhab switch commands.

Null8x

Have you had a chance to consider why these things aren’t tracked in EvenTWatcher and populated in ImperiHome?

Pardon the “Blonde” moment here. Installing the plugin from the App Store under UI5 The requirements say
Requirements

  • UI5 only: akb-json need to be on the vera to parse json responses (use I_HttpSwitch1_UI5.xml)

Where do I find “I_HttpSwitch1_UI5.xml”

Thanks
Update:
Blonde moment gone and all working :slight_smile:

I received the switch, tried testing with plugin, use static IP in router, update both IP(Parma Tab) and Address(Variable Tab), shows offline,

however I’m able to control the switch from its native app doesn’t work with Vera Plugin.

I am not a programming guy so I can’t look into the code for further troubleshooting.

See first post of the thread, it contains a number of attachments.

Did you ever have any other thoughts on why these devices don’t show up in ImperiHome

clippermiami, I had used this plugin as a base and done some modifications to make it work for a Sonoff Wifi relay controller. After using it a bit, I too noticed that I was not able to add these things to ImperiHome. Through a post on a russian forum site, I found out what the issue was. Nullx8 has the device type set to mios-nullx8-com:device:HttpSwitch:1 which I think is a non-standard device type. I switched it to urn:schemas-upnp-org:device:BinaryLight:1 and things worked. I noticed though that after changing the device_type for individual devices, that it reverted back to the old device type. I made the change in the D_HttpSwitch1.xml file and uploaded that. It changed all of my HTTPSwitch devices to that device type and I can now see them in ImperiHome. I have included my updated .xml file for you to try. Before uploading it, either download your existing one so you can revert back to it if you need to, and/or make a backup of your Vera setup before uploading.

For those who want to see my changes for using this plugin with a Sonoff, check out my blog post at my website.

Clippermiami passed away: http://forum.micasaverde.com/index.php?topic=48421.0

Dan ! Congratulations!!!

take a look in sonoff-server by mdopp or grandberro (i prefer)

and modify file sonof.server.modules.js

…Sonoff server run on raspberry for example

// ----------- sonoff server ------------------------
// setup a server, that will respond to the SONOFF requests
// this is the replacement for the SONOFF cloud!

var wsOptions = {
secure: true,
key: config.server.privateKey,
cert: config.server.certificate,
};

const dispositivos = {

// put yours code sonoff and number device vera
“1000xxxx-0”: 1239,

    "1000xxxx-1": 1240,

     "1000xxxxx-2": 1247,

// for one channel
“10000xxx”: 1256,

}

const estados = {

  "on": 1,

  "off": 0,

}


const enviarRequisicao = (idDispositivo, estado, callback) => {

   http.get(`http://VERA_IP:3480/data_request?id=action&output_format=json&DeviceNum=${idDispositivo}&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=${estado}`, (resp) => {

        resp.on('data', (chunk) => {

             callback(false, chunk)

        });

    }).on("error", (err) => {

         callback(true, err)

    });

}

/////////////////////////////////… find

                case 'update':
                    //device wants to update its state
                    if (typeof data.params.switches == 'undefined') {
                        // Single switch
                        var device = state.getDeviceById(data.deviceid);
                        if (!device) {
                            log.error('ERR | WS | Unknown device ', data.deviceid);
                        } else {
                            device.state = data.params.switch;
                            device.rawMessageLastUpdate = data;
                            device.rawMessageLastUpdate.timestamp = Date.now();
                            state.updateKnownDevice(device);
							 
										enviarRequisicao(dispositivos[device.id], estados[device.state], (erro, dados) => {
                                          console.log(erro)
                                          console.log(dados)
                                          console.log("-----------------------------------------------------------------------------------");
                                          console.log(device.id);
                                          console.log(device.state);
                                        })
                        }
                    } else {
                        // Multiple switches, look for parent
                        var device = state.getDeviceByParentId(data.deviceid);
                        if (!device) {
                            log.error('ERR | WS | Unknown device ', data.deviceid);
                                       } else {
                                       for (i = 0; i < data.params.switches.length; i++) {
                                        var device = state.getDeviceById(data.deviceid + '-' + i);
                                        device.state = data.params.switches[i].switch;
                                        device.rawMessageLastUpdate = data;
                                        device.rawMessageLastUpdate.timestamp = Date.now();
                                        state.updateKnownDevice(device);
                                        
										enviarRequisicao(dispositivos[device.id], estados[device.state], (erro, dados) => {
                                          console.log(erro)
                                          console.log(dados)
                                          console.log("-----------------------------------------------------------------------------------");
                                          console.log(device.id);
                                          console.log(device.state);
                                        })

                                    }
                             }
                    }
                    break;


                case 'register':

 ////https://github.com/granberro/simple-sonoff-server////