Service Type issue
Closed this issue · 5 comments
So have been having a look at the code for index.js, to try to figure out Device Types.
it appears that the code is only set up for lightbulbs, meaning that in my HomeKit app (Eve), all switches appear as lightbulbs
So invoking "Hey Siri, switch off all the upstairs lights" also switches off the fan, and the baby monitor connected to the LW outlets.
Here's what I've found. Now I admittedly don't know the right code to change the way this works, but here's where it's currently going wrong (for switches)
Line 64: this.isDimmer = (device.deviceType.indexOf('D') > -1);
ok fine, it's either a Dimmer, or it's not.
Line 183:
case 'power': if (value > 0) { if(this.isDimmer) { if(this.previousPercentage < 3.125 ) this.previousPercentage = 100; // Prevent very low last states this.api.setDeviceDim(this.roomId,this.deviceId,this.previousPercentage,callback); this.status = this.previousPercentage; } else { this.api.turnDeviceOn(this.roomId,this.deviceId,callback); this.status = 100; } }
So basically we're telling it to set a dimmer to a percentage, rather than on or off
Here's where the problem with that is:
Line 255:
`lightbulbService
.getCharacteristic(Characteristic.On)
.on('get', function(callback) { that.getState("power", callback);})
.on('set', function(value, callback) { that.executeChange("power", value, callback);})
.value = this.extractValue("power", this.status);
lightbulbService
.addCharacteristic(Characteristic.Brightness)
.on('get', function(callback) { that.getState("brightness", callback);})
.on('set', function(value, callback) { that.executeChange("brightness", value, callback);})
.value = this.extractValue("brightness", this.status);
lightbulbService.getCharacteristic(Characteristic.Brightness)
.setProps({ minStep: 1 })
this.lightbulbService = lightbulbService;
`
We're setting the Brightness characteristic, whether isDimmer is true or false, so all devices regardless of type (D, or not D) have a brightness characteristic in the HomeKit. This bit is easy to fix... just stick the brightness characteristic block inside an If isDimmer.
I believe that additional DeviceTypes/Services could be configured easily enough with setting additional flags up by Line 64.
HAP-nodeJS/HomeKitTypes.js defines additional Services like: Outlet, Switch, or StatelessProgrammableSwitch. Utilising one of these would allow outlets and switches to "appear" as outlets or switches in HomeKit, and therefore not be affected by bulk lighting changes.
Hi,
I've just pushed a new version with Lights Dimmers and Switches as deviceTypes: L, D, S
I don't have any switches so I cannot test it... could you?
Roy
I'm running sudo npm update -g homebridge-lightwaverf, but it's not pulling the new index.js
oops, forgot the publish the new version. Please try again
@rooi Awesome! It works perfectly!
I've got Switches, and Lights without Dimmers, they look really good in the Eve app 😊
Now... I don't have any Thermostats, or Energy Monitors, but I've been looking at getting some... I bet that's a whole new kettle of fish, isn't it... considering that they're stateful devices.