Supereg / homebridge-http-switch

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

Status Cache is not refreshing #78

Closed mdombrowski13 closed 3 years ago

mdombrowski13 commented 3 years ago

Describe the bug When a users changes the state of the switch from the switch it is not updated on Homebridge or Apple home App unless you leave the accessory page and come back on homebridge or quit and relaunch the apple home app. Once relaunching the app it queries the switch and gets an updated state. No other device (Kasa,Wemo,Hue) respond in this manner they are all responsive of changes.

Expected behavior A status icon update a few seconds of change when changed from device.

To Reproduce Steps to reproduce the behavior:

  1. open apple home app
  2. push button on ESP8266 Switch (switch changes output state)
  3. validate json output string in web browser (output is reflected properly)
  4. note apple home app does not reflect update
  5. view homebridge log and note no periodic check is occurring of switch state
  6. Close home apple home app
  7. Relaunch apple home app
  8. See http switch periodic check occur and update switch status in homebridge log.

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

Configuration JSON Config

"accessories": [
        {
            "accessory": "HTTP-SWITCH",
            "name": "test_switch",
            "switchType": "stateful",
            "statusCache": 1000,
            "onUrl": "http://test_switch.local/relay_on",
            "offUrl": "http://test_switch.local/relay_off",
            "statusUrl": {
                "url": "http://test_switch.local/relay_status",
                "method": "GET",
                "statusCache": 1000
            },
            "debug": true
        }
    ]

Additional context Json data from relay_status response {"relay_status": 1} relay on {"relay_status": o} relay off

ashishgururani commented 3 years ago

I am not using this method but the documentation states to set the "pullInterval" parameter. I don't see it in your configuration? Without the pullInterval (because I didn't want to make requests every 1 second) and without other push methods, mine does the same where is only refreshes (makes the status call) when I go back in the app.

Supereg commented 3 years ago

As @ashishgururani stated this is intended behavior. HTTP is a protocol where the client (in our case the switch) makes a request to the server (in your case the test_switch.local) and the server can respond to whatever the client asks for. But there is no way for the server to actively send new data to the client (how should he know who is even interested in that). So you need to create another mechanism to update the data on the plugin.

Basically everything I just said is also written in the README under the section Updating the switch state in HomeKit (which is like the first section after the Installation). There it is also described in a bit more detail. So closing the issue with a RTFM.