poldim
November 23, 2017, 1:06am
1
Can anyone spot what I’m doing wrong in my syntax? I’ve also tried adding .state
to the end, but that didn’t help.
template_garage_door:
value_template:
>-
{%- if is_state('states.sensor.garage_door_status', 'CLOSED') -%}
Closed
{%- elif is_state('states.sensor.garage_door_status', 'OPEN') -%}
Open
{%- else -%}
<--- ERROR --->
{%- endif %}
icon_template: >-
{%- if is_state("states.sensor.garage_door_status.state", "CLOSED") -%}
mdi:garage
{%- else -%}
mdi:garage-open
{%- endif %}
friendly_name: 'Garage Door Status'
This is the sensor:
- platform: mqtt
state_topic: "homeassistant/garage/door/status"
name: "Garage Door Status"
payload_on: "OPEN"
payload_off: "CLOSED"
stibbons
(Peter Hardy)
November 23, 2017, 1:58am
2
Just to confirm, this is a binary_sensor, right?
If that’s the case, then the states will only be ‘on’ of ‘off’, rather than the ‘OPEN’ and ‘CLOSED’ you’re using in your templates.
keithh666
(Keith Hull)
November 23, 2017, 1:15pm
3
poldim:
template_garage_door:
value_template:
>-
{%- if is_state(‘states.sensor.garage_door_status’, ‘CLOSED’) -%}
Closed
{%- elif is_state(‘states.sensor.garage_door_status’, ‘OPEN’) -%}
Open
{%- else -%}
<— ERROR —>
{%- endif %}
icon_template: >-
{%- if is_state(“states.sensor.garage_door_status.state”, “CLOSED”) -%}
mdi:garage
{%- else -%}
mdi:garage-open
{%- endif %}
friendly_name: ‘Garage Door Status’
Maybe it should look like…
- platform: template
sensors:
template_garage_door:
value_template: >-
{%- if is_state('sensor.garage_door_status', 'CLOSED') -%}
Closed
{%- elif is_state('sensor.garage_door_status', 'OPEN') -%}
Open
{%- endif %}
icon_template: >-
{%- if is_state("sensor.garage_door_status", "CLOSED") -%}
mdi:garage
{%- else -%}
mdi:garage-open
{%- endif %}
friendly_name: 'Garage Door Status'
poldim
November 23, 2017, 5:36pm
4
What I provided was just the template_garage_door
sensor under my template platform. All my other templates are working fine.
poldim
November 24, 2017, 7:24pm
5
I have a WEMOS D1 that’s getting a door open/close sensor. This updates the MQTT topic with either OPEN or CLOSED. The value shows up for the MQTT sensor no problem, but I’d like to tie it in with the icon template.
marthocoo
(Mark Coombes)
November 24, 2017, 7:59pm
6
I don’t think you need to use state.sensor… and maybe some indentation weirdness? Should just be able to use the entity name like so:
template_garage_door:
value_template: >-
{%- if is_state('sensor.garage_door_status', 'CLOSED') -%}
Closed
{%- elif is_state('sensor.garage_door_status', 'OPEN') -%}
Open
{%- else -%}
<--- ERROR --->
{%- endif %}
icon_template: >-
{%- if is_state("sensor.garage_door_status", "CLOSED") -%}
mdi:garage
{%- else -%}
mdi:garage-open
{%- endif %}
friendly_name: 'Garage Door Status'
1 Like
poldim
November 25, 2017, 12:12am
7
marthocoo:
I don’t think you need to use state.sensor… and maybe some indentation weirdness? Should just be able to use the entity name like so:
template_garage_door:
value_template: >-
{%- if is_state('sensor.garage_door_status', 'CLOSED') -%}
Closed
{%- elif is_state('sensor.garage_door_status', 'OPEN') -%}
Open
{%- else -%}
<--- ERROR --->
{%- endif %}
icon_template: >-
{%- if is_state("sensor.garage_door_status", "CLOSED") -%}
mdi:garage
{%- else -%}
mdi:garage-open
{%- endif %}
friendly_name: 'Garage Door Status'
You, sir, are a genius!
BTW, how do you get syntax highlighting of your code?
marthocoo
(Mark Coombes)
November 25, 2017, 12:48am
8
Preface (and end) code paragraphs with three backticks!