AlexGustafsson / homebridge-wol

A Wake on Lan plugin for Homebridge
MIT License
297 stars 30 forks source link

The switch in Homekit is switched off although the status is "Shutting Down" #61

Closed carsten-h closed 5 years ago

carsten-h commented 5 years ago

Backstory

I want to use the wol plugin to shut down my piCorePlayer running on a Raspberry Pi. When the Pi is shut down, the socket (handled by Tuya-LAN) for the Pi should be switched off.

Issue

When I am using the plugin to shut down my Pi the following happens:

[TuyaAccessory] Sending piCorePlayer {"1":true} [4/29/2019, 9:03:57 PM] [Musikbox] NetworkDevice "Musikbox" (192.168.178.107) went from status "Offline" to "Online" [4/29/2019, 9:04:10 PM] [Musikbox] NetworkDevice shutdown cycle started for "Musikbox" (192.168.178.107) [4/29/2019, 9:04:10 PM] [Musikbox] Attempting to shut down "Musikbox" (192.168.178.107) using "sshpass -p 'xxxxx' ssh -oStrictHostKeyChecking=no tc@192.168.178.107 pcp bs" [4/29/2019, 9:04:10 PM] [Musikbox] NetworkDevice "Musikbox" (192.168.178.107) went from status "Online" to "Shutting Down" [TuyaAccessory] Sending piCorePlayer {"1":false} [4/29/2019, 9:04:56 PM] [Musikbox] NetworkDevice "Musikbox" (192.168.178.107) went from status "Shutting Down" to "Offline"

In the moment where I press the Button to shut Down the Pi the Button becomes switched off in Homekit, although the Pi is only in status "Shutting Down" Isn't it possible to let the Button in Homekit set to off when the Pi is in status "Offline"?

Environment

Configuration

My configuration looks like this: { "accessory": "NetworkDevice", "name": "Musikbox", "ip": "192.168.178.107", "pingInterval": 5, "shutdownGraceTime": 45, "shutdownCommand": "sshpass -p 'xxxxx' ssh -oStrictHostKeyChecking=no tc@192.168.178.107 pcp bs" },

I have omitted the Log, as you can see the Log above and there is no issue in not functioning or something like that.

AlexGustafsson commented 5 years ago

To avoid issues with users trying to shut something down when it's already shutting down, the plugin shows a device as turned off directly after the first press. It won't handle any further presses whilst in the "shutting down" state until it is actually shut down or the shutdown grace time has passed. This is intended behavior and is unlikely to change.

You could try to change the shutdownGraceTime to 0 to continue pinging the device even though it might be shutting down.

carsten-h commented 5 years ago

Ok, thank you for the answer! I understand why you did this! The reason why I want to have an event after completely shutted down is that I want to switch off the power afterwards and not while the Pi is shutting down. But I think I have to use a delayed switch for handling this behaviour.

One last question. I see that when I a switching on my Pi the switch in Homekit is going to "On" state. So your plugin is pinging the devices the whole time (in my config every 5 seconds). Isn't this a little bit too much? Should I set a larger time?

Best Regards!

AlexGustafsson commented 5 years ago

Hi! Sorry for missing your comment.

TLDR: five seconds should be find.

Pinging every five or so seconds has a negligible impact on the network and devices. So from a performance point of view, there is no issue with pinging every five seconds.

Pinging, however, is not perfect - there are sometimes false positives. Therefore the plugin only marks a device as off if five consecutive pings fail. If you find that the status of a device in the HomeKit app flickers on and off or if it does not reflect the actual state of the device you're pinging, you may want to increase or decrease the ping delay.

Don't hesitate to reach out if you have further questions or if my explanation was unclear.