Command is used for this binary sensor (IP address masked on purpose). It’s just to probe the state of systemd service on another machine:
binary_sensor:
- platform: command_line
name: Spy serwis
command: "/usr/bin/ssh [email protected] '/bin/systemctl is-active spy.service'"
payload_on: 'active'
payload_off: 'inactive'
I have generated ssh key, uploaded to remote machine and I can login user homeassistant without the password. Command itself works flawlessly inside homeassistant env:
pi@hassbian:~ $ sudo -u homeassistant -H -s
homeassistant@hassbian:/home/pi $ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@hassbian:/home/pi $ /usr/bin/ssh [email protected] '/bin/systemctl is-active spy.service'
active
(homeassistant) homeassistant@hassbian:/home/pi $
However, HA throws me this log:
2018-08-19 18:53:46 ERROR (Thread-11) [homeassistant.components.sensor.command_line] Command failed: /usr/bin/ssh [email protected] '/bin/systemctl is-active spy.service'
Strangely, this happens only when spy.service on remote machine is inactive. When it’s active, HA runs the command just fine. When it’s inactive, HA reports above error and fails to change the state of binary sensor. I can still run the same command manually in HA env just fine, no matter what’s the state of spy.service.
What else am I missing? How can I find out why this command fails? I know about this post, explaining how to run remote ssh commands with Hass.io. Well, I’m using Hassbian, so does it apply here as well? It’s not running in Docker. Shouldn’t this just work, if it’s working in homeassistant environment?