I have a rest sensor (Open Sprinkler) which returns 0 or 1. I’d prefer to display off/on
platform: rest
name: sprinkler1
resource: http://x.x.x.x:8080/js?pw=XXX
value_template: “{{value_json.sn[0]}}”
I tried a template (below), which didn’t work because I don’t know enough about HA, and templates yet
- platform: template
sensors:
sprinkler1_name:
entity_id: sensor.sprinkler1
value_template: “{%if states.sensor.sprinkler1 == ‘1’ %}On{% elif states.sensor.sprinkler1 == ‘0’ %}Off{% endif %}”
The values in the template should not be quoted (otherwise I believe the state will contain those quote characters.) Also I’d recommend using the “standard” state of unknown for the third option. So:
sensor:
platform: rest
name: sprinkler1
resource: http://x.x.x.x:8080/js?pw=XXX
value_template:>
{% if value_json.sn[0] | int == 1 %}
On
{% elif value_json.sn[0] | int == 0 %}
Off
{% else %}
unknown
{% endif %}
Another option is to use a binary REST sensor instead:
Also make sure that whatever editor you’re using uses “standard” text-style quotation marks. The ones you posted in your template above weren’t simple text marks. I’m pretty sure the ones you posted will make your code not work.