Update binary_sensor.command_line.markdown (#5669)

* Update binary_sensor.command_line.markdown

Added example for system services.

* Update style
This commit is contained in:
Patrik Hermansson 2018-07-07 22:59:25 +02:00 committed by Fabian Affolter
parent 4fa41cf80d
commit 377a69dcf6

View File

@ -81,3 +81,27 @@ binary_sensor:
```
Consider to use the [`ping` sensor ](/components/binary_sensor.ping/) as an alternative to the samples above.
### {% linkable_title Check if a system service is running %}
The services running is listed in `/etc/systemd/system` and can be checked with the `systemctl` command:
```
$ systemctl is-active home-assistant@rock64.service
active
$ sudo service home-assistant@rock64.service stop
$ systemctl is-active home-assistant@rock64.service
inactive
```
A binary command line sensor can check this:
```yaml
binary_sensor:
- platform: command_line
command: '/bin/systemctl is-active home-assistant@rock64.service'
payload_on: 'active'
payload_off: 'inactive'
```
Note: Use single quotes!