binary_sensor:
- platform: command_line
name: Status
scan_interval: 60
command: "/Users/server/scripts/status.sh"
value_template: "{{ value }}"
The script returns True or False (tested with on and off). The status is alway unknown.
But it worked like this:
sensor:
- platform: command_line
name: Status
scan_interval: 60
command: "/Users/server/scripts/status.sh"
value_template: "{{ value }}"
What is wrong here?
petro
(Petro)
April 16, 2022, 10:35am
2
Paste the states of the sensor in here for the working configuration.
binary_sensor.status
Status
unknown
sensor.status
Status
False
I copied the code from binary_sensor:
to sensor:
Bash:
if [ -f "$FILE" ]; then
echo "True"
else
echo "False"
fi
petro
(Petro)
April 16, 2022, 10:45am
4
It should be resolving it. It’s possible there’s hidden special characters in the response due to the encoding level. Change your value_template to
"{{ 'True' in value }}"
Still unknown:
value_template: "{{ 'True' in value }}"
petro
(Petro)
April 16, 2022, 10:53am
6
I don’t see how it could be. How are you checking the state of the binary sensor
In frontend and developer tools.
petro
(Petro)
April 16, 2022, 11:02am
8
Not sure what to tell you. Without looking at the docs, it should be working after a restart.
I have four sensors in binary_sensor. One works the others don’t. They are all platform: command_line.
It does work in sensor:
Is there a disadvantage using it under sensor:?
petro
(Petro)
April 16, 2022, 11:31am
10
Do you have 2 binary sensor sections? If yes, you can only have 1. Merge them together
I do have one in template where I use - binary_sensor:
each time.
In the binary_sensor.yaml I only have this:
- platform: ping
host: 8.8.8.8
count: 1
scan_interval: 60
name: Internet
- platform: command_line
...
Just to be sure, I can use template binary sensor and binary sensor, right?
petro
(Petro)
April 16, 2022, 12:10pm
13
Yes.
My only other thought is that you’re looking at the wrong binary_sensor and a new one was created with a similar name.
123
(Taras)
April 16, 2022, 12:19pm
14
According to the documentation , the default values for payload_on
and payload_off
are ON
and OFF
, respectively. In your case, the received values are True
and False
so modify the values of payload_on
and payload_off
.
binary_sensor:
- platform: command_line
name: Status
scan_interval: 60
command: "/Users/server/scripts/status.sh"
value_template: "{{ value }}"
payload_on: "True"
payload_off: "False"
2 Likes
Wow, that was really the issue. Thanks a lot for that. I was about to give up.
1 Like