command_line binary sensor platform issues specific commands to get data.
To use your Command binary sensor in your installation, add the following to your
# Example configuration.yaml entry binary_sensor: - platform: command_line command: cat /proc/sys/net/ipv4/ip_forward
(string)(Required)The action to take to get the value.
(string)(Optional)Let you overwrite the name of the device. By default name from the device is used.
Default value: name
(string)(Optional)The type/class of the sensor to set the icon in the frontend.
(string)(Optional)The payload that represents enabled state.
Default value: true
(string)(Optional)The payload that represents disabled state.
Default value: false
(string)(Optional)Defines a template to extract a value from the payload.
(integer)(Optional)Defines number of seconds for polling interval.
Default value: 60
(integer)(Optional)Defines number of seconds for command timeout.
Default value: 15
In this section you find some real-life examples of how to use this sensor.
Check the state of an SickRage instance.
# Example configuration.yaml entry binary_sensor: - platform: command_line command: netstat -na | find "33322" | find /c "LISTENING" > nul && (echo "Running") || (echo "Not running") name: 'sickragerunning' device_class: moving payload_on: "Running" payload_off: "Not running"
Check if RasPlex is
binary_sensor: - platform: command_line command: 'ping -c 1 rasplex.local | grep "1 received" | wc -l' name: 'is_rasplex_online' device_class: connectivity payload_on: 1 payload_off: 0
An alternative solution could look like this:
binary_sensor: - platform: command_line name: Printer command: ping -W 1 -c 1 192.168.1.10 > /dev/null 2>&1 && echo success || echo fail device_class: connectivity payload_on: "success" payload_off: "fail"
Consider to use the
ping sensor as an alternative to the samples above.
The services running is listed in
/etc/systemd/system and can be checked with the
$ systemctl is-active email@example.com active $ sudo service firstname.lastname@example.org stop $ systemctl is-active email@example.com inactive
A binary command line sensor can check this:
binary_sensor: - platform: command_line command: '/bin/systemctl is-active firstname.lastname@example.org' payload_on: 'active' payload_off: 'inactive'
Note: Use single quotes!