timcharper / homebridge-vivint

Integrates Vivint security system with Apple Home
Other
33 stars 34 forks source link

Add support for light switches #7

Open mceres opened 5 years ago

mceres commented 5 years ago

[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"}

daymondm commented 5 years ago

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)

mceres commented 5 years ago

Living Room (75) and garage entrance (85) are dimmers.

Garage (79) and Play Area (89) are just on and off.

daymondm commented 5 years ago

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"

Screen Shot 2019-04-23 at 11 33 45 PM

Click on "Use this template" -> "Create"

Click on the "Capture API requests" icon:

Screen Shot 2019-04-24 at 12 07 12 AM

Note the proxy port number, 5555 by default, select the reverse engineering profile as the target and click "Connect":

Screen Shot 2019-04-23 at 11 39 59 PM

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:

Screen Shot 2019-04-23 at 11 41 38 PM

Click on the "advanced" tab, and click "Change Settings" under "Proxies":

Screen Shot 2019-04-23 at 11 42 54 PM

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:

Screen Shot 2019-04-23 at 11 44 31 PM

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):

Screen Shot 2019-04-23 at 11 47 55 PM

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!

mceres commented 5 years ago

Great, thanks for the tip. I was able to do this on a Windows PC. Here is the info

This is on a dimmer

image

This is on an on/off switch

image

Let me know if you need any other info.

daymondm commented 5 years ago

Switches I guess it wouldn’t have been impossible to guess. Looks easy enough, I’ll update the fork when I get home

daymondm commented 5 years ago

ok so lets try this... add the following code to the deviceset class, after the // mischief managed comment (line 678 of device_set.js):

  // Binary switch has only on and off states
  class LightSwitch extends Device {
    constructor(accessory) {
      super(accessory)
      this.service = accessory.getServiceByUUIDAndSubType(Service.Lightbulb)

      this.service
        .getCharacteristic(Characteristic.On)
        .on('get', (next) => next(null,this.switchCurrentValue()))
        .on('set', this.setSwitchCurrentValue.bind(this))
    }

    switchCurrentValue() {
      return this.data.s
    }

    setSwitchCurrentValue(targetState, next) {
      if (targetState) {
        // turn switch on
        vivintApi.putDevice('switches', this.id, {s: true, _id: this.id})
          .then(
            (success) => next(),
            (failure) => {
              log("failure " + failure)
              next(failure)
            })
      } else {
        // turn switch off
        vivintApi.putDevice('switches', this.id, {s: false, _id: this.id})
          .then(
            (success) => next(),
            (failure) => {
              log("failure " + failure)
              next(failure)
            })
      }
    }

    notify() {
      if (this.service) {
        this.service.getCharacteristic(Characteristic.On)
          .updateValue(this.switchCurrentValue())
      }
    }
  }

  extend(LightSwitch, {
    appliesTo: (data) => { return data.t == "binary_switch_device"},
    addServices: (accessory) => {
      accessory.addService(new Service.Lightbulb(accessory.context.name))
    }
  })

and change the let Devices = line to:

let Devices = [ContactSensor, MotionSensor, Lock, Thermostat, GarageDoor, Panel, PIVMotion, LightSwitch]

daymondm commented 5 years ago

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?

mceres commented 5 years ago

For on/off it goes to false {"s":false,"_id":79}

For dimmer it goes to 0 or if its being dimmed to a diff value Off {"val":0,"_id":85} Dimmed {"val":40,"_id":85}

ill give the code a try.

Thank You :)

mceres commented 5 years ago

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 [4/26/2019, 3:41:47 AM] [Vivint] { name: 'Garage', id: 79, deviceClassName: 'LightSwitch' } [4/26/2019, 3:41:47 AM] [Vivint] { name: 'Play Area', id: 89, deviceClassName: 'LightSwitch' }

daymondm commented 5 years ago

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):

let Devices = [ContactSensor, MotionSensor, Lock, Thermostat, GarageDoor, Panel, PIVMotion, BinarySwitch, DimmerSwitch]

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):

  class BinarySwitch extends Device {
    constructor(accessory) {
      super(accessory)

      this.service = accessory.getServiceByUUIDAndSubType(Service.Lightbulb) || accessory.getServiceByUUIDAndSubType(Service.Fan) || accessory.getServiceByUUIDAndSubType(Service.Switch)

      this.service
        .getCharacteristic(Characteristic.On)
        .on('get', (next) => next(null,this.switchCurrentValue()))
        .on('set', this.setSwitchCurrentValue.bind(this))
    }

    switchCurrentValue() {
      return this.data.s
    }

    setSwitchCurrentValue(targetState, next) {
      if (targetState) {
        // turn switch on
        vivintApi.putDevice('switches', this.id, {s: true, _id: this.id})
          .then(
            (success) => next(),
            (failure) => {
              log("failure " + failure)
              next(failure)
            })
      } else {
        // turn switch off
        vivintApi.putDevice('switches', this.id, {s: false, _id: this.id})
          .then(
            (success) => next(),
            (failure) => {
              log("failure " + failure)
              next(failure)
            })
      }
    }

    notify() {
      if (this.service) {
        this.service.getCharacteristic(Characteristic.On)
          .updateValue(this.switchCurrentValue())
      }
    }
  }

  extend(BinarySwitch, {
    appliesTo: (data) => { return data.t == "binary_switch_device"},
    addServices: (accessory) => {
      if (accessory.context.name.match(/\blight\b/i)) {
        accessory.addService(new Service.Lightbulb(accessory.context.name))
      }
      else if (accessory.context.name.match(/\bfan\b/i)) {
        accessory.addService(new Service.Fan(accessory.context.name))
      }
      else {
        accessory.addService(new Service.Switch(accessory.context.name))
      }
    }
  })

  // dimmer switch {s: true/false, val: 0-100}
  class DimmerSwitch extends Device {
    constructor(accessory) {
      super(accessory)

      this.service = accessory.getServiceByUUIDAndSubType(Service.Lightbulb)

      this.service
        .getCharacteristic(Characteristic.On)
        .on('get', (next) => next(null,this.switchCurrentValue()))
        .on('set', this.setSwitchCurrentValue.bind(this))

      this.service
        .getCharacteristic(Characteristic.Brightness)
        .on('get', (next) => next(null, this.switchBrightnessValue()))
        .on('set', this.setBrightnessValue.bind(this))
    }

    switchCurrentValue() {
      return this.data.s
    }

    setSwitchCurrentValue(targetState, next) {
      if (targetState) {
        // turn switch on
        vivintApi.putDevice('switches', this.id, {s: true, _id: this.id})
          .then(
            (success) => next(),
            (failure) => {
              log("failure " + failure)
              next(failure)
            })
      } else {
        // turn switch off
        vivintApi.putDevice('switches', this.id, {s: false, _id: this.id})
          .then(
            (success) => next(),
            (failure) => {
              log("failure " + failure)
              next(failure)
            })
      }
    }

    switchBrightnessValue() {
      return this.data.val
    }

    setBrightnessValue(targetState,next) {
      vivintApi.putDevice('switches', this.id, {val: targetState, _id: this.id})
        .then(
          (success) => next(),
          (failure) => {
            log("failure " + failure)
            next(failure)
          })
    }

    notify() {
      if (this.service) {
        if (this.data.val >= 0) {
          this.service
           .getCharacteristic(Characteristic.Brightness)
           .updateValue(this.data.val)
        }

        if (this.data.s == true || this.data.s == false) {
          this.service
            .getCharacteristic(Characteristic.On)
            .updateValue(this.data.s)
        }
        //this.service.getCharacteristic(Characteristic.On)
        //  .updateValue(this.switchCurrentValue())
      }
    }
  }

  extend(DimmerSwitch, {
    appliesTo: (data) => { return data.t == "multilevel_switch_device"},
    addServices: (accessory) => {
      //assuming this is a dimmer switch controlling a light
      accessory.addService(new Service.Lightbulb(accessory.context.name))
    }
  })
mceres commented 5 years ago

im getting this

[4/26/2019, 4:18:23 AM] [Vivint] Error while bootstrapping accessories [4/26/2019, 4:18:23 AM] [Vivint] Unknown device class name LightSwitch

daymondm commented 5 years ago

ok lets change the device class name back to LightSwitch instead of BinarySwitch:

let Devices = [ContactSensor, MotionSensor, Lock, Thermostat, GarageDoor, Panel, PIVMotion, LightSwitch, DimmerSwitch]

and:

  // Binary switch has only on and off states
  class LightSwitch extends Device {
    constructor(accessory) {
      super(accessory)

      this.service = accessory.getServiceByUUIDAndSubType(Service.Lightbulb) || accessory.getServiceByUUIDAndSubType(Service.Fan) || accessory.getServiceByUUIDAndSubType(Service.Switch)

      this.service
        .getCharacteristic(Characteristic.On)
        .on('get', (next) => next(null,this.switchCurrentValue()))
        .on('set', this.setSwitchCurrentValue.bind(this))
    }

    switchCurrentValue() {
      return this.data.s
    }

    setSwitchCurrentValue(targetState, next) {
      if (targetState) {
        // turn switch on
        vivintApi.putDevice('switches', this.id, {s: true, _id: this.id})
          .then(
            (success) => next(),
            (failure) => {
              log("failure " + failure)
              next(failure)
            })
      } else {
        // turn switch off
        vivintApi.putDevice('switches', this.id, {s: false, _id: this.id})
          .then(
            (success) => next(),
            (failure) => {
              log("failure " + failure)
              next(failure)
            })
      }
    }

    notify() {
      if (this.service) {
        this.service.getCharacteristic(Characteristic.On)
          .updateValue(this.switchCurrentValue())
      }
    }
  }

  extend(LightSwitch, {
    appliesTo: (data) => { return data.t == "binary_switch_device"},
    addServices: (accessory) => {
      if (accessory.context.name.match(/\blight\b/i)) {
        accessory.addService(new Service.Lightbulb(accessory.context.name))
      }
      else if (accessory.context.name.match(/\bfan\b/i)) {
        accessory.addService(new Service.Fan(accessory.context.name))
      }
      else {
        accessory.addService(new Service.Switch(accessory.context.name))
      }
    }
  })

  // dimmer switch {s: true/false, val: 0-100}
  class DimmerSwitch extends Device {
    constructor(accessory) {
      super(accessory)

      this.service = accessory.getServiceByUUIDAndSubType(Service.Lightbulb)

      this.service
        .getCharacteristic(Characteristic.On)
        .on('get', (next) => next(null,this.switchCurrentValue()))
        .on('set', this.setSwitchCurrentValue.bind(this))

      this.service
        .getCharacteristic(Characteristic.Brightness)
        .on('get', (next) => next(null, this.switchBrightnessValue()))
        .on('set', this.setBrightnessValue.bind(this))
    }

    switchCurrentValue() {
      return this.data.s
    }

    setSwitchCurrentValue(targetState, next) {
      if (targetState) {
        // turn switch on
        vivintApi.putDevice('switches', this.id, {s: true, _id: this.id})
          .then(
            (success) => next(),
            (failure) => {
              log("failure " + failure)
              next(failure)
            })
      } else {
        // turn switch off
        vivintApi.putDevice('switches', this.id, {s: false, _id: this.id})
          .then(
            (success) => next(),
            (failure) => {
              log("failure " + failure)
              next(failure)
            })
      }
    }

    switchBrightnessValue() {
      return this.data.val
    }

    setBrightnessValue(targetState,next) {
      vivintApi.putDevice('switches', this.id, {val: targetState, _id: this.id})
        .then(
          (success) => next(),
          (failure) => {
            log("failure " + failure)
            next(failure)
          })
    }

    notify() {
      if (this.service) {
        if (this.data.val >= 0) {
          this.service
           .getCharacteristic(Characteristic.Brightness)
           .updateValue(this.data.val)
        }

        if (this.data.s == true || this.data.s == false) {
          this.service
            .getCharacteristic(Characteristic.On)
            .updateValue(this.data.s)
        }
        //this.service.getCharacteristic(Characteristic.On)
        //  .updateValue(this.switchCurrentValue())
      }
    }
  }

  extend(DimmerSwitch, {
    appliesTo: (data) => { return data.t == "multilevel_switch_device"},
    addServices: (accessory) => {
      //assuming this is a dimmer switch controlling a light
      accessory.addService(new Service.Lightbulb(accessory.context.name))
    }
  })
mceres commented 5 years ago

[4/26/2019, 4:26:04 AM] Error: listen EADDRINUSE :::51826 at Object._errnoException (util.js:1022:11) at _exceptionWithHostPort (util.js:1044:20) at Server.setupListenHandle [as _listen2] (net.js:1367:14) at listenInCluster (net.js:1408:12) at Server.listen (net.js:1492:7) at EventedHTTPServer.listen (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/eventedhttp.js:60:19) at HAPServer.listen (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/HAPServer.js:158:20) at Bridge.Accessory.publish (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:616:16) at Server._publish (/usr/local/lib/node_modules/homebridge/lib/server.js:132:16) at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:101:10) [4/26/2019, 4:26:04 AM] Got SIGTERM, shutting down Homebridge... [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 5 Data.t: energy_service data.ec: undefined Data.n: undefined [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 12 Data.t: network_hosts_service data.ec: undefined Data.n: undefined [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 13 Data.t: panel_diagnostics_service data.ec: undefined Data.n: undefined [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 35 Data.t: wireless_sensor data.ec: 1248 Data.n: Bedroom Glass Break [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 36 Data.t: wireless_sensor data.ec: 1248 Data.n: Living Room Glass Break [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 44 Data.t: phillips_hue_bridge_device data.ec: undefined Data.n: Philips hue [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 45 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Front Outdoor [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 46 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Front Door Lights [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 47 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Belen's [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 48 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Cristian's [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 49 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Master Bedroom [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 20003 Data.t: scheduler_service data.ec: undefined Data.n: undefined [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 70 Data.t: controller_device data.ec: undefined Data.n: Wink [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 84 Data.t: wireless_sensor data.ec: 1269 Data.n: Master Hall Fire Alert [4/26/2019, 4:26:05 AM] [Vivint] Do not know how to handle device! ID: 94 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Bathroom [4/26/2019, 4:26:05 AM] [Vivint] Adding 0 new accessories HAP Warning: Characteristic 00000008-0000-1000-8000-0026BB765291 not in required or optional characteristics for service 00000043-0000-1000-8000-0026BB765291. Adding anyway. HAP Warning: Characteristic 00000008-0000-1000-8000-0026BB765291 not in required or optional characteristics for service 00000043-0000-1000-8000-0026BB765291. Adding anyway. [4/26/2019, 4:26:05 AM] [Vivint] Handling incoming device snapshot for timestamp 2019-04-26T04:24:35.749000

daymondm commented 5 years ago

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

daymondm commented 5 years ago

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)

mceres commented 5 years ago

It actually did, but something is stopping homebridge

received cached accessory PlatformAccessory { displayName: 'Living Room', UUID: '28ea52bf-3ecf-4d94-8aee-7d18ebbd0d24', category: 1, services: [ Service { displayName: undefined, UUID: '0000003E-0000-1000-8000-0026BB765291', subtype: undefined, iid: null, characteristics: [Array], optionalCharacteristics: [], isHiddenService: false, isPrimaryService: false, linkedServices: [] }, Service { displayName: 'Living Room', UUID: '00000043-0000-1000-8000-0026BB765291', subtype: undefined, iid: null, characteristics: [Array], optionalCharacteristics: [], isHiddenService: false, isPrimaryService: false, linkedServices: [] } ], reachable: false, context: { name: 'Living Room', id: 75, deviceClassName: 'DimmerSwitch' }, _associatedPlugin: 'homebridge-vivint', _associatedPlatform: 'Vivint' } received cached accessory PlatformAccessory { displayName: 'Garage Entrance', UUID: 'ba6172b2-376a-4166-9a3d-ca282f33de29', category: 1, services: [ Service { displayName: undefined, UUID: '0000003E-0000-1000-8000-0026BB765291', subtype: undefined, iid: null, characteristics: [Array], optionalCharacteristics: [], isHiddenService: false, isPrimaryService: false, linkedServices: [] }, Service { displayName: 'Garage Entrance', UUID: '00000043-0000-1000-8000-0026BB765291', subtype: undefined, iid: null, characteristics: [Array], optionalCharacteristics: [], isHiddenService: false, isPrimaryService: false, linkedServices: [] } ], reachable: false, context: { name: 'Garage Entrance', id: 85, deviceClassName: 'DimmerSwitch' }, _associatedPlugin: 'homebridge-vivint', _associatedPlatform: 'Vivint' }

mceres commented 5 years ago

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?

daymondm commented 5 years ago

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?

mceres commented 5 years ago

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 at Object._errnoException (util.js:1022:11) at _exceptionWithHostPort (util.js:1044:20) at Server.setupListenHandle [as _listen2] (net.js:1367:14) at listenInCluster (net.js:1408:12) at Server.listen (net.js:1492:7) at EventedHTTPServer.listen (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/eventedhttp.js:60:19) at HAPServer.listen (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/HAPServer.js:158:20) at Bridge.Accessory.publish (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:616:16) at Server._publish (/usr/local/lib/node_modules/homebridge/lib/server.js:132:16) at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:101:10) [4/26/2019, 4:42:37 AM] Got SIGTERM, shutting down Homebridge... [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 5 Data.t: energy_service data.ec: undefined Data.n: undefined [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 12 Data.t: network_hosts_service data.ec: undefined Data.n: undefined [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 13 Data.t: panel_diagnostics_service data.ec: undefined Data.n: undefined [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 35 Data.t: wireless_sensor data.ec: 1248 Data.n: Bedroom Glass Break [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 36 Data.t: wireless_sensor data.ec: 1248 Data.n: Living Room Glass Break [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 44 Data.t: phillips_hue_bridge_device data.ec: undefined Data.n: Philips hue [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 45 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Front Outdoor [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 46 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Front Door Lights [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 47 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Belen's [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 48 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Cristian's [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 49 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Master Bedroom [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 20003 Data.t: scheduler_service data.ec: undefined Data.n: undefined [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 70 Data.t: controller_device data.ec: undefined Data.n: Wink [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 84 Data.t: wireless_sensor data.ec: 1269 Data.n: Master Hall Fire Alert [4/26/2019, 4:42:38 AM] [Vivint] Do not know how to handle device! ID: 94 Data.t: multilevel_switch_ip_device data.ec: undefined Data.n: Bathroom [4/26/2019, 4:42:38 AM] [Vivint] Adding 0 new accessories HAP Warning: Characteristic 00000008-0000-1000-8000-0026BB765291 not in required or optional characteristics for service 00000043-0000-1000-8000-0026BB765291. Adding anyway. HAP Warning: Characteristic 00000008-0000-1000-8000-0026BB765291 not in required or optional characteristics for service 00000043-0000-1000-8000-0026BB765291. Adding anyway. [4/26/2019, 4:42:38 AM] [Vivint] Handling incoming device snapshot for timestamp 2019-04-26T04:41:01.308000 status { category: 'PNConnectedCategory', operation: 'PNSubscribeOperation', affectedChannels: [ 'PlatformChannel#H4nf3iAXnxFdsSkptxuv51GZc7eLBpwQ' ], subscribedChannels: [ 'PlatformChannel#H4nf3iAXnxFdsSkptxuv51GZc7eLBpwQ' ], affectedChannelGroups: [], lastTimetoken: 0, currentTimetoken: '15562530192086688' }

daymondm commented 5 years ago

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):

    notify() {
      /*
      if (this.service) {
        if (this.data.val >= 0) {
          this.service
           .getCharacteristic(Characteristic.Brightness)
           .updateValue(this.data.val)
        }

        if (this.data.s == true || this.data.s == false) {
          this.service
            .getCharacteristic(Characteristic.On)
            .updateValue(this.data.s)
        }
        //this.service.getCharacteristic(Characteristic.On)
        //  .updateValue(this.switchCurrentValue())
      }
      */
    }
mceres commented 5 years ago

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.

daymondm commented 5 years ago

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?

mceres commented 5 years ago

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.

daymondm commented 5 years ago

hey try this real quick if you don't mind and see if it corrects that issue:

    notify() {
      if (this.service) {
        if (this.data.val >= 0) {
          this.service
           .getCharacteristic(Characteristic.Brightness)
           .updateValue(this.data.val)
        }

        if (this.data.s == true || this.data.s == false) {
          if (this.data.s == true && this.data.val == 0) this.service.getCharacteristic(Characteristic.On).updateValue(false)
          else {
            this.service
              .getCharacteristic(Characteristic.On)
              .updateValue(this.data.s)
          }
        }
        //this.service.getCharacteristic(Characteristic.On)
        //  .updateValue(this.switchCurrentValue())
      }
mceres commented 5 years ago

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 class LightSwitch extends Device { constructor(accessory) { super(accessory)

  this.service = accessory.getServiceByUUIDAndSubType(Service.Lightbulb) || accessory.getServiceByUUIDAndSubType(Service.Fan) || accessory.getServiceByUUIDAndSubType(Service.Switch)

  this.service
    .getCharacteristic(Characteristic.On)
    .on('get', (next) => next(null,this.switchCurrentValue()))
    .on('set', this.setSwitchCurrentValue.bind(this))
}

switchCurrentValue() {
  return this.data.s
}

setSwitchCurrentValue(targetState, next) {
  if (targetState) {
    // turn switch on
    vivintApi.putDevice('switches', this.id, {s: true, _id: this.id})
      .then(
        (success) => next(),
        (failure) => {
          log("failure " + failure)
          next(failure)
        })
  } else {
    // turn switch off
    vivintApi.putDevice('switches', this.id, {s: false, _id: this.id})
      .then(
        (success) => next(),
        (failure) => {
          log("failure " + failure)
          next(failure)
        })
  }
}

notify() {
  if (this.service) {
    this.service.getCharacteristic(Characteristic.On)
      .updateValue(this.switchCurrentValue())
  }
}

}

extend(LightSwitch, { appliesTo: (data) => { return data.t == "binary_switch_device"}, addServices: (accessory) => { if (accessory.context.name.match(/\blight\b/i)) { accessory.addService(new Service.Lightbulb(accessory.context.name)) } else if (accessory.context.name.match(/\bfan\b/i)) { accessory.addService(new Service.Fan(accessory.context.name)) } else { accessory.addService(new Service.Switch(accessory.context.name)) } } })

// dimmer switch {s: true/false, val: 0-100} class DimmerSwitch extends Device { constructor(accessory) { super(accessory)

  this.service = accessory.getServiceByUUIDAndSubType(Service.Lightbulb)

  this.service
    .getCharacteristic(Characteristic.On)
    .on('get', (next) => next(null,this.switchCurrentValue()))
    .on('set', this.setSwitchCurrentValue.bind(this))

  this.service
    .getCharacteristic(Characteristic.Brightness)
    .on('get', (next) => next(null, this.switchBrightnessValue()))
    .on('set', this.setBrightnessValue.bind(this))
}

switchCurrentValue() {
  return this.data.s
}

setSwitchCurrentValue(targetState, next) {
  if (targetState) {
    // turn switch on
    vivintApi.putDevice('switches', this.id, {s: true, _id: this.id})
      .then(
        (success) => next(),
        (failure) => {
          log("failure " + failure)
          next(failure)
        })
  } else {
    // turn switch off
    vivintApi.putDevice('switches', this.id, {s: false, _id: this.id})
      .then(
        (success) => next(),
        (failure) => {
          log("failure " + failure)
          next(failure)
        })
  }
}

switchBrightnessValue() {
  return this.data.val
}

setBrightnessValue(targetState,next) {
  vivintApi.putDevice('switches', this.id, {val: targetState, _id: this.id})
    .then(
      (success) => next(),
      (failure) => {
        log("failure " + failure)
        next(failure)
      })
}

notify() {
  if (this.service) {
    if (this.data.val >= 0) {
      this.service
       .getCharacteristic(Characteristic.Brightness)
       .updateValue(this.data.val)
    }

    if (this.data.s == true || this.data.s == false) {
      this.service
        .getCharacteristic(Characteristic.On)
        .updateValue(this.data.s)
    }
    //this.service.getCharacteristic(Characteristic.On)
    //  .updateValue(this.switchCurrentValue())
  }
}

}

extend(DimmerSwitch, { appliesTo: (data) => { return data.t == "multilevel_switch_device"}, addServices: (accessory) => { //assuming this is a dimmer switch controlling a light accessory.addService(new Service.Lightbulb(accessory.context.name)) } })

daymondm commented 5 years ago

replace that last bit of code (the notify function):

notify() {
  if (this.service) {
    if (this.data.val >= 0) {
      this.service
       .getCharacteristic(Characteristic.Brightness)
       .updateValue(this.data.val)
    }

    if (this.data.s == true || this.data.s == false) {
      this.service
        .getCharacteristic(Characteristic.On)
        .updateValue(this.data.s)
    }
    //this.service.getCharacteristic(Characteristic.On)
    //  .updateValue(this.switchCurrentValue())
  }
}

with:

    notify() {
      if (this.service) {
        if (this.data.val >= 0) {
          this.service
           .getCharacteristic(Characteristic.Brightness)
           .updateValue(this.data.val)
        }

        if (this.data.s == true || this.data.s == false) {
          if (this.data.s == true && this.data.val == 0) this.service.getCharacteristic(Characteristic.On).updateValue(false)
          else {
            this.service
              .getCharacteristic(Characteristic.On)
              .updateValue(this.data.s)
          }
        }
        //this.service.getCharacteristic(Characteristic.On)
        //  .updateValue(this.switchCurrentValue())
      }
   }
daymondm commented 5 years ago

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

mceres commented 5 years ago

i catch the edit... still behaving the same way.

daymondm commented 5 years ago

copy that, thanks for trying!

mceres commented 5 years ago

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

mceres commented 5 years ago

If i remember correctly the first time we tested with just the on/off switches worked fine with out the device toggling the status.

mceres commented 5 years ago

Also I turned off the wink hub and still the same

daymondm commented 5 years ago

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):

    notify() {
      if (this.service) {
        log("DEBUG [dimmer] s:" + this.data.s + " val:" this.data.val)

        if (this.data.val >= 0) {
          this.service
           .getCharacteristic(Characteristic.Brightness)
           .updateValue(this.data.val)
        }

        if (this.data.s == true || this.data.s == false) {
          this.service
            .getCharacteristic(Characteristic.On)
            .updateValue(this.data.s)
        }
        //this.service.getCharacteristic(Characteristic.On)
        //  .updateValue(this.switchCurrentValue())
      }
    }

this is the same notify function as before.. can you put that in and toggle the switches and paste the result?

mceres commented 5 years ago

[4/26/2019, 6:00:04 AM] ERROR LOADING PLUGIN homebridge-vivint: [4/26/2019, 6:00:04 AM] /usr/local/lib/node_modules/homebridge-vivint/lib/device_set.js:797 log("DEBUG [dimmer] s:" + this.data.s + " val:" this.data.val) ^^^^^^^

SyntaxError: missing ) after argument list at createScript (vm.js:80:10) at Object.runInThisContext (vm.js:139:10) at Module._compile (module.js:616:28) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object. (/usr/local/lib/node_modules/homebridge-vivint/index.js:6:25) [4/26/2019, 6:00:04 AM] ==================== [4/26/2019, 6:00:04 AM] No plugins found. See the README for information on installing plugins. [4/26/2019, 6:00:04 AM] Loading 1 platforms... [4/26/2019, 6:00:04 AM] Error: The requested platform 'Vivint' was not registered by any plugin. at API.platform (/usr/local/lib/node_modules/homebridge/lib/api.js:134:13) at Server._loadPlatforms (/usr/local/lib/node_modules/homebridge/lib/server.js:327:45) at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:90:36) at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:59:10) at Object. (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) [4/26/2019, 6:00:04 AM] Got SIGTERM, shutting down Homebridge...

daymondm commented 5 years ago

sorry forgot a +:

log("DEBUG [dimmer] s:" + this.data.s + " val:" + this.data.val)

mceres commented 5 years ago

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"} [4/26/2019, 6:09:44 AM] [Vivint] DEBUG [dimmer] s:false val:100 [4/26/2019, 6:09:45 AM] [Vivint] received pubNub msg [4/26/2019, 6:09:45 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"s":true}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"51eeffa323673fc4:51eeffa323673fc4:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a0a8c8879f486ec801d2","ts":"2019-04-26T06:09:44.967","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"} [4/26/2019, 6:09:45 AM] [Vivint] DEBUG [dimmer] s:true val:100 ^[[28~[4/26/2019, 6:09:57 AM] [Vivint] received pubNub msg [4/26/2019, 6:09:57 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"val":0}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"3db3c3231a6c5c73:3db3c3231a6c5c73:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a0b58cbd444270f8f68e","ts":"2019-04-26T06:09:57.245","validation":{"args":{"value":[0]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1556258997.044725}}},"op":"u","panid":,"parid":1,"t":"account_partition"} [4/26/2019, 6:09:57 AM] [Vivint] DEBUG [dimmer] s:true val:0 [4/26/2019, 6:09:57 AM] [Vivint] received pubNub msg [4/26/2019, 6:09:57 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"s":false}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"599f5e932ff52a8a:599f5e932ff52a8a:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a0b58cbd444270f8f68e","ts":"2019-04-26T06:09:57.342","validation":{"args":{"value":[0]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1556258997.044725}}},"op":"u","panid":,"parid":1,"t":"account_partition"} [4/26/2019, 6:09:57 AM] [Vivint] DEBUG [dimmer] s:false val:0

daymondm commented 5 years ago

ok replace that notify function with this:

    notify() {
      if (this.service) {
        //log("DEBUG [dimmer] s:" + this.data.s + " val:" + this.data.val)

        if (this.data.val == 0) {
          this.service
            .getCharacteristic(Characteristic.On)
            .updateValue(false)
        } else {
          this.service
            .getCharacteristic(Characteristic.On)
            .updateValue(true)
        }

        this.service
          .getCharacteristic(Characteristic.Brightness)
          .updateValue(this.data.val)
      }
    }
mceres commented 5 years ago

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"} [4/26/2019, 6:17:58 AM] [Vivint] received pubNub msg [4/26/2019, 6:17:58 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":89,"s":false}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"70dcb10e50d07504:70dcb10e50d07504:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a2953916b20051b43987","ts":"2019-04-26T06:17:57.874","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"}

daymondm commented 5 years ago

are you getting another message that says "val":100 when you turn those binary switches on?

mceres commented 5 years ago

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 [4/26/2019, 6:23:43 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":89,"val":100}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"36470f3295072ecd:36470f3295072ecd:0:1"}},"mid":"5cc2a3ef74af720001781c51","ts":"2019-04-26T06:23:43.246"}},"op":"u","panid":,"parid":1,"t":"account_partition"} [4/26/2019, 6:23:43 AM] [Vivint] received pubNub msg [4/26/2019, 6:23:43 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":89,"val":100}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"36470f3295072ecd:36470f3295072ecd:0:1"}},"mid":"5cc2a3ef74af720001781c51","ts":"2019-04-26T06:23:43.246"}},"op":"u","panid":,"parid":1,"t":"account_partition"} [4/26/2019, 6:23:43 AM] [Vivint] received pubNub msg [4/26/2019, 6:23:43 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":89,"s":true}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"6ff30604c1bd5aa8:6ff30604c1bd5aa8:0:1"}},"mid":"5cc2a3ef74af720001781c6f","ts":"2019-04-26T06:23:43.335"}},"op":"u","panid":,"parid":1,"t":"account_partition"}

daymondm commented 5 years ago

ok so the notify function you have for those switches looks like this:

    notify() {
      if (this.service) {
        this.service.getCharacteristic(Characteristic.On)
          .updateValue(this.switchCurrentValue())
      }
    }

change it to this:

notify() {
      if (this.service) {
        if (this.data.val == 0) {
          this.service
            .getCharacteristic(Characteristic.On)
            .updateValue(false)
        } else {
          this.service
            .getCharacteristic(Characteristic.On)
            .updateValue(true)
        }
      }
    }
mceres commented 5 years ago

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"} [4/26/2019, 6:30:41 AM] [Vivint] received pubNub msg [4/26/2019, 6:30:41 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"s":false}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"1d257c20eaddbe08:1d257c20eaddbe08:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a590c8879f4456cf7889","ts":"2019-04-26T06:30:40.999","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"} [4/26/2019, 6:30:43 AM] [Vivint] received pubNub msg [4/26/2019, 6:30:43 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"val":100}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"138805b158989c51:138805b158989c51:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a5938cbd44005e2552ea","ts":"2019-04-26T06:30:43.615","validation":{"args":{"value":[100,true]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1556260243.396211}}},"op":"u","panid":,"parid":1,"t":"account_partition"} [4/26/2019, 6:30:43 AM] [Vivint] received pubNub msg [4/26/2019, 6:30:43 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"s":true}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"2527a8a21868aef2:2527a8a21868aef2:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a5938cbd44005e2552ea","ts":"2019-04-26T06:30:43.693","validation":{"args":{"value":[100,true]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1556260243.396211}}},"op":"u","panid":,"parid":1,"t":"account_partition"} [4/26/2019, 6:30:46 AM] [Vivint] received pubNub msg [4/26/2019, 6:30:46 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"val":0}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"115c281e59eb11ae:115c281e59eb11ae:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a59611188d005203dd39","ts":"2019-04-26T06:30:46.213","validation":{"args":{"value":[0]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1556260246.030391}}},"op":"u","panid":,"parid":1,"t":"account_partition"} [4/26/2019, 6:30:46 AM] [Vivint] received pubNub msg [4/26/2019, 6:30:46 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"s":false}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"5d403b3f965c9eb2:5d403b3f965c9eb2:0:1"}},"ctxd":null,"ctxid":"5cad6f8e19a7d8004f09f422","ctxt":10,"mid":"5cc2a59611188d005203dd39","ts":"2019-04-26T06:30:46.294","validation":{"args":{"value":[0]},"method":["on_property_updated"],"module":["binary_switch_device","multilevel_switch_device"],"timestamp":1556260246.030391}}},"op":"u","panid":,"parid":1,"t":"account_partition"} [4/26/2019, 6:30:46 AM] [Vivint] received pubNub msg [4/26/2019, 6:30:46 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"val":79}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"18796075d0237885:18796075d0237885:0:1"}},"mid":"5cc2a5960f71c10001a55ddf","ts":"2019-04-26T06:30:46.848"}},"op":"u","panid":,"parid":1,"t":"account_partition"} [4/26/2019, 6:30:47 AM] [Vivint] received pubNub msg [4/26/2019, 6:30:47 AM] [Vivint] {"_id":"7656642868867671|1","da":{"d":[{"_id":75,"s":true}],"plctx":{"context_carrier":{"previous_handler":"Subscriber Update Handler","tracing_context":{"uber-trace-id":"ce009c74cd763e7:ce009c74cd763e7:0:1"}},"mid":"5cc2a5961b0a98000197de80","ts":"2019-04-26T06:30:46.948"}},"op":"u","panid":,"parid":1,"t":"account_partition"}

daymondm commented 5 years ago

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?

mceres commented 5 years ago

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

daymondm commented 5 years ago

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:'

    setBrightnessValue(targetState,next) {
      vivintApi.putDevice('switches', this.id, {val: targetState, _id: this.id})
        .then(
          (success) => next(),
          (failure) => {
            log("failure " + failure)
            next(failure)
          })
    }

change to:

    setBrightnessValue(targetState,next) {
      log("updating brightness level: " + targetState)
      vivintApi.putDevice('switches', this.id, {val: targetState, _id: this.id})
        .then(
          (success) => next(),
          (failure) => {
            log("failure " + failure)
            next(failure)
          })
    }
daymondm commented 5 years ago

does it even call that routine if you just turn the light on and off without adjusting the brightness?

daymondm commented 5 years ago

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.

kody-redlist commented 4 years ago

Hey just checking in here, what’s the status of this issue and how can I help?

timcharper commented 4 years ago

Open a PR :)

Also, if you could add unit tests, that'd be swell.