hello everyone
I am curently try to create a interface with main service running on my nuc for that I have create binary sensor like that:
- platform: command_line
name: Radicale service
command: 'systemctl is-active radicale'
device_class: moving
payload_on: active
payload_off: inactive
problem is when I stop the serce to test, sensor don’t switch to off I have this error in log:
2020-02-11 21:25:39 ERROR (SyncWorker_0) [homeassistant.components.command_line.sensor] Command failed: systemctl is-active radicale
when after that I restart Home assistant service is off. when I restart the service he switch correctly to on, but if I stop again service I have the same issue
weird isn’t he?
jocnnor
(Jim O'Connor)
February 11, 2020, 9:05pm
2
is-active will return non zero if it’s inactive. Just testing, mine returned ‘inactive’ and the return code was 3.
It’s possible defining a value_template will ignore the output result. This is true for command_line switch at least.
- platform: command_line
name: Radicale service
command: 'systemctl is-active radicale'
device_class: moving
payload_on: active
payload_off: inactive
# Returns true if value is active. False otherwise.
value_template: "{{ value == 'active' }}"
Actually, payload_on and payload_off are redundant with that template. I’d just use the following command and ignore the value_template.
command: 'systemctl is-active radicale || true'
Indeed I don’t check return code
I will try like you say
seem doesn’t work for me, like the sensor execution stop with non zero return code
but i have try this and seem to work
- platform: command_line
name: Radicale sensor
command: 'echo $(systemctl is-active radicale)'
device_class: moving
payload_on: active
payload_off: inactive`