-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for light switches #7
Comments
Is Id 79 (garage) a dimmer switch or normal on/off switch? I presume binary device designates it as having only an on/off state? What about the multilevel switches (id 85/garage entrance) |
Living Room (75) and garage entrance (85) are dimmers. Garage (79) and Play Area (89) are just on and off. |
Are you able to control the switches through the Vivint app itself? I don't know why I had in my mind that this was simply adding a contact sensor. I'm not sure how the api handles a put request to a switch. For example, to control a lock the Homebridge app sends a "PUT" request to https://vivintsky.com/api/locks/24 (assuming 24 is the ID# of the lock) with the following body: {id: 24, s:true}. So without actually having compatible switches, its impossible to guess what Vivint would replace "/locks/" with. That being said, we can utilize an app to sniff out the api, but it only works if you're able to control the switches directly from the Vivint app (or more specifically, from vivintsky.com). The app that I've used in this project is called Postman.. I'll try to post a walkthrough on how to set this up: When the app loads, click on the templates tab, and select "Reverse Engineering an API" Click on "Use this template" -> "Create" Click on the "Capture API requests" icon: Note the proxy port number, 5555 by default, select the reverse engineering profile as the target and click "Connect": You should get a pop up saying something to the effect of the connection has been established. Now you need to set up your browser to use postman as a proxy.. I am on a Mac and use safari so I'll show how its done with Mac: Click on the "advanced" tab, and click "Change Settings" under "Proxies": Check the box next to HTTP and HTTPS, set server to localhost, and port to 5555 (or whatever you set previously in postman) and click ok: Click Apply on the network screen (if you just close it, it will prompt you to apply) .... open vivintsky.com in safari, and things should start populating in the postman log. On the vivintsky website, operate the light switch on and off, and look back at the postman log. You are looking for any "PUT" requests. Next pic is an example of a PUT request that I got for unlocking my backdoor (id 42): Don't post the string of numbers that I have blocked out in the picture above, I just need to see what the /1/locks/42 part says for you when the switch is controlled. If you could post that information, I think I ought to be able to write the code for it! |
Switches I guess it wouldn’t have been impossible to guess. Looks easy enough, I’ll update the fork when I get home |
ok so lets try this... add the following code to the deviceset class, after the // mischief managed comment (line 678 of device_set.js):
and change the let Devices = line to:
|
Also for the dimmer switches.. can you tell me if you always get a PubNub message stating s: true and s:false when the light is switched on and off? or does it send you a val: 0 when the switch is turned off? It looks like, based on what you had pasted before, that it always sends two separate messages, one with the s true/false stating whether or not the light is on, as well as one with a val argument. I'm curious as to what messages are sent when you change the dim level without turning the bulb completely off? |
For on/off it goes to false For dimmer it goes to 0 or if its being dimmed to a diff value ill give the code a try. Thank You :) |
Nice, you did it. Thank you! My on/off switches are working perfectly. My dimmers are not being passed to homekit yet. [4/26/2019, 3:41:47 AM] [Vivint] Do not know how to handle device! ID: 75 Data.t: multilevel_switch_device data.ec: undefined Data.n: Living Room [4/26/2019, 3:41:47 AM] [Vivint] Do not know how to handle device! ID: 85 Data.t: multilevel_switch_device data.ec: undefined Data.n: Garage Entrance [4/26/2019, 3:41:47 AM] [Vivint] Adding 2 new accessories |
excellent, I added a couple things I was hoping you would try.. so first off for the binary switches, I added some code to infer whether or not they are light switches, fan switches, or just plan old switches. My assumption is that you'll get a light icon if it identifies as a lightbulb, fan icon for a fan, and just a normal switch which is what you are seeing now. I'm pretty confident that that code will work so I'm not necessarily needing you to test it, but if you add the word "light" somewhere into the name of the device it will register as a lightbulb in HomeKit instead of just a switch. Now for the dimmer... I've wrote some code for you to test! for the let Devices line (note the change from LightSwitch to BinarySwitch):
and the good stuff (replace the previous code with this, this updates to more intelligently define the binary switches as well as add support for the dimmer switch):
|
im getting this [4/26/2019, 4:18:23 AM] [Vivint] Error while bootstrapping accessories |
ok lets change the device class name back to LightSwitch instead of BinarySwitch:
and:
|
[4/26/2019, 4:26:04 AM] Error: listen EADDRINUSE :::51826 |
I don't see id 75/85 in the unknown devices list, did those devices add to homekit? Living Room and Garage Entrance were the device names |
also those devices that are marked as multilevel_switch_ip_device.. do those behave the same way within postman? (s: true/false for when the switch is turned on and off, and val: 0-100 when the dim level is changed) |
It actually did, but something is stopping homebridge received cached accessory PlatformAccessory { |
the multilevel_switch_ip_device are hue lights... ill need to see how the message looks on those. Also i already have Hue integrated with homekit so im not in a hurry to make those work for now.... but to continue to grow the plugin we can take a look. any idea why is my homebridge stopping? |
ok no need to add the extra step through Vivint if it can be controlled directly from HomeKit, they'll be much more reliable that way. does the log file show any more detail? |
this is all its showing right after loading the accessories and displaying the pairing code [4/26/2019, 4:42:36 AM] Error: listen EADDRINUSE :::51826 |
the first line in the log seems like there might be two instances of Homebridge running? if not.. lets try commenting out the following lines and seeing if its the notify code that is causing problems (add /* and */ to comment out the code):
|
got it, there were other homebridge processes running. the are working :) only thing i am finding is that when i when i change a light, lets say from on to off... i see the accessory in homekit going to off status and then to on and back to off.. not sure if i am describing this correctly to you.. but like if its getting a status update before doing what is told. |
interesting.. maybe because the Vivint api is sending two messages each time the switch is operated, one with just the brightness value and then another with whether or not the light is on or off. Do you mean when you press the button in HomeKit from your phone or when you physically control the switch? Also, does the HomeKit show you that this is a dimmable light and are you able to dim the bulb from HomeKit? |
the dimmer lights show correctly i can dim them in homekit and the on/off also show correctly. its when i control them in homekit... it might be an issue with having a wink hub connected to the vivint panel. I will be removing the wink hub and do some more testing. Ill do that tomorrow. Before coming across this plugin i had to add the wink hub to the vivint panel as a zwave device and then added the wink hub to hassio to be able to pass the light switches to homekit. But now its all working :) im pretty sure that wink hub has something to do with what i am experiencing. Thanks for all your help, ill report back once i remove the wink hub from the panel. |
hey try this real quick if you don't mind and see if it corrects that issue:
|
where do you want me to add that.. i didnt comment out what you asked when i was having problems running homebridge this is what i currently have // Binary switch has only on and off states
} extend(LightSwitch, { // dimmer switch {s: true/false, val: 0-100}
} extend(DimmerSwitch, { |
replace that last bit of code (the notify function):
with:
|
sorry I edited that last post hopefully before you saw it, I forgot a }, there should be two of them at the end after the two // lines |
i catch the edit... still behaving the same way. |
copy that, thanks for trying! |
if i turn on the light it goes to 100% -> off ->100%.... if i turn it off it seems to go to off and stays there |
If i remember correctly the first time we tested with just the on/off switches worked fine with out the device toggling the status. |
Also I turned off the wink hub and still the same |
yeah I'm pretty sure that both issues are because of the way the code is handling the Vivint api sending two messages for the dimmer switches. this might help, this code will print a DEBUG statement in the log file to show exactly what the messages that are being sent (and in what order):
this is the same notify function as before.. can you put that in and toggle the switches and paste the result? |
[4/26/2019, 6:00:04 AM] ERROR LOADING PLUGIN homebridge-vivint: SyntaxError: missing ) after argument list |
sorry forgot a +:
|
This is what is showing when trying to turn it on and then off [4/26/2019, 6:09:44 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"val":100}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"1beaa323d00d8515:1beaa323d00d8515:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a0a8c8879f486ec801d2","ts":"2019-04-26T06:09:44.890","validation":{"args":{"value":[100,true]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1556258984.654695}}},"op":"u","panid":,"parid":1,"t":"account_partition"} |
ok replace that notify function with this:
|
that did it for the dimmers. The of/off switches are doing the same on->off->on [4/26/2019, 6:17:57 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":89,"val":0}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"204b1d972f9902a6:204b1d972f9902a6:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a2953916b20051b43987","ts":"2019-04-26T06:17:57.796","validation":{"args":{"value":[0]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1556259477.613524}}},"op":"u","panid":,"parid":1,"t":"account_partition"} |
are you getting another message that says "val":100 when you turn those binary switches on? |
im getting these 3.. they seem to just go by true and false and not by a value [4/26/2019, 6:23:43 AM] [Vivint] received pubNub msg |
ok so the notify function you have for those switches looks like this:
change it to this:
|
that works better... now just on the dimmer for some reason when turning off it does turn off the lights but then it displays as it it was on with 79%... sometimes a random number. Here is the log [4/26/2019, 6:30:40 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"val":0}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"1f7f5c3fcd27a8b8:1f7f5c3fcd27a8b8:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a590c8879f4456cf7889","ts":"2019-04-26T06:30:40.926","validation":{"args":{"value":[0]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1556260240.698228}}},"op":"u","panid":,"parid":1,"t":"account_partition"} |
strange so the last two lines say the Vivint system is telling the code that the brightness is 79%, then the last message says that the light is on.. is it doing this every time you turn the lights off? |
no, not everytime... it seems that it only does it if i turn it on then off almost right away it does it.... if i wait a couple of seconds it works fine and it just turns off and no other updates from vivint |
maybe changes are happening too fast for the event stream to handle? im honestly not sure about that one. weird that it would report a random brightness... especially since it is Vivint itself reporting that brightness number. based on what Vivint is reporting back to the code... it seems like it is functioning correctly. we can check the set routine and see if something funky is happening there: you have currently:'
change to:
|
does it even call that routine if you just turn the light on and off without adjusting the brightness? |
Let me know if anything else quirky happens. My last thought would be that perhaps when we send the signal to tell Vivint to turn the switch off, we also need to send a val:0 command and tell it the brightness should be reduced to 0. Not sure why not doing that would result in a random brightness level though. Anyhow, unless something crazy happens ill update the fork to support the zwave switches. Thanks for troubleshooting! You might also delete or edit the comments that have your panel ID number in them. @timcharper mentioned that they could somehow be traced back to you. |
Hey just checking in here, what’s the status of this issue and how can I help? |
Open a PR :) Also, if you could add unit tests, that'd be swell. |
[4/18/2019, 4:14:37 AM] [Vivint] Do not know how to handle device! ID: 75 Data.t: multilevel_switch_device data.ec: undefined Data.n: Living Room
[4/18/2019, 4:14:37 AM] [Vivint] Do not know how to handle device! ID: 79 Data.t: binary_switch_device data.ec: undefined Data.n: Garage
[4/18/2019, 4:14:37 AM] [Vivint] Do not know how to handle device! ID: 85 Data.t: multilevel_switch_device data.ec: undefined Data.n: Garage Entrance
[4/18/2019, 4:14:37 AM] [Vivint] Do not know how to handle device! ID: 89 Data.t: binary_switch_device data.ec: undefined Data.n: Play Area
This is the message that comes across when turning on and off the switches
[4/18/2019, 4:17:04 AM] [Vivint] {"_id":"0000000000000000|1","da":{"d":[{"_id":75,"s":true}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"68c03ea59ab42378:68c03ea59ab42378:0:1"}},"ctxd":null,"ctxid":"5bf05d0878b4d449811a228b","ctxt":20,"mid":"5cb7fa3f9681f1005b837115","ts":"2019-04-18T04:17:04.253","validation":{"args":{"value":[100,true]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1555561023.972614}}},"op":"u","panid":0000000000000000,"parid":1,"t":"account_partition"}
[4/18/2019, 4:17:11 AM] [Vivint] received pubNub msg
[4/18/2019, 4:17:11 AM] [Vivint] {"_id":"0000000000000000|1","da":{"d":[{"_id":75,"val":0}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"be1f781f661677a:be1f781f661677a:0:1"}},"ctxd":null,"ctxid":"5bf05d0878b4d449811a228b","ctxt":20,"mid":"5cb7fa47d593cf3b720af265","ts":"2019-04-18T04:17:11.729","validation":{"args":{"value":[0,false]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1555561031.536903}}},"op":"u","panid":0000000000000000,"parid":1,"t":"account_partition"}
[4/18/2019, 4:17:12 AM] [Vivint] received pubNub msg
[4/18/2019, 4:17:12 AM] [Vivint] {"_id":"0000000000000000|1","da":{"d":[{"_id":75,"s":false}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"36be93225eda0f1b:36be93225eda0f1b:0:1"}},"ctxd":null,"ctxid":"5bf05d0878b4d449811a228b","ctxt":20,"mid":"5cb7fa47d593cf3b720af265","ts":"2019-04-18T04:17:11.801","validation":{"args":{"value":[0,false]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1555561031.536903}}},"op":"u","panid":0000000000000000,"parid":1,"t":"account_partition"}
[4/18/2019, 4:20:18 AM] [Vivint] received pubNub msg
[4/18/2019, 4:20:18 AM] [Vivint] {"_id":"0000000000000000|1","da":{"d":[{"_id":79,"val":100}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"6aec278a1b9a41d6:6aec278a1b9a41d6:0:1"}},"mid":"5cb7fb028acbfd0001a0c521","ts":"2019-04-18T04:20:18.530"}},"op":"u","panid":0000000000000000,"parid":1,"t":"account_partition"}
[4/18/2019, 4:20:18 AM] [Vivint] received pubNub msg
[4/18/2019, 4:20:18 AM] [Vivint] {"_id":"0000000000000000|1","da":{"d":[{"_id":79,"val":100}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"6aec278a1b9a41d6:6aec278a1b9a41d6:0:1"}},"mid":"5cb7fb028acbfd0001a0c521","ts":"2019-04-18T04:20:18.530"}},"op":"u","panid":0000000000000000,"parid":1,"t":"account_partition"}
[4/18/2019, 4:20:18 AM] [Vivint] received pubNub msg
[4/18/2019, 4:20:18 AM] [Vivint] {"_id":"0000000000000000|1","da":{"d":[{"_id":79,"s":true}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"a2bd097ee304022:a2bd097ee304022:0:1"}},"mid":"5cb7fb02975a7600014604ca","ts":"2019-04-18T04:20:18.613"}},"op":"u","panid":0000000000000000,"parid":1,"t":"account_partition"}
[4/18/2019, 4:20:21 AM] [Vivint] received pubNub msg
[4/18/2019, 4:20:21 AM] [Vivint] {"_id":"0000000000000000|1","da":{"d":[{"_id":79,"val":0}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"3d741e60348fe717:3d741e60348fe717:0:1"}},"ctxd":null,"ctxid":"5bf05d0878b4d449811a228b","ctxt":20,"mid":"5cb7fb05d593cf3b720afbc7","ts":"2019-04-18T04:20:21.695","validation":{"args":{"value":[0]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1555561221.500922}}},"op":"u","panid":0000000000000000,"parid":1,"t":"account_partition"}
[4/18/2019, 4:20:21 AM] [Vivint] received pubNub msg
[4/18/2019, 4:20:21 AM] [Vivint] {"_id":"0000000000000000|1","da":{"d":[{"_id":79,"s":false}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"4618e58f7bb2b66c:4618e58f7bb2b66c:0:1"}},"ctxd":null,"ctxid":"5bf05d0878b4d449811a228b","ctxt":20,"mid":"5cb7fb05d593cf3b720afbc7","ts":"2019-04-18T04:20:21.799","validation":{"args":{"value":[0]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1555561221.500922}}},"op":"u","panid":0000000000000000,"parid":1,"t":"account_partition"}
The text was updated successfully, but these errors were encountered: