Supereg/homebridge-http-switch

statusPattern not working as expected

Closed this issue · 1 comments

Describe the bug

I'm not sure this is being a bug.
More likely a support request to setup a working statusPattern...

I've got this endpoint http://hyperhdr.local/json-rpc?xxxx
It returns me the following JSON body (truncated version):

{
    "command": "serverinfo",
    "info": {
        "videomodehdr": 0
    },
    "success": true,
    "tan": 0
}

I would like to use the videomodehdr property to get the state of my stateful switch:

  • "videomodehdr": 0 => Switch OFF
  • "videomodehdr": 1 => Switch ON

To do so I set up the statusPattern property as following:
"statusPattern": "/.*\"videomodehdr\": 1.*/gms"

But the switch status is aways being detected as OFF.

Expected behavior
The statusPattern/RegEx "statusPattern": "/.*\"videomodehdr\": 1.*/gms" to correctly set my switch status.

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

  • homebridge: 1.4.0
  • homebridge-http-switch: 0.5.35

Configuration

{
    "accessory": "HTTP-SWITCH",
    "name": "Ambi HDR",
    "switchType": "stateful",
    "onUrl": "http://hyperhdr.local:8090/json-rpc?request=%7B%22command%22:%22componentstate%22,%22componentstate%22:%7B%22component%22:%22HDR%22,%22state%22:true%7D%7D",
    "offUrl": "http://hyperhdr.local:8090/json-rpc?request=%7B%22command%22:%22componentstate%22,%22componentstate%22:%7B%22component%22:%22HDR%22,%22state%22:false%7D%7D",
    "statusUrl": "http://hyperhdr.local:8090/json-rpc?request=%7B%22command%22:%22serverinfo%22%7D",
    "statusPattern": "/.*\"videomodehdr\": 1.*/gms",
    "debug": true,
    "pullInterval": 50000
}

Hey @mbotalend, i had a similar issue and found out i need to "skip" whitespaces, beause the get striped out by the plugin. I guess the Phrasing of the Return-Body is the issue here.

However, if you enable debug mode and just copy the Logged status-Body, you'll see there are no whitespaces or returns. So, you'll need to test your regex with this "truncaded" response body.

In my Case, this is the response from the API (Postman):

{
    "isok": true,
    "data": {
        "online": true,
        "device_status": {
            "unixtime": 1651765690,
            "uptime": 969775,
            "mqtt": {
                "connected": false
            },
            "update": {
                "status": "idle",
                "has_update": false,
                "new_version": "20220209-095044/v1.11.8-g8c7bb8d",
                "old_version": "20220209-095044/v1.11.8-g8c7bb8d"
            },
            "actions_stats": {
                "skipped": 0
            },
            "time": "18:10",
            "wifi_sta": {
                "connected": true,
                "ssid": "Media",
                "ip": "192.168.20.71",
                "rssi": -67
            },
            "ram_total": 49960,
            "fs_free": 146835,
            "relays": [
                {
                    "ison": false,
                    "has_timer": false,
                    "timer_started": 0,
                    "timer_duration": 0,
                    "timer_remaining": 0,
                    "source": "cloud"
                },
                {
                    "ison": true,
                    "has_timer": false,
                    "timer_started": 0,
                    "timer_duration": 0,
                    "timer_remaining": 0,
                    "source": "cloud"
                }
            ],
            "has_update": false,
            "mac": "98CDAC252550",
            "serial": 28132,
            "cloud": {
                "enabled": true,
                "connected": true
            },
            "ext_humidity": [],
            "inputs": [
                {
                    "input": 0,
                    "event": "",
                    "event_cnt": 0
                },
                {
                    "input": 0,
                    "event": "",
                    "event_cnt": 0
                }
            ],
            "_updated": "2022-05-05 16:10:24",
            "ext_sensors": [],
            "ext_temperature": [],
            "fs_size": 233681,
            "ram_free": 38472,
            "cfg_changed_cnt": 1,
            "adcs": [
                {
                    "voltage": 0
                }
            ]
        }
    }
}

This is processed by the Plugin (copied from Terminal viewing the hb-log):
{"isok":true,"data":{"online":true,"device_status":{"unixtime":1651765690,"uptime":969775,"mqtt":{"connected":false},"update":{"status":"idle","has_update":false,"new_version":"20220209-095044\/v1.11.8-g8c7bb8d","old_version":"20220209-095044\/v1.11.8-g8c7bb8d"},"actions_stats":{"skipped":0},"time":"18:06","wifi_sta":{"connected":true,"ssid":"Media","ip":"192.168.20.71","rssi":-67},"ram_total":49960,"fs_free":146835,"relays":[{"ison":false,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"source":"cloud"},{"ison":true,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"source":"cloud"}],"has_update":false,"mac":"98CDAC252550","serial":28059,"cloud":{"enabled":true,"connected":true},"ext_humidity":[],"inputs":[{"input":0,"event":"","event_cnt":0},{"input":0,"event":"","event_cnt":0}],"_updated":"2022-05-05 16:06:56","ext_sensors":[],"ext_temperature":[],"fs_size":233681,"ram_free":38472,"cfg_changed_cnt":1,"adcs":[{"voltage":0.02}]}}}

I guess, in your case, this whitespace here is the /.*"videomodehdr": ← Problem

By the way, it took me only 2 Hours to find this out 🤯 😁