Supereg / homebridge-http-lightbulb

Powerful http lightbulb for Homebridge: https://github.com/homebridge/homebridge
ISC License
23 stars 7 forks source link

Error: Error setting for 'Color Temperature': 'minValue' cannot be greater or equal the 'maxValue' #16

Closed ascl00 closed 3 years ago

ascl00 commented 3 years ago

Describe the bug Configuring a colorTemp range (in kelvin) seems to result in this error: Error: Error setting for 'Color Temperature': 'minValue' cannot be greater or equal the 'maxValue'Error

Expected behavior Well, for the config to work!

To Reproduce Steps to reproduce the behavior:

        "colorTemperature": {
            "statusUrl": {
                "url": "http://nanoleaf.hades/api/v1/xxxxxxx/state/ct",
                "method": "GET"
            },
            "statusPattern": "{\"value\":([0-9]{1,3}),\"max\":100,\"min\":0}",
            "unit": "kelvin",
            "minValue": 1200,
            "maxValue": 6500,
            "setUrl": {
                "headers": { "Content-Type" : "application/json" },
                "url": "http://nanoleaf.hades/api/v1/xxxxxx/state",
                "method": "PUT",
                "body": "{ \"ct\": { \"value\" : %s }}"
            }
        }

Config as above. Error on startup:

1|homebrid | [2/27/2021, 1:55:11 PM] Error: Error setting CharacteristicsProps for 'Color Temperature': 'minValue' cannot be greater or equal the 'maxValue'!
1|homebrid |     at ColorTemperature.Characteristic.setProps (/home/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:1129:15)
1|homebrid |     at new HTTP_LIGHTBULB (/home/homebridge/node_modules/homebridge-http-lightbulb/index.js:135:14)
1|homebrid |     at /home/homebridge/node_modules/homebridge/src/server.ts:290:50
1|homebrid |     at Array.forEach (<anonymous>)
1|homebrid |     at Server.loadAccessories (/home/homebridge/node_modules/homebridge/src/server.ts:221:29)
1|homebrid |     at Server.start (/home/homebridge/node_modules/homebridge/src/server.ts:119:12)

Version (output of npm list -g homebridge homebridge-http-lightbulb)

$ npm list  homebridge homebridge-http-lightbulb
/home/homebridge
+-- homebridge@1.3.1 
`-- homebridge-http-lightbulb@1.2.3 

Configuration

        "colorTemperature": {
            "statusUrl": {
                "url": "http://nanoleaf.hades/api/v1/xxxxxxx/state/ct",
                "method": "GET"
            },
            "statusPattern": "{\"value\":([0-9]{1,3}),\"max\":100,\"min\":0}",
            "unit": "kelvin",
            "minValue": 1200,
            "maxValue": 6500,
            "setUrl": {
                "headers": { "Content-Type" : "application/json" },
                "url": "http://nanoleaf.hades/api/v1/xxxxxx/state",
                "method": "PUT",
                "body": "{ \"ct\": { \"value\" : %s }}"
            }
        }

Additional context Seems likely to be related to the Characteristics changes in homebridge 1.3

ascl00 commented 3 years ago

So... this is user error, but I think it'd be useful to at least document this (if not deal with it in the code). As "mired" values get smaller, "kelvin" values get bigger, since the conversion from kelvin to mired is (as I have since learned) m = 1,000,000/k . This makes "min" and "max" inverted to what I would expect when configuring a kelvin device.

So, AFAICT, the correct configuration for my device is:

"unit":"kelvin",
"minValue":6500,
"maxValue":1200

... which is far from intuitive!