Supereg / homebridge-http-switch

Powerful http switch for Homebridge: https://github.com/homebridge/homebridge
ISC License
218 stars 36 forks source link

statusPattern regex not working #86

Closed Shaft405 closed 3 years ago

Shaft405 commented 3 years ago

Hello,

I have this issue with statusUrl and stateful switchType.

My http request returns the correct device status :

getStatus() request returned successfully (200). Body: '{"power":"On"}'

So I have added the statusPattern option to statusUrl:

"statusUrl": { "url": "http://x.x.x.x/power", "method": "GET", "statusPattern": "{\"power\":\"On\"}" }

But the switch status is never updated and log return "Switch is currently OFF"

I even tried to use a stupid "match all" regex but it does not even set to switch to enable.

"statusUrl": { "url": "http://x.x.x.x/power", "method": "GET", "statusPattern": ".*" }

Help would be much appreciated... Thanks!

Supereg commented 3 years ago

The statusPattern must be placed on the same level as the statusUrl property, not inside the statusUrl object.

like



{
    ...
    "statusUrl": {
        ...
    },
    "statusPattern": "....",
    ...
}
luc-ass commented 3 years ago

Hey @Shaft405, this looks like you were trying to implement a switch for your ambilight TV. Have you got it working? Mind sharing your configuration?

Shaft405 commented 3 years ago

Hi @luc-ass

Here is a starting point for your configuration

{
    "accessory": "HTTP-SWITCH",
    "name": "Ambilight",
    "switchType": "stateful",
    "pullInterval": "60000",
    "onUrl": {
        "url": "http://x.x.x.x:1925/6/ambilight/currentconfiguration",
        "method": "POST",
        "body": "{\"styleName\":\"FOLLOW_VIDEO\",\"isExpert\":false,\"menuSetting\":\"IMMERSIVE\"}"
    },
    "offUrl": {
        "url": "http://x.x.x.x:1925/6/ambilight/power",
        "method": "POST",
        "body": "{\"power\":\"Off\"}"
    },
    "statusUrl": {
        "url": "http://x.x.x.x:1925/6/ambilight/power",
        "method": "GET"
    },
    "statusPattern": "{\"power\":\"On\"}"
}

An issue is that if the TV is switched off while Ambilight is ON, the status cannot be updated and it remains shown as ON. Other annoyance is that while TV is OFF we get lots of connexions error in the HomeBridge logs every time the plugin tries to refresh.

I wish homebridge-http-switch could just consider a non-reachable URL as just being OFF for a stateful switch.

If you find a better way please let me know :)

luc-ass commented 3 years ago

Yeah, it's a workaround for me as well because the Philips Saphi OS Plug-in doesn't support it. Right now I just don't have the time to contribute but maybe some time in the future...