Struggling with template values

Hi all,

I’m trying to setup a sensor template (will eventually become an input_select) for a sensor value.

My current sensor script is:

  • platform: template
    friendly_name: ‘Living LUX value’
    value_template: >-
    {%- if states.sensor.fibaro_system_fgms001_motion_sensor_luminance_2 | float < 10.0 %}
    {% elif states.sensor.fibaro_system_fgms001_motion_sensor_luminance_2.state | float < 40.0 %}
    {% else %}
    {%- endif %}

but it’s not working. The value of the sensor is 50 and the sensor says: “Night”.

I’m not sure how to fix this. As far as i can see the sensor value is a float, so there must be something wrong with the expression.

Hope you can help me out.

Thanks in advance!

I’m finding that the best tool for debugging this kind of thing is the Templates dev tool (the icons down below the “streaming output” indicator). Drop in the if/then block and see what it says, then pare it down to simply show a sensor’s state like:

{{states.sensor.fibaro_system_fgms001_motion_sensor_luminance_2.state | float < 40.0 %}}

I think that the prob with your code is that you’re missing a “.state” after the sensor in that first IF statement.

You want:

{%- if states.sensor.fibaro_system_fgms001_motion_sensor_luminance_2.state | float < 10.0 %}


That’s a really cool tool! Didn’t find that yet… Should help loads with debugging (and restarting HASS quite a bit less).

Also was able to fix the problem by adding states before and state after the sensor.

Thanks a million! Would have taken ages to find out by myself.

“States” before, “state” after. Yeah - it’s taking me a while to get used to the syntax too.

The extensions list on the templating page is a helpful reference.

1 Like


just found this topic with is what I’m looking to get help…
I need to create a template what will also check for the Luminance and if it’s bellow a specific value will then switch on a Light. My question is, how to I set the value to ON or OFF to a switch on a template ???
Can anyone help me ??

Thanks in advance

service_template will let you choose light.turn_on vs light.turn_off

Never knew you could paste stuff there - you’re my hero of the day! :smiley:

OMFG. I didn’t realise you could do that. Thanks so much ! What a time saver.