arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
466 stars 104 forks source link

Ignoring invalid value #510

Closed satiromarra closed 2 years ago

satiromarra commented 2 years ago

When a device is defined as RGB or HSV, the Brightness value received is float. [RGB] Ignoring invalid value [29.01960784313726] for Brightness - not an integer

The configuration does not allow modifying the Brigthness value: If topics.setRGB is populated .... brightness, hue and saturation topics are ignored. If topics.setHSV is populated, a combined value is used and any individual brightness, hue, saturation and color temperature topics are ignored.

Posible solution in "function isValid" add a condition before check "isInteger":

if( typeof value === 'number' ) {
    value = Number.parseInt(value);
}

after:

if( typeof value === 'number' ) {
    value = Number.parseInt(value);
}
if( ! Number.isInteger( value ) ) {
    log( `Ignoring invalid value [${value}] for ${charac.displayName} - not an integer` );
    return false;
}
lukebrannon1 commented 2 years ago

I am having this same issue and unable to get the proper brightness value. Any fixes for this?

arachnetech commented 2 years ago

For now you can write an apply function which converts the incoming floating point number to an integer to get around this.

I am tempted to relax the validation by converting numbers to integers automatically, but I haven't had a chance to make this change yet.

arachnetech commented 2 years ago

Actually, rereading the issue I may have misunderstood the issue. I need to reproduce...

Do you have a sample Config and a sample MQTT message which causes this issue?

satiromarra commented 2 years ago

config:

"accessories": [ 
...
{
    "accessory": "mqttthing",
    "type": "lightbulb",
    "url": "mqtt://xxxxxx:1883",
    "mqttPubOptions": {
        "retain": true
    },
    "topics": {
        "getOn": "DimmerRgb1",
        "setOn": "DimmerRgb1",
        "getRGB": "DimmerRgb1/rgb",
        "setRGB": "DimmerRgb1/rgb"
    },
    "integerValue": false,
    "onValue": "on",
    "offValue": "off",
    "retain": true,
    "name": "RGB"
},
...

log: [RGB] Ignoring invalid value [29.01960784313726] for Brightness - not an integer

Steps to reproduce error: In iOS or macOS, open Home app, next activate RGB item and select any color, then view the log file.

lukebrannon1 commented 2 years ago

@satiromarra's description above matches mine, but if you need my config as well I can provide it. It seems the brightness value is being derived from the RGB values instead of from an MQTT message, so I'm not seeing a way to fix this in my config.

arachnetech commented 2 years ago

Thanks, both. Very helpful. Sorry, I had initially misunderstood.

arachnetech commented 2 years ago

Should be fixed in version 1.1.39.

satiromarra commented 2 years ago

Updated and works perfectly. Good job! Thanks a lot