Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not waking/shutting down my iMac #30

Closed
VeniceNerd opened this issue Jan 31, 2018 · 33 comments
Closed

Not waking/shutting down my iMac #30

VeniceNerd opened this issue Jan 31, 2018 · 33 comments
Milestone

Comments

@VeniceNerd
Copy link

VeniceNerd commented Jan 31, 2018

Backstory

Using the plugin via the Home App

Issue

I successfully installed homebridge-wol and added the configuration to the config file. The plugin seems to be running fine and my iMac 5K shows up in HomeKit.

However, I am not not able to either wake up or shut down my computer. Nor does the plugin update my iMac status if I manually turn it on or off. The switch doesn't seem to do anything.

Here is screenshots of my networking settings:

screen shot 2018-01-31 at 1 16 53 pm

screen shot 2018-01-31 at 1 17 00 pm

And here is my configuration file:

{
    "bridge": {
        "name": "Homebridge Misc",
        "username": "CD:22:4D:E3:DE:34",
        "port": 51826,
        "pin": "051-85-128"
    },
    "description": "This is an example configuration file. You can use this as a template for creating your own configuration file containing devices you actually own.",
    "accessories": [
        {
            "accessory": "NetworkDevice",
            "name": "iMac 5k",
            "mac": "<mac-address>",
            "ip": "10.0.1.12",
            "pingInterval": 45,
            "wakeGraceTime": 90,
            "shutdownGraceTime": 45,
            "shutdownCommand": "ssh 10.0.1.12 sudo shutdown -h now"
        }
    ],
    "platforms": [
        {
            "platform": "config",
            "name": "Config",
            "port": 8170,
            "log": "/homebridge/logs/homebridge.log",
            "restart": "docker-compose restart homebridge"
        }
    ]
}

Environment

  • os & os version: Raspberry Pi 3 - Raspian OS
  • node version: not sure
  • homebridge version: 0.4.37 (running via OZNU Docker)
  • homebridge-wol version: 3.1.0

Log

When I follow these steps:
I couldn't figure out how to run the DEBUG=* homebridge command. However, here is a copy of my log file:

I get the following log:

[2018-1-31 13:02:22] Homebridge is running on port 51826.
[2018-1-31 13:02:25] [Config] Using Form Authentication
[2018-1-31 13:02:25] [Config] Console is listening on port 8170.
[2018-1-31 13:03:55] [Config] Changes to config.json saved.

/usr/local/lib/node_modules/homebridge/node_modules/mdns/lib/advertisement.js:42
    var error = dns_sd.buildException(errorCode);
                       ^
Error: dns service error: unknown
    at Advertisement.on_service_registered (/usr/local/lib/node_modules/homebridge/node_modules/mdns/lib/advertisement.js:42:24)
    at SocketWatcher.MDNSService.self.watcher.callback (/usr/local/lib/node_modules/homebridge/node_modules/mdns/lib/mdns_service.js:18:40)
*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node>
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister>
[2018-1-31 13:04:30] Loaded plugin: homebridge-dummy
[2018-1-31 13:04:30] Registering accessory 'homebridge-dummy.DummySwitch'
[2018-1-31 13:04:30] ---
[2018-1-31 13:04:30] Loaded plugin: homebridge-wol
[2018-1-31 13:04:30] Registering accessory 'homebridge-wol.NetworkDevice'
[2018-1-31 13:04:30] ---
[2018-1-31 13:04:31] Loaded plugin: homebridge-config-ui-x
[2018-1-31 13:04:31] Registering platform 'homebridge-config-ui-x.config'
[2018-1-31 13:04:31] ---
[2018-1-31 13:04:31] Loaded config.json with 1 accessories and 1 platforms.
[2018-1-31 13:04:31] ---
[2018-1-31 13:04:31] Loading 1 platforms...
[2018-1-31 13:04:31] [Config] Initializing config platform...
[2018-1-31 13:04:31] Loading 1 accessories...
[2018-1-31 13:04:31] [iMac 5k] Initializing NetworkDevice accessory...
Setup Payload:
X-HM://0023K0OYWKCPC
Scan this code with your HomeKit app on your iOS device to pair with Homebridge:



























Or enter this code with your HomeKit app on your iOS device to pair with Homebridge:

    ┌────────────┐
    │ 051-85-128 │
    └────────────┘

[2018-1-31 13:04:31] Homebridge is running on port 51826.
[2018-1-31 13:04:34] [Config] Using Form Authentication
[2018-1-31 13:04:34] [Config] Console is listening on port 8170.
[2018-1-31 13:07:39] [iMac 5k] NetworkDevice awake cycle started for "iMac 5k" (10.0.1.12)
[2018-1-31 13:07:39] [iMac 5k] Attempting to wake up "iMac 5k" (10.0.1.12)
[2018-1-31 13:07:39] [iMac 5k] NetworkDevice "iMac 5k" (10.0.1.12) went from status "Offline" to "Waking Up"
[2018-1-31 13:07:44] [iMac 5k] NetworkDevice shutdown cycle started for "iMac 5k" (10.0.1.12)
[2018-1-31 13:07:44] [iMac 5k] Attempting to shut down "iMac 5k" (10.0.1.12) using "ssh 10.0.1.12 sudo shutdown -h now"
[2018-1-31 13:07:44] [iMac 5k] NetworkDevice "iMac 5k" (10.0.1.12) went from status "Waking Up" to "Shutting Down"
[2018-1-31 13:07:44] [iMac 5k] An error occured while trying to shut down "iMac 5k" (10.0.1.12): Error: Command failed: ssh 10.0.1.12 sudo shutdown -h now
/bin/sh: ssh: not found

[2018-1-31 13:07:44] [iMac 5k] NetworkDevice "iMac 5k" (10.0.1.12) went from status "Shutting Down" to "Offline"
[2018-1-31 13:10:21] [iMac 5k] NetworkDevice awake cycle started for "iMac 5k" (10.0.1.12)
[2018-1-31 13:10:21] [iMac 5k] Attempting to wake up "iMac 5k" (10.0.1.12)
[2018-1-31 13:10:21] [iMac 5k] NetworkDevice "iMac 5k" (10.0.1.12) went from status "Offline" to "Waking Up"
[2018-1-31 13:11:51] [iMac 5k] NetworkDevice "iMac 5k" (10.0.1.12) went from status "Waking Up" to "Offline"

Notes

I would love to get your help with this problem. I was REALLY excited to be able to remotely turn off and turn on my iMac. Please let me know if there is any additional information you need from me!

@VeniceNerd
Copy link
Author

Also just noticed that the iMac 5k accessory sets itself to “off” state even while I’m working on my iMac.

@AlexGustafsson
Copy link
Owner

You don't seem to have ssh installed on your Raspberry Pi. Could you try typing ssh 10.0.1.12 sudo shutdown -h now on your Raspberry Pi and make sure it works? It seems like you're using docker, so you might have to run the command in that image. This package simply runs the shutdown command provided in the default shell, so you have to make sure that works. Note that you don't seem to have any means by authenticating yourself. Usually you will need to enter user and password for ssh, this is solved by using ssh keys.

As for the issue regarding your iMac being shown as offline even when it's on, it's possible that you need to adjust the ping interval. The package pings your iMac every now and then (as specified in the config). When 5 pings are returned with the same status (turned on or off) the status of the computer is considered changed. So basically it's possible that 5 pings fails in a row even when your iMac is on. Lowering pingInterval should in theory return a more accurate state, but could fail more often resulting in a flicker of state. A higher value for pingInterval makes the actual state change take longer to happen (i.e. your iMac will be shown as turned on some time after it has been turned off) but could lower the fail rate.

@AlexGustafsson
Copy link
Owner

@VeniceNerd Have you been able to resolve the issue?

@VeniceNerd
Copy link
Author

Hi Alex! Not yet. I haven’t had time to look back into it.

Also, I found out that apparently you can’t even wake up an iMac from shut off state. Only from sleep state.

Also, when you wake up a mac from sleep over WOL it only wakes up for a few seconds before going right back to sleep.

That seems to be a limitation of the Mac. Makes WOL less useful for me overall.

@AlexGustafsson
Copy link
Owner

Yes, these are some limitations of iMacs and MacBooks. However a common opinion that I share is that usually one does not really turn an Apple computer completely off. That mitigates that shortcoming.

About the computer only being started for a minute or two before going back to sleep. That sounds like it could have to do with the computer not logging in. If possible, one mitigation could be to disable the login screen.

Thank you for sharing your findings! I hope this issue can be helpful for others stumbling upon this or similar issues.

@jellybeansoup
Copy link

In my (admittedly limited) testing, I've found that WOL will wake the computer from sleep (similar to if you attempt to ssh into it), but won't wake the screen. It likely explains why the computer doesn't stay awake for long, the system goes back to sleep after detecting no further activity (and the example wakeGraceTime will usually completely miss this window).

Having the ability to issue a "wakeCommand" (in a similar vein to the existing shutdownCommand) would effectively solve this issue, since you could then send a command to properly attempt to wake the computer, i.e. ssh 10.0.1.12 caffeinate -u -t 300 (which is simply telling macOS that the user is active and it shouldn't sleep for another 300 seconds).

Is there a chance this functionality could be added?

@AlexGustafsson
Copy link
Owner

@jellybeansoup Thank you for reporting your findings! The feature was added in 3.2.0 published just now. The wake command is issued after the wake grace time has expired, see the example below.

{
   "accessory": "NetworkDevice",
   "name": "My Macbook",
   "mac": "<mac-address>",
   "ip": "192.168.1.51",
   "pingInterval": 45,
   "wakeGraceTime": 1,
   "wakeCommand": "ssh 192.168.1.51 caffeinate -u -t 300",
   "shutdownGraceTime": 15,
   "shutdownCommand": "ssh 192.168.1.51 sudo shutdown -h now"
}

This configuration will wake up the computer using wake on lan and then wait one second before starting to ping the device and issuing the caffeinate command.

The readme has been updated to reflect the changes.

I hope this will solve your issue as well, @VeniceNerd.

Feel free to update me whether or not the feature works as expected.

@VeniceNerd
Copy link
Author

VeniceNerd commented Mar 3, 2018

Interesting. I may try this again. Question, though, will my iMac go to sleep if I turn the “outlet” off? Or does this not work on the Mac either?

@AlexGustafsson
Copy link
Owner

Yes, that feature works. The configuration shown in your original post is correct. Make sure that SSH is enabled on the Mac.

@jellybeansoup
Copy link

I've done a few days of testing on this, and it appears to work as expected. Turning the device off via homekit causes my Macbook Pro to sleep, and the new wakeCommand causes it to fully wake up, including the displays. Thanks for adding this so quickly, @AlexGustafsson!

I did find that too short a wakeGraceTime would end up causing it to fail sending the wakeCommand, for some reason. My suggestion would be setting the value somewhere between 5–10 seconds. It seems like that allows WOL to wake the machine enough for the ssh command to trigger successfully.

For reference, the settings I'm using are as follows:

{
    "accessory": "NetworkDevice",
    "name": "Macbook Pro",
    "mac": "<mac-address>",
    "ip": "mbp.local",
    "shutdownGraceTime": 60,
    "shutdownCommand": "ssh user@mbp.local pmset sleepnow",
    "wakeGraceTime": 5,
    "wakeCommand": "ssh user@mbp.local caffeinate -u -t 300"
}

It's worth noting that, in addition to having "Wake for network access" enabled, I've also disabled Power Nap, which tends to cause this plugin to think the device has turned on at random times (which is legitimate, the whole point is that it accesses the network to fetch things while sleeping). If you've got automation based on when the machine turns on, you might find disabling this will help at least reduce them (though I can't say if it disables the behaviour completely).

screen shot 2018-03-04 at 12 10 43 pm

@AlexGustafsson
Copy link
Owner

Thank you, @jellybeansoup for posting about all of your findings. It’s great for future reference!

@VeniceNerd
Copy link
Author

@jellybeansoup thanks for the detailed post! Do you run homebridge on the same machine that you’re putting to sleep?

I’m running homebridge on a Pi3 and was wondering if that would still work the same to control my iMac on the same network?

@jellybeansoup
Copy link

jellybeansoup commented Mar 5, 2018

@VeniceNerd I'm running homebridge from a Raspberry Pi Zero W, which uses SSH keys to log in to the Macbook Pro over Wifi. Your set up should totally work (I actually wouldn't suggest trying to run this from the iMac itself, or the bridge will go offline when the machine goes to sleep).

FYI, if you're running into login problems, it could be a couple of things. A dynamic IP, which I'm getting around by using the hostname found in System Preferences > Sharing (it'll be noted as <ComputerName>.local). Alternatively, the need for a password, which you can bypass by setting up SSH keys to log into your iMac from the Raspberry Pi 3.

@AlexGustafsson
Copy link
Owner

@VeniceNerd Has your issue been solved?

@bubez81
Copy link

bubez81 commented Mar 29, 2018

Hello! I'm able to call the sleep mode on my macbook but i can't wake up it.
Here is my config:
{ "accessory": "NetworkDevice", "name": "Macbook Pro", "mac": "MACADDRESS", "ip": "MacBook-Pro-di-Michele.local", "pingInterval": 45, "wakeGraceTime": 5, "wakeCommand": "ssh michele@MacBook-Pro-di-Michele.local caffeinate -u -t 300", "shutdownGraceTime": 60, "shutdownCommand": "ssh michele@MacBook-Pro-di-Michele.local pmset sleepnow"

and the log:

[3/29/2018, 7:46:25 AM] [Macbook Pro] NetworkDevice shutdown cycle started for "Macbook Pro" (MacBook-Pro-di-Michele.local) [3/29/2018, 7:46:25 AM] [Macbook Pro] Attempting to shut down "Macbook Pro" (MacBook-Pro-di-Michele.local) using "ssh michele@MacBook-Pro-di-Michele.local pmset sleepnow" [3/29/2018, 7:46:25 AM] [Macbook Pro] NetworkDevice "Macbook Pro" (MacBook-Pro-di-Michele.local) went from status "Online" to "Shutting Down"

but no log when i try to wake up the Macbook...seems that no command get given to homebridge

@bubez81
Copy link

bubez81 commented Mar 29, 2018

Sorry update, with this configuration:
{ "accessory": "NetworkDevice", "name": "Macbook Pro", "mac": "MACADDRESS", "ip": "MacBook-Pro-di-Michele.local", "pingInterval": 10, "wakeGraceTime": 5, "wakeCommand": "ssh michele@MacBook-Pro-di-Michele.local caffeinate -u -t 300", "shutdownGraceTime": 45, "shutdownCommand": "ssh michele@MacBook-Pro-di-Michele.local pmset sleepnow" }
i can see an action in the logs:

[3/29/2018, 10:02:06 AM] [Macbook Pro] Attempting to shut down "Macbook Pro" (MacBook-Pro-di-Michele.local) using "ssh michele@MacBook-Pro-di-Michele.local pmset sleepnow" [3/29/2018, 10:02:06 AM] [Macbook Pro] NetworkDevice "Macbook Pro" (MacBook-Pro-di-Michele.local) went from status "Online" to "Shutting Down" [3/29/2018, 10:02:52 AM] [Macbook Pro] NetworkDevice "Macbook Pro" (MacBook-Pro-di-Michele.local) went from status "Shutting Down" to "Online" [3/29/2018, 10:04:14 AM] [Macbook Pro] NetworkDevice "Macbook Pro" (MacBook-Pro-di-Michele.local) went from status "Online" to "Offline" [3/29/2018, 10:08:26 AM] [Macbook Pro] NetworkDevice "Macbook Pro" (MacBook-Pro-di-Michele.local) went from status "Offline" to "Online"
But i can see that the command ssh michele@MacBook-Pro-di-Michele.local caffeinate -u -t 300 is missing

@AlexGustafsson
Copy link
Owner

@bubez81 Hi! If this is a persisting problem, could you please open a separate issue? It makes it easier for me to follow and hopefully solve.

@bubez81
Copy link

bubez81 commented May 31, 2018

ok sorry for the delay it's not a good period for me.
i will make some test and then i will open a new post.
Michele.

@AlexGustafsson
Copy link
Owner

@bubez81 No worries. Take your time!

@PerthSteve
Copy link

PerthSteve commented Jul 7, 2018

Hello, I’m having the same issue at the OP. I get ssh not found and I’m using a docker container. Any advice on adding ssh to docker? I’ve included it in the docker-compose.yml as a package (openssh). I added this after the initial installation, so I’m not sure if I’m supposed to do anything more?
Cheers!

Edit: Discovered I need to add openssh to the docker-compose.yml file, then docker-compose down, docker-compose up and it installs.

@AlexGustafsson
Copy link
Owner

AlexGustafsson commented Jul 7, 2018

@PerthSteve Also make sure that you’re running your container on the host network interface - otherwise the container won’t be able to find devices on your local network. If you’re unsure of what I’m talking about, take a look at the docker documentation. Feel free to come back whether it works or not!

@PerthSteve
Copy link

PerthSteve commented Jul 8, 2018 via email

@domeOo
Copy link

domeOo commented Sep 10, 2018

Hi Alex, thanks for replying. I’ve managed to ssh from within the docker, even with rsa key and no password. The trouble seems to be when I use off switch the command fails in the logs. I’m unable to tell “who” is using the command, but assumed that within the container it’s root. I might try the verbose flag in the Config to see what ssh is doing

If u are using "oznu/docker-homebridge" the user "abc" is running node and with this your ssh keys are at a different location.
If thats your problem u can go to /config/.ssh and put your keys there.

@woelfchen471
Copy link

Hi Alex, hope you can help me. I've also can't send my iMac to sleep or wake up.... when I send the ssh command to sleep to wake up from the console of the raspberry the iMac wakes up and go to sleep without any problem. When I try it over Homebridge it doesn't work....
in the logfile stands "An error occurred while trying to shut down "myimac"..... Error: Command failed: ssh myname@myimac pmset sleepnow

@AlexGustafsson
Copy link
Owner

Does the command work if you run it yourself in the terminal? It seems like either you don’t have SSH installed on the pi or it couldn’t connect to the Mac.

@woelfchen471
Copy link

woelfchen471 commented Dec 2, 2018

Thanks for your quick response.... ssh on the raspberry should be installed. maybe my explanation was not detailed enough. for testing ssh I'm using the app Homebridge on my iPad. in the app I open the console on the raspberry pi and start the ssh comma as explained... when I send the ssh command from this console the iMac go to sleep or wake up. But not when I use Homekit... sorry for my bad explanation. But I'm al bloody beginner with raspberry... Can I give you further informations?

@AlexGustafsson
Copy link
Owner

AlexGustafsson commented Dec 2, 2018

There was no issue with your explenation. The reason for me asking is that homebridge-wol basically copy and pasted the command you enter and run it as a command the same way you would. The idea is that if it works when you type it yourself, it works with homebridge-wol.

One difference, however, is that it inherits the user from homebridge. If you start homebridge as root, then SSH will also be run as root.

Do you start homebridge with sudo? If so, does sudo ssh yourname@mac... work?

@woelfchen471
Copy link

changes nothing :-( I'm looking forward to run the home bridge in debug mode and will give you further informations....

@nickcom
Copy link

nickcom commented Dec 10, 2018

changes nothing :-( I'm looking forward to run the home bridge in debug mode and will give you further informations....

same issue for me... issuing the caffeniate command directly in the terminal works fine, but the same command issued via the plugin does not

@AlexGustafsson AlexGustafsson added this to the 3.3 milestone Jan 16, 2019
@amaisano
Copy link

Same issues: shutdown works great with either pmset displaysleepnow or pmset sleepnow, but:

  1. When attempting to wake up, no command is shown in the console like when shutting down
  2. Nothing happens, even with shorter/longer wait/grace periods
  3. My Macs both keep switching back to "On" when they are off (I have disabled Power Nap)

Is this the latest information for this problem or is there another issue or PR open for it?

@AlexGustafsson
Copy link
Owner

@amaisano Yes and no. Yes as this issue mostly has to do with Macs “lying” about their state. No as there’s most likely an issue with the internal state machine that has come up in other issues.

A PR came in yesterday mentioning pinging which may or may not be related.

I’d say that your best off following the milestone https://github.com/AlexGustafsson/homebridge-wol/milestones to follow progress.

@AlexGustafsson
Copy link
Owner

Locking this as there are many unrelated issues popping up now and then.

Repository owner locked as too heated and limited conversation to collaborators Jun 25, 2019
@AlexGustafsson
Copy link
Owner

I've published 3.2.5 to NPM which contains many fixes. Please try it and open new issues for any problems you may face. Closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants