Supereg / homebridge-http-switch

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

Status Updating #8

Closed nchlsgh1 closed 6 years ago

nchlsgh1 commented 6 years ago

HTTP GET changes state upon on/off command however after awhile the switch appears OFF even though GET is 1 and physical state is still on. There is no external program changing the state.

Supereg commented 6 years ago

Could you provide your configuration. Additionally log messages would be helpful when this error occurs.

Also which version of homebridge-http-switch and homebridge is running? Output of: ‘npm list -g homebridge homebridge-http-switch‘

nchlsgh1 commented 6 years ago

Hi Supereg,

Homebridge log: homebridge_1 | [2018-8-22 15:50:11] [Tank Light] Switch is currently OFF //Was already on homebridge_1 | [2018-8-22 15:50:14] [Tank Light] setStatus()[1] successfully set switch to ON //Pressed in HomeKit again (ON) homebridge_1 | [2018-8-22 15:50:28] [Tank Light] setStatus()[1] successfully set switch to OFF // Pressed Off homebridge_1 | [2018-8-22 15:50:37] [Tank Light] setStatus()[1] successfully set switch to ON //Pressed On homebridge_1 | [2018-8-22 15:50:42] [Tank Light] Switch is currently OFF // HomeKit refresh shows Off,Physical is still on and GET is still 1

Config:

{
            "accessory": "HTTP-SWITCH",
            "name": "Tank Light",

            "switchType": "stateful",

            "httpMethod": "GET",
            "onUrl": "http://192.168.0.130/?LightingON",
            "offUrl": "http://192.168.0.130/?LightingOFF",

            "statusUrl": "http://192.168.0.130/LightingStatus"
        }

Ver: homebridge@0.4.38

GET Status: HTTP/1.1 200 OK Content-Type: text/plain Connection: keep-alive \r\n\r\n 0 (For Off or 1 for On)

nchlsgh1 commented 6 years ago

Hi Supereg, After copying the code here and running my GET through Fiddler just realized why your code can't get any actual status. My actual URL was /?LightingStatus but I entered /LightingStatus in config. The first round upon pressing on, homekit probably updated the value to "On" while trying to figure out the API response but since that failed, it reverted to Off status.

Thanks for the help :)

Supereg commented 6 years ago

Yes that was also my guess, something about the status request failed as a result every time HomeKit refreshed the state the switch reported an 'off' state. I was preparing an update with more debug options but I'm glad you found the problem yourself.

nchlsgh1 commented 6 years ago

Thanks Supereg! On a side request, I don't have the capability to use the notification server, not sure if this is under HomeKit's capabilities but could you look at maybe allowing a user definable optional refresh period for the status? I have a switch which also toggles another status backend however in HomeKit, it will not see the new value. If it requests GET status again after maybe 1-5seconds it should update to the backend value. As a workaround currently, I am closing Home app, relaunching for it to update all statuses.

Supereg commented 6 years ago

I though about this too while developing the notification-server. I‘m currently on vacation so this probably could take about 1-2 weeks until I get back. But there should be no problem implementing this. Gonna notify you when it‘s done.

Supereg commented 6 years ago

Okay, so that was faster than I though. Published version v0.5.0 today. It adds support for "pull updates". For configuration have a look at the README. One just need to specify the pullInterval property in the config.json in milliseconds.

nchlsgh1 commented 6 years ago

This if fast thanks! I think you missed out to update the sample config.json ... Is there any order to put the fields or will this be fine:

{
            "accessory": "HTTP-SWITCH",
            "name": "Tank Light",

            "switchType": "stateful",

            "httpMethod": "GET",
            "onUrl": "http://192.168.0.130/?LightingON",
            "offUrl": "http://192.168.0.130/?LightingOFF",

            "statusUrl": "http://192.168.0.130/?LightingStatus",
                       "pullInterval": "5000"
        }
nchlsgh1 commented 6 years ago

Tried to update but its still giving back the same version 0.4.14 even though a package was updated..

/homebridge # npm i homebridge-http-switch
npm WARN homebridge No description
npm WARN homebridge No repository field.
npm WARN homebridge No license field.

+ homebridge-http-switch@0.4.14
updated 1 package in 9.837s
/homebridge # npm list homebridge-http-switch
/homebridge
`-- homebridge-http-switch@0.4.14 

This is running in a docker container so the global flag isn't used

Supereg commented 6 years ago

0.5.0 is live as of npm. Coming back to this later

Supereg commented 6 years ago

So, I successfully installed v0.5.0 on my end, so I don't really know what the problem is on your side. And README is up to date if you look at the commit. I just decided to didn't put the pullInterval property into the default configuration since many people only copy that one and the pull update timer shouldn't be enabled by default by "accident". But below every option is listed very detailed.

nchlsgh1 commented 6 years ago

This is strange update still doesn't work.. uninstalling and reinstalling the package however works :)

pi@HomeKit:~/homebridge $ docker-compose exec homebridge sh
/homebridge # npm i homebridge-http-switch
npm WARN homebridge No description
npm WARN homebridge No repository field.
npm WARN homebridge No license field.

+ homebridge-http-switch@0.4.14
updated 1 package in 48.055s
/homebridge # npm uninstall homebridge-http-switch
npm WARN homebridge No description
npm WARN homebridge No repository field.
npm WARN homebridge No license field.

removed 3 packages in 44.369s
/homebridge # npm install homebridge-http-switch
npm WARN homebridge No description
npm WARN homebridge No repository field.
npm WARN homebridge No license field.

+ homebridge-http-switch@0.5.0
added 3 packages in 53.243s
/homebridge #