jvmahon / Homebridge-HomeSeer4

Homebridge Plugin for HomeSeer 3 and 4
29 stars 8 forks source link

100 Percent Issue #136

Closed meluvalli closed 3 years ago

meluvalli commented 3 years ago

Hello. I'm having a strange issue.

If I ask Alexa to set my light to 100 percent, it responds back saying the device doesn't support that. I can however set it to anything between 1-98 percent.

I have already posted an issue with the Alexa plugin developer and we tried trouble shooting it. The developer recommend I post the issue here as we do not think it's the Alexa Plugin problem.

I have a feeling it has something to do with the way my Z-Wave devices got added to HomeSeer. I am attaching the images for your reference.

In Image 1, this was the way HomeSeer added the device (Untouched). As you can see, the Diming function is any percent 1-98 where 99 is ON and 100 Doesn't exist.

In Image 2, I changed the light and made 1-100 being a Dimming function. Then tried to delete the device and re-add it into HomeBridge. Device was deleted, verified removed from HomeKit, then I re-added it and set it up again in HomeKit. I then deleted the device in Alexa and rediscovered it in there as well. After doing so, Alexa still can't set the light to 99 or 100 percent.

Image1: Light

Image2: Light-New

Link to HomeBridge-Alexa Issue for reference: https://github.com/NorthernMan54/homebridge-alexa/issues/414

jvmahon commented 3 years ago

Hi, Not sure I can be of much help here as I don't use Alexa and don't know much about its internals, and there should be no interaction between that plugin and mine, but two thoughts . . . .

First, don't change your HomeSeer Status Graphics to include 100. Z-wave dimming devices only recognize 0 - 99 and 255 so the value "100" won't work.

Second, since HomeSeer / Z-Wave doesn't recognize "100", the plugin must accommodate for that. Here's what I do. In my library file "HomeKitDevicesetup.js", I create a lightbulb with the Brightness property. Line 1186 sets up the brightness property.

thisService.multilevelControl = thisService.addCharacteristic(new Characteristic.Brightness())

Then at line 1304 in that file, I use the '.setProps' property to set the maximumValue to 99 (that value is stored in that.config.levels).

thisService.multilevelControl
    .setConfigValues(that.config)
    .setProps({maxValue:that.config.levels})

'that.config.levels" was set at line 398 in the file "DeviceDefaults.js".

So, in my plugin, if the iOS device requests 100%, it will, instead, be set at the maximum value of 99.

Now, if I were doing this again, I'd probably take an easier route and simply do something like:

Before line 1314 in my code, the .on('set' ...) function, add

if (homekit request 100) map to 99 then send to HomeSeer

And when processing data received from HomeSeer (line 1339),, then in the .on('HSvalueChanged block,

Before lines 1364 and 1370, I'd add

if (newValue == 99 received from HomeSeer), map it back to 100 then do the .updateValue(newValue) call

So, I'd suggest the Alexa plugin author check if they do that mapping -- i.e., if Alexa request 100, map to 99 and send to HomeSeer. If HomeSeer reports 99, map back to 100 and tell Alex.

The one issue with this approach -- if the user actually has a bulb that does support 100% (e.g., Zigbee / Hue/ or via some other plugin, then this may set the bulb incorrectly. The way to fix that would be to look at the HomeSeer "status" data for the actual device. In my plugin, I have a function that retrieves that. See file "HomeSeerSystemObject.js", line 298. This returns the status properties for the device. The plugin could then look at that data - the format of that data is shown at lines 16-81 of that file. The plugin would have to look at the data shown in the ControlPairs section (lines 52-61) to get the "true" range supported. Note that I show only a single one of the ControlPairs [0], there can be multiple, so you have to do a "find" on the ControlPairs array to get the right one by also looking at ControlType (line 65) or maybe it was ControUse (line 74) or ControValue (line 75) - I forget. In any case, I'm no longer using HomeSeer, so I never finished added that level of analysis to my code, but the needed structure is there for retrieving the data.

NorthernMan54 commented 3 years ago

Thanks for the detailed response on this,I didn't realize that this was a bulb / device issue but had thought it was a configuration issue with @meluvalli's setup. I looked at the API on the Amazon side, and they don't support adjusting the range of valid values, and just pass the value spoken by the end user. This API is here

https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-powerlevelcontroller.html

Thinking about this further, it appears that everything is working as designed. The Alexa service is passing the spoken value to the Homeseer plugin, and the Homeseer plugin is just saying that 100% is an invalid value. This is similar to asking for a value over 100, and her responding back with an 'invalid value' message.

jvmahon commented 3 years ago

Yes, I think you're correct that when Alexa gets a 100% it sends that to HomeSeer which then can't process it. But as this is predictable problem, maybe you can solve it like I suggested - i.e., if Alexa instructs a change to 100% send that to HomeSEer as a 99 and if HomeSeer sends a 99, tell Alexa that is 100%. Good luck.