Supereg / homebridge-http-lightbulb

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

Incorrectly sees status of device. #25

Closed petedavey closed 4 months ago

petedavey commented 4 months ago

With the following code:

{
    "accessory": "HTTP-LIGHTBULB",
    "name": "Hypercube",
    "debug": true,
    "onUrl": {
        "url": "http://192.168.50.212/json/state",
        "method": "PUT",
        "body": "{ \"on\": true }"
    },
    "offUrl": {
        "url": "http://192.168.50.212/json/state",
        "method": "PUT",
        "body": "{ \"on\": false }"
    },
    "statusUrl": {
        "url": "http://192.168.50.212/json/state",
        "method": "GET",
        "headers": {
            "Content-Type": "application/json"
        },
        "statusPattern": "\"on\":true",
    },
    "brightness": {
        "statusUrl": {
            "url": "http://192.168.50.212/json/state",
            "method": "GET",
            "headers": {
                "Content-Type": "application/json"
            }
        },
        "setUrl": {
            "url": "http://192.168.50.212/json/state",
            "method": "PUT",
            "body": "{ \"bri\": %s }"
        },
        "unit": "rgb",
        "statusPattern": "\"bri\"\\s*:\\s*(\\d+)",
        "patternGroupToExtract": 1
    },
    "_bridge": {
        "username": "0E:4A:AB:9A:EE:D7",
        "port": 48532
    }
}

I see this in the logs:

[12/04/2024, 17:05:59] [Hypercube] getPowerState() request returned successfully (200). Body: '{"on":false,"bri":254,"transition":8,"sb":false,"ps":-1,"pss":0,"pl":-1,"fb":0,"nl":{"on":false,"dur":60,"fade":false,"tbri":0},"udpn":{"send":true,"recv":true},"seg":[{"start":0,"stop":480,"len":480,"col":[[255,159,0],[0,0,0],[0,0,0]],"fx":1,"sx":0,"ix":0,"pal":0,"sel":true,"rev":false,"psd":false,"sym":3}]}' [12/04/2024, 17:05:59] [Hypercube] getPowerState() power is currently ON

Even though "on" clearly shows false.

Is this because I have two statuspatterns? One for power one for brightness? unit is set to RGB as the brightness of this device is 1-255.

Supereg commented 4 months ago

The statusPattern must be on the same level as the statusUrl (similar on how you did it in the brightness object), see options here.

So the correct configuration should look like the following. Let me know if that worked for you 👍

{
    "accessory": "HTTP-LIGHTBULB",
    "name": "Hypercube",
    "debug": true,
    "onUrl": {
        "url": "http://192.168.50.212/json/state",
        "method": "PUT",
        "body": "{ \"on\": true }"
    },
    "offUrl": {
        "url": "http://192.168.50.212/json/state",
        "method": "PUT",
        "body": "{ \"on\": false }"
    },
    "statusUrl": {
        "url": "http://192.168.50.212/json/state",
        "method": "GET",
        "headers": {
            "Content-Type": "application/json"
        }
    },
    "statusPattern": "\"on\":true",
    "brightness": {
        "statusUrl": {
            "url": "http://192.168.50.212/json/state",
            "method": "GET",
            "headers": {
                "Content-Type": "application/json"
            }
        },
        "setUrl": {
            "url": "http://192.168.50.212/json/state",
            "method": "PUT",
            "body": "{ \"bri\": %s }"
        },
        "unit": "rgb",
        "statusPattern": "\"bri\"\\s*:\\s*(\\d+)",
        "patternGroupToExtract": 1
    },
    "_bridge": {
        "username": "0E:4A:AB:9A:EE:D7",
        "port": 48532
    }
}
petedavey commented 4 months ago

wow. spent hours on this. appreciate your quick response, works great.

Supereg commented 4 months ago

Great that this got resolved so quickly