jvmahon / Homebridge-HomeSeer4

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

characteristic 'Current Ambient Light Level': characteristic was supplied illegal value. #186

Closed emiliosic closed 2 years ago

emiliosic commented 2 years ago

Getting this error when reading a Z-Wave light sensor at night: [homebridge-homeseer4] This plugin generated a warning from the characteristic 'Current Ambient Light Level': characteristic was supplied illegal value: number 0 exceeded minimum of 0.0001. See https://homebridge.io/w/JtMGR for more info.

A simple hack to resolve this issue is this:

diff --git a/lib/Setup Sensor.js b/lib/Setup Sensor.js
index 6607519..d0951e6 100644
--- a/lib/Setup Sensor.js
+++ b/lib/Setup Sensor.js
@@ -134,6 +134,9 @@ exports.setupSensor = function (newDevice, services) {
                                .on('HSvalueChanged', (newHSValue, homekitObject) => {
                                                var newLightLevel =  Math.min(Math.max(newHSValue, ambientLight.props.minValue), ambientLight.props.maxValue )
                                                newLightLevel = Math.round(newLightLevel * 100) / 100
+                                               if (newLightLevel < 0.0001) {
+                                                       newLightLevel = 0.0001;
+                                               }
                                                homekitObject.updateValue(newLightLevel)
                                        })
                        break;
jvmahon commented 2 years ago

I think it works if you just flip the order of the code so you round to two digits first, then do the min / max analysis.:

var newLightLevel =  Math.round( newHSValue * 100) / 100
newLightLevel =  Math.min(Math.max( newLightLevel, ambientLight.props.minValue), ambientLight.props.maxValue )

Then you don't need the added "if" block. Can you give it a try and let me know if this works.

jvmahon commented 2 years ago

Actually, I went ahead and made that change, so try the update to version 1.0.35.