Command line binary sensor never switches to on

Hi All,

I’m trying to create a sensor which senses whether a certain port is open on a device on my network. Home Assistant is happy with my configuration and creates the sensor, but it never switches to on when the port is open. Here is the configuration:

binary_sensor:
  - platform: command_line
    name: "Port Open"
    command: '/usr/bin/nmap -p<port> <ip> | /bin/grep open > /dev/null && (echo true) || (echo false)'
    device_class: connectivity

I’ve run the command from the command line with the port both open and closed and it works as expected. I’ve even run it inside the docker container running HASS (via docker exec -it <container> /bin/bash) and it runs fine there too.

I’m also getting nothing in the logs about the sensor.

Anyone have any idea what I’m missing here?

Thanks in advance!

Looks like a bug, or some confusion with the docs.
Your sensor works for me when you provide the payloads.

binary_sensor:
  - platform: command_line
    name: "Port Open"
    command: '/usr/bin/nmap -p<port> <ip> | /bin/grep open > /dev/null && (echo true) || (echo false)'
    device_class: connectivity
    payload_on: "true"
    payload_off: "false"

Made a PR to change the docs, because the default values in the code are ‘ON’/‘OFF’.

Hi,

Thanks for your responses and sorry for taking a while to get back to you. That works great, I guess the solution in these cases is to go to the source!

Thanks for updating the docs, hopefully that will prevent someone else having the same problem.

Thanks again!