Command Line

The 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 configuration.yaml file:

# Example configuration.yaml entry
  - platform: command_line
    command: "cat /proc/sys/net/ipv4/ip_forward"

It’s highly recommended to enclose the command in single quotes ' as it ensures all characters can be used in the command and reduces the risk of unintentional escaping. To include a single quote in a command enclosed in single quotes, double it: ''.

Configuration Variables

command string Required

The action to take to get the value.

name string (Optional)

Let you overwrite the name of the device.


name from the device

device_class string (Optional)

Sets the class of the device, changing the device state and icon that is displayed on the frontend.

payload_on string (Optional, default: ON)

The payload that represents enabled state.

payload_off string (Optional, default: OFF)

The payload that represents disabled state.

value_template string (Optional)

Defines a template to extract a value from the payload.

scan_interval integer (Optional, default: 60)

Defines number of seconds for polling interval.

command_timeout integer (Optional, default: 15)

Defines number of seconds for command timeout.


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
  - 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 RasPlex

Check if RasPlex is online.

  - 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:

  - platform: command_line
    name: Printer
    command: 'ping -W 1 -c 1 > /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.

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 [email protected]
$ sudo service [email protected] stop
$ systemctl is-active [email protected]

A binary command line sensor can check this:

  - platform: command_line
    command: '/bin/systemctl is-active [email protected]'
    payload_on: "active"
    payload_off: "inactive"


Available services: reload.

Service command_line.reload

Reload all command_line entities.

This service takes no service data attributes.