I am trying to set a derivative configuration variable through an if condition like this:
(I wanna apply a time_window for the first 60 seconds of a sensor s2 turning on, and after that, no time_window)
- platform: derivative
name: "timeWindowConditional"
source: sensor.s1
unit_time: min
round: 2
time_window: >
{% if is_state(binary_sensor.s2, 'on') and (as_timestamp(now()) - as_timestamp(states.binary_sensor.s2.last_changed) | float <= 60) %}
"00:01:00"
{% else %}
"00:00:00"
{% endif %}
And I get an error when I do “check configuration”:
Invalid config for [sensor.derivative]: offset {% if is_state(binary_sensor.s2, 'on') and (as_timestamp(now()) - as_timestamp(states.binary_sensor.s2.last_changed) | float <= 60) %} "00:01:00" {% else %} "00:00:00" {% endif %} should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['time_window']. Got '{% if is_state(binary_sensor.s2, \'on\') and (as_timestamp(now()) - as_timestamp(states.binary_sensor.s2.last_changed) | float <= 60) %} "00:01:00" {% else %} "00:00:00" {% endif %} \n'. (See ?, line ?).
It seems that it takes the syntax very literally and not applying the logic…
I checked the condition syntax and it seems to work; also somewhere else in a template sensor, set the “state” using a similar syntax and it worked… it only doesn’t work with the derivative…
Any ideas how I can fix this? Or this is not doable at all?
Thanks!