Sensor Templating | Convert % to open/closed state

Hi there,

I have a Vera unit coming into HA very well and I can control my lights and other z-wave devices. I have two inputs however that are on a IO bridge interface the appear in Vera as light sensors so they report their values as % Lux.

My garage door sensor and rain gauge sensor appear in HA but I want to create a new sensor that reports either wet/dry or open/closed. I’ve used template sensors before and I tried modifying an existing one shown below but when I do a config_check, I get an error for the new Vera garage door sensor. Anyone tell me what I’m doing wrong?

Working config on an Electrodragon relay and reports on/off

ED02 Input 1 Garage Door Sensor 7:

- platform: template
      value_template: '{% if is_state("binary_sensor.ed02_button_1", "on") %}Closed{% else %}Open{% endif %}'
      friendly_name: 'Garage Door State'

New non-working sensor modified from the above.

Vera IO Relay Garage Door #14 8:

- platform: template
    Vera_14_garage sensor:
      value_template: '{% if is_state("sensor.i1garage_door_sensor_14", "< 10") %}Closed{% else %}Open{% endif %}'
      friendly_name: 'Vera Garage Door State'

Your name cannot start with a capital V, and it cannot contain a space.
try: vera_14_garage_sensor:

You sir are a legend, thank you. Working perfectly! Now just to tweak the icons.

Whoops, seems it doesn’t actually change state. Sensor appears and when inspecting in templating, it seems that <10 is not recognised. If I put {% if is_state("sensor.i1garage_door_sensor_14", "0") %}, the state is determined correctly. Trouble is, sometimes the state ‘floats’ a bit and is not either fully 0 or 100. Anyone got any clues.

This {% if states('sensor.i1garage_door_sensor_14') | float < 5%}Closed{% else %}Open{% endif %} seems to work but I don’t know why.

Mabe try <= 10

Thanks, but that reports the wrong state too like < 10.

What state value is reported when the door is actually closed?

Normally 0 but it can be 1 or 2 hence the < requirement. 100 (or 99) when open.

{% if states('sensor.i1garage_door_sensor_14') | float < 5%}Closed{% else %}Open{% endif %} works but I’m not sure if that is the correct use of the syntax.

How about:

value_template: ‘{% if states.sensor.i1garage_door_sensor_14.state|float <= 10 %}Closed{% else %}Open{% endif %}’

value_template: “{%if states.sensor.i1garage_door_sensor_14.state <= ‘10’ %}Closed{% else %}Open{% endif %}”

I now understand what you are saying, I’m still new to all this and still trying to interpret the info provided in the examples.

is equivalent to

So you can use either
{% if states(‘sensor.i1garage_door_sensor_14’)|float < 5 %}
{% if states(‘sensor.i1garage_door_sensor_14’):float < 5 %}

Thanks. {% if states(‘sensor.i1garage_door_sensor_14’):float < 5 %} does not work but {% if states(‘sensor.i1garage_door_sensor_14’)|float < 5 %} works a treat. Appreciate your help.

yea sorry, that : was a typo