From 377a69dcf6ac33396a7329cd8221c239bce34057 Mon Sep 17 00:00:00 2001 From: Patrik Hermansson Date: Sat, 7 Jul 2018 22:59:25 +0200 Subject: [PATCH] Update binary_sensor.command_line.markdown (#5669) * Update binary_sensor.command_line.markdown Added example for system services. * Update style --- .../binary_sensor.command_line.markdown | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/source/_components/binary_sensor.command_line.markdown b/source/_components/binary_sensor.command_line.markdown index b37d6e40bbc..25fb0c03302 100644 --- a/source/_components/binary_sensor.command_line.markdown +++ b/source/_components/binary_sensor.command_line.markdown @@ -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!