Author Topic: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)  (Read 14605 times)

Offline stefaanbolle

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +4/-1
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #45 on: September 18, 2015, 04:30:02 am »
Quote
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 ;)

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

Offline nullx8

  • Hero Member
  • *****
  • Posts: 870
  • Karma: +9/-3
  • Trouble !
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #46 on: October 02, 2015, 02:31:23 am »
could you replace this files on your vera and test with Imperihome of it does show now properly ?
1 VeraLite, 2 RaspberryPI, Harmony Remote, openLuup, 85 Devices, 34Nodes, 63 Triggers, 49 Scenes

Offline clippermiami

  • Hero Member
  • *****
  • Posts: 1391
  • Karma: +27/-6
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #47 on: October 02, 2015, 08:40:56 am »
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
Two Vera Plus UI7 Linked via HTTP, 90+ Devices. PlugIns: PLEG, DSC, Blue Iris, MySensors,  AutoVera, ImperiHome, VeraAlerts, EventWatcher

Offline Viruta57

  • Jr. Member
  • **
  • Posts: 97
  • Karma: +1/-0
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #48 on: October 03, 2015, 11:20:31 am »
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...

 

 
« Last Edit: October 04, 2015, 12:20:43 pm by Viruta57 »

Offline Viruta57

  • Jr. Member
  • **
  • Posts: 97
  • Karma: +1/-0
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #49 on: October 04, 2015, 12:36:56 pm »
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....
« Last Edit: October 04, 2015, 04:12:06 pm by Viruta57 »

Offline stefaanbolle

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +4/-1
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #50 on: October 11, 2015, 11:27:03 am »
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.

Offline clippermiami

  • Hero Member
  • *****
  • Posts: 1391
  • Karma: +27/-6
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #51 on: October 15, 2015, 04:30:32 pm »
Null8x

Have you had a chance to consider why these things aren't tracked in EvenTWatcher and populated in ImperiHome?
Two Vera Plus UI7 Linked via HTTP, 90+ Devices. PlugIns: PLEG, DSC, Blue Iris, MySensors,  AutoVera, ImperiHome, VeraAlerts, EventWatcher

Offline spudjr

  • Full Member
  • ***
  • Posts: 133
  • Karma: +2/-0
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #52 on: October 17, 2015, 05:34:50 pm »
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 :)


« Last Edit: October 19, 2015, 09:53:56 am by spudjr »

Offline ishaq

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #53 on: November 11, 2015, 05:43:59 am »
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.

Offline Brientim

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2497
  • Karma: +77/-7
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #54 on: November 11, 2015, 06:00:55 am »
See first post of the thread, it contains a number of attachments.

Offline clippermiami

  • Hero Member
  • *****
  • Posts: 1391
  • Karma: +27/-6
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #55 on: December 02, 2015, 09:06:11 am »
No encoding, i simply read status informations, all "put" is straight http-get hardcoded

Did you ever have any other thoughts on why these devices don't show up in ImperiHome
Two Vera Plus UI7 Linked via HTTP, 90+ Devices. PlugIns: PLEG, DSC, Blue Iris, MySensors,  AutoVera, ImperiHome, VeraAlerts, EventWatcher

Offline dbemowsk

  • Newbie
  • *
  • Posts: 18
  • Karma: +2/-1
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #56 on: August 27, 2017, 10:50:58 pm »
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.
https://dan.bemowski.info/2017/07/04/using-a-sonoff-with-espeasy-and-vera/

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1289
  • Karma: +33/-32
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #57 on: August 28, 2017, 07:07:22 pm »
Vera 3, 1.7.1030, CT101 t-stat, Everspring motion detector, GE/Jasco switch, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, Weatherunderground, LB60Z-1 bulb

Offline givapva

  • Newbie
  • *
  • Posts: 7
  • Karma: +0/-0
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #58 on: August 12, 2018, 08:50:38 pm »
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.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':
.................................................................

Offline givapva

  • Newbie
  • *
  • Posts: 7
  • Karma: +0/-0
Re: PLUGIN: HttpSwitch (for Cheap WiFi Switches like KK-SR3)
« Reply #59 on: August 12, 2018, 10:20:10 pm »
     ////https://github.com/granberro/simple-sonoff-server////