Supereg / homebridge-http-switch

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

Cannot read stare from status url #35

Closed Dr4il closed 5 years ago

Dr4il commented 5 years ago

Hello, I have an problem with status url. When I'm adding url status, it don't have coverage on real states. Link for reading status is for example: https://svr1.supla.org/direct/554/yDzzMYYMmUN/read output for curl is: {"connected":true,"on":false} I think that's a problem is a response for this url. How can I can fix this? I don't have any option to change server response.

Supereg commented 5 years ago

I don’t quite understand what you mean? What do you mean with „coverage on real states“. Is the „pullTimer“ option (refer to the README) what you are looking for? Or do you just want to specify a custom response? Then look at the „statusPattern“ option

Dr4il commented 5 years ago

Homebridge is not able to check status of device. For example, when I turn on light, then restart the app, light will be shown as disabled. I thought it was caused by form of this api.

Supereg commented 5 years ago

You can define custom api responses using the statusPattern property (refer to README). There you can define which response represents the ON state. For your mentioned response something like the following should work:

"statusPattern": "\"on\”:true",

Just add that to the configuration of the plugin. Side-note: would be best practice if you type it yourself, it had bad experiences when people copied the backslash resulting in the pattern not working.

Dr4il commented 5 years ago

Maybe it is a problem with syntax because "\"on\”:true" is identified with error "Bad string". I tried to create another regexp "\"on:'true'" but it isnt working. Do you have another idea?

Supereg commented 5 years ago

Where exactly does it print that error? Can I get the full error message? Could you maybe attach your configuration for the plugin.

Dr4il commented 5 years ago

This is my full config for this switch

{
            "accessory": "HTTP-SWITCH",
            "name": "Garage",
            "switchType": "stateful",
            "onUrl": "https://svr1.supla.org/direct/xxx/xxxxxxxxx/turn-on",
            "offUrl": "https://svr1.supla.org/direct/xxx/xxxxxxxxx/turn-off",
            "statusUrl": {
                "url": "https://svr1.supla.org/direct/xxx/xxxxxxxx/read",
                "method": "GET",
                "statusPattern": "\"on\":true"
            }
}

Where I can find logs of plugin? I can check only logs from entire homebridge without any details about plugins. This is a raw of homebridge logs:

[2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookSensor' [2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookSwitch' [2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookPushButton' [2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookLight' [2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookThermostat' [2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookOutlet' [2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookSecurity' [2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookGarageDoorOpener' [2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookStatelessSwitch' [2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookLockMechanism' [2019-6-11 12:41:01] Registering accessory 'homebridge-http-webhooks.HttpWebHookWindowCovering' [2019-6-11 12:41:01] --- [2019-6-11 12:41:01] Loaded plugin: homebridge-samsung-remote [2019-6-11 12:41:01] Registering accessory 'homebridge-samsung-remote.SamsungTV' [2019-6-11 12:41:01] --- [2019-6-11 12:41:01] Loaded plugin: homebridge-samsung-tizen [2019-6-11 12:41:01] Registering platform 'homebridge-samsung-tizen.SamsungTizen' [2019-6-11 12:41:01] --- [2019-6-11 12:41:01] Loaded plugin: homebridge-config-ui-x [2019-6-11 12:41:01] Registering platform 'homebridge-config-ui-x.config' [2019-6-11 12:41:01] --- [2019-6-11 12:41:01] Loading 0 platforms... [2019-6-11 12:41:01] Loading 6 accessories... [2019-6-11 12:41:01] [Living Room TV] Initializing SamsungTV accessory... [2019-6-11 12:41:01] [Around home] Initializing HTTP-SWITCH accessory... [2019-6-11 12:41:01] [Around home] Switch successfully configured... [2019-6-11 12:41:01] [Garage] Initializing HTTP-SWITCH accessory... [2019-6-11 12:41:01] [Garage] Switch successfully configured... [2019-6-11 12:41:01] [Led] Initializing HTTP-SWITCH accessory... [2019-6-11 12:41:01] [Led] Switch successfully configured... [2019-6-11 12:41:01] [Furtka] Initializing HTTP-SWITCH accessory... [2019-6-11 12:41:01] [Furtka] Switch successfully configured... [2019-6-11 12:41:01] [Ogród] Initializing HTTP-SWITCH accessory... [2019-6-11 12:41:01] [Ogród] Switch successfully configured... Load homebridge-samsung-tizen.SamsungTizen

Supereg commented 5 years ago

Disclaimer: consider deleting your config post, since it contains your urls without access restriction (or contains the api key). Sorry for accidentally turning your lights off.

Did you test the config as posted below? The backslashes inside the quotation marks in the statusPattern property are important (escape character). Have you tried that or did I misunderstand anything?

If this doesn't work try adding the debug property and setting it to true. When turned on the plugin will print more information what it is actually doing. There should be interesting messages on startup (what exact pattern was configured) and also messages on how the status request got interpreted.

EDIT: i noticed that the backslashes are indeed there but only not displayed by GitHub. The home bridge log is the right one. Some log messages what happens when the status get requests would be great. Exclude anything what you thing is sensitive data.

{
  "accessory": "HTTP-SWITCH",
  "name": "Garage",
  "switchType": "stateful",
  "onUrl": "https://svr1.supla.org/direct/xxx/xxxxx/turn-on",
  "offUrl": "https://svr1.supla.org/direct/xxx/xxxxx/turn-off",
  "statusUrl": {
    "url": "https://svr1.supla.org/direct/xxx/xxxxx/read",
    "method": "GET",
    "statusPattern": "\"on\":true"
  },
  "debug": true
}
Dr4il commented 5 years ago

I know about url to steering device I will change them after solve the problem. When I pasted your pattern, the editor show me an error in regexp reference, so I created my own.

Raw of affected device:

[2019-6-11 16:44:38] [Garage] Initializing HTTP-SWITCH accessory... [2019-6-11 16:44:38] [Garage] Switch successfully configured... [2019-6-11 16:44:38] [Garage] Switch started with the following options: [2019-6-11 16:44:38] [Garage] - switchType: stateful [2019-6-11 16:44:38] [Garage] - statusPattern: /1/ [2019-6-11 16:44:38] [Garage] - onUrls: [{"url":"https://svr1.supla.org/direct/551/MFiiT3cNjZGh/turn-on","method":"GET","body":"","repeat":1,"delayBeforeExecution":0,"auth":{"sendImmediately":true},"headers":{},"strictSSL":false,"requestTimeout":20000}] [2019-6-11 16:44:38] [Garage] - offUrls: [{"url":"https://svr1.supla.org/direct/551/MFiiT3cNjZGh/turn-off","method":"GET","body":"","repeat":1,"delayBeforeExecution":0,"auth":{"sendImmediately":true},"headers":{},"strictSSL":false,"requestTimeout":20000}] [2019-6-11 16:44:38] [Garage] - statusUrl: {"url":"https://svr1.supla.org/direct/551/MFiiT3cNjZGh/read","method":"GET","body":"","repeat":1,"delayBeforeExecution":0,"auth":{"sendImmediately":true},"headers":{},"strictSSL":false,"requestTimeout":20000}

After turn on/off

[2019-6-11 16:44:38] Homebridge is running on port 51826. [2019-6-11 16:46:46] [Garage] getStatus() doing http request... [2019-6-11 16:46:46] [Garage] getStatus() request returned successfully (200). Body: '{"connected":true,"on":false}' [2019-6-11 16:46:46] [Garage] Switch is currently OFF [2019-6-11 16:46:54] [Living Room TV] TV is ON [2019-6-11 16:46:57] [Garage] setStatus() doing http request... [2019-6-11 16:46:57] [Garage] Successfully set switch to ON [2019-6-11 16:47:03] [Garage] setStatus() doing http request... [2019-6-11 16:47:04] [Garage] Successfully set switch to OFF

Dr4il commented 5 years ago

So the pattern "\"on\":true" is correct? Do you need more logs?

Supereg commented 5 years ago

As far as the backslashes are included, yes. The above logs show a request querying the status. Your API endpoint returns '{"connected":true,"on":false}' and the Switch interprets it correctly as OFF. It would be helpful getting the logs when in the switch does NOT correctly interpret the status. So, when the light is on and the Switch should also report ON but does not.

Supereg commented 5 years ago

Your message from three days ago represents the current state of the config? In the startup log messages the following is printed: [2019-6-11 16:44:38] [Garage] - statusPattern: /1/ Which indicates that the plugin was loaded with an status pattern of "statusPattern": "1". Which means that either the property is not set correctly or is misinterpreted by the plugin 🤔

Supereg commented 5 years ago

Okay I found the mistake 😅 A bit embarrassing that I didn't noticed it before. Your "statusPattern" property is located in the wrong spot.

The property does not belong inside the statusUrl object but on the same level:

{
  "accessory": "HTTP-SWITCH",
  "name": "Garage",
  "switchType": "stateful",
  "onUrl": "https://svr1.supla.org/direct/xxx/xxxxx/turn-on",
  "offUrl": "https://svr1.supla.org/direct/xxx/xxxxx/turn-off",
  "statusUrl": {
    "url": "https://svr1.supla.org/direct/xxx/xxxxx/read",
    "method": "GET"
  },
  "statusPattern": "\"on\":true"
}
Supereg commented 5 years ago

This should solve your problem. Should there still be issues feel free to reopen the issue again :)

Dr4il commented 5 years ago

Oh, yes statusPattern was in wrong place, sorry about this matrix :smile: I blamed cloud api for output.

Dr4il commented 5 years ago

Everything works properly now, thank you