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!
@robconnolly, are you running this yaml on hass.io or hassbian?
Thanks,.
My binary sensor is always returning off.
binary_sensor:
- platform: command_line
name: "Statut ZWave/Zigbee"
command: 'ha hardware info | grep -q HubZ && (echo "True") || (echo "False")'
device_class: connectivity
payload_on: "True"
payload_off: "False"
But the command in SSH does return True of False depending on the situation.
Anything seems off in my sensor?
Thank you
I came across this topic when dealing with the same issue myself. As it’s an old topic, apparently the issue has still not resolved. So I created an issue on github.
For anyone wanting this to work NOW, it turns out that for the default payload values, it does work… (See github issue)