For some reason this value (1) is being displayed as “On”
I wanted to show this as OK, or when value is 0, as “Low”, so I started to fiddle with the value_template.
Anything I do, however, changes the display to either Unavailable or Unknown.
What I tried:
...
value_template: >
{% if value_json.battery_ok == 1 %}
OK
{% else %}
LOW
{% endif %}
Does not work.
I tried changing == 1 to == ‘1’, but that isn’t working either.
Also tried changing == 1 to == INT 1, but no cigar.
So my questions are:
Why is the value 1 being displayed as On ?
What am I doing wrong in the template manipulation ?
This will get me going in the right direction, I think.
One thing though, how does HA know it is a binary sensor, or thinks this is a binary sensor ?
Probably not because the code is in a file called binary_sensors.yaml, right ?
you should have somewhere in your config a yaml key that tells HA that the file you are referencing (“/mqtt/binary_sensors.yaml”) contains binary_sensors.
the usual config for mqtt binary sensors that aren’t split out from the configuration.yamnl is (per the docs):
mqtt:
- binary_sensor:
state_topic: etc....
if you split it out you still need to have at least the “mqtt:” followed by an !include to tell HA where to find the files.
Since we can’t see your config you will need to figure out how you split the config and look for “binary_sensor:” somewhere in there.