Add details about ping (#10424)

This commit is contained in:
Fabian Affolter 2019-09-22 19:14:49 +02:00 committed by GitHub
parent a1cc108fd7
commit f2b8ace4fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,12 +53,9 @@ The `wake_on_lan` (WOL) switch platform allows you to turn on a [WOL](https://en
### Switch configuration ### Switch configuration
<div class='note warning'> The WOL switch can only turn on your computer and monitor the state. There is no universal way to turn off a computer remotely. The `turn_off` variable is there to help you call a script when you have figured out how to remotely turn off your computer. See below for suggestions on how to do this.
The WOL switch can only turn on your computer and monitor the state. There is no universal way to turn off a computer remotely. The `turn_off` variable is there to help you call a script when you have figured out how to remotely turn off your computer. It's required that the binary `ping` is in your `$PATH`.
See below for suggestions on how to do this.
</div>
To enable this switch in your installation, add the following to your `configuration.yaml` file: To enable this switch in your installation, add the following to your `configuration.yaml` file:
@ -103,12 +100,12 @@ Here are some real-life examples of how to use the **turn_off** variable.
Suggested recipe for letting the `turn_off` script suspend a Linux computer (the **target**) Suggested recipe for letting the `turn_off` script suspend a Linux computer (the **target**)
from Home Assistant running on another Linux computer (the **server**). from Home Assistant running on another Linux computer (the **server**).
1. On the **server**, log in as the user account Home Assistant is running under. (I'm using `hass` in this example) 1. On the **server**, log in as the user account Home Assistant is running under. In this exampleit's `hass`.
2. On the **server**, create ssh keys by running `ssh-keygen`. Just press enter on all questions. 2. On the **server**, create SSH keys by running `ssh-keygen`. Just press enter on all questions.
3. On the **target**, create a new account that Home Assistant can ssh into: `sudo adduser hass`. Just press enter on all questions except password. I recommend using the same user name as on the server. If you do, you can leave out `hass@` in the ssh commands below. 3. On the **target**, create a new account that Home Assistant can ssh into: `sudo adduser hass`. Just press enter on all questions except password. It's recommended using the same user name as on the server. If you do, you can leave out `hass@` in the SSH commands below.
4. On the **server**, transfer your public ssh key by `ssh-copy-id hass@TARGET` where TARGET is your target machine's name or IP address. Enter the password you created in step 3. 4. On the **server**, transfer your public SSH key by `ssh-copy-id hass@TARGET` where TARGET is your target machine's name or IP address. Enter the password you created in step 3.
5. On the **server**, verify that you can reach your target machine without password by `ssh TARGET`. 5. On the **server**, verify that you can reach your target machine without password by `ssh TARGET`.
6. On the **target**, we need to let the hass user execute the program needed to suspend/shut down the target computer. I'm using `pm-suspend`, use `poweroff` to turn off the computer. First, get the full path: `which pm-suspend`. On my system, this is `/usr/sbin/pm-suspend`. 6. On the **target**, we need to let the `hass` user execute the program needed to suspend/shut down the target computer. Here is it `pm-suspend`, use `poweroff` to turn off the computer. First, get the full path: `which pm-suspend`. On my system, this is `/usr/sbin/pm-suspend`.
7. On the **target**, using an account with sudo access (typically your main account), `sudo visudo`. Add this line last in the file: `hass ALL=NOPASSWD:/usr/sbin/pm-suspend`, where you replace `hass` with the name of your user on the target, if different, and `/usr/sbin/pm-suspend` with the command of your choice, if different. 7. On the **target**, using an account with sudo access (typically your main account), `sudo visudo`. Add this line last in the file: `hass ALL=NOPASSWD:/usr/sbin/pm-suspend`, where you replace `hass` with the name of your user on the target, if different, and `/usr/sbin/pm-suspend` with the command of your choice, if different.
8. On the **server**, add the following to your configuration, replacing TARGET with the target's name: 8. On the **server**, add the following to your configuration, replacing TARGET with the target's name:
@ -122,4 +119,4 @@ switch:
shell_command: shell_command:
turn_off_TARGET: 'ssh hass@TARGET sudo pm-suspend' turn_off_TARGET: 'ssh hass@TARGET sudo pm-suspend'
``` ```