Time dependend IF Statement

Hi,

I have a roof window from Velux which I can control via the Velux KLF200 Gateway. The Problem is, that this Gateway is only supporting Scenes without Feedback, so I have no status.

For the window I solved this with a Window Sensor.

For the Blind/Shutter I have set the following value_template:

  arbeitszimmer_dach_rollostatus:
    value_template: '{% if states.sensor.arbeitszimmer_dach_motion_sensor_luminance %}
     {% if states.sensor.arbeitszimmer_dach_motion_sensor_luminance.state < "20" %}
       Geschlossen
     {% else %}
       Offen
     {% endif %}
     {% else %}
       n/a
     {% endif %}'

Can I extend this to a time dependend rule? Eg. Before Sunrise and After Sunset it shows me “NIGHT” and in between the Stauts Open and Closed depending on the luminance?

Or do I need to do this with an automation?

Br,
Johannes

You can use the sun sensor to add to your if statements.

{% if states.sun.sun.state == ‘below_horizon’ %}

Can I cascade the if statemantes?

e.g.:

 arbeitszimmer_dach_rollostatus:
    value_template: '{% if states.sensor.arbeitszimmer_dach_motion_sensor_luminance %}
     {% if states.sensor.arbeitszimmer_dach_motion_sensor_luminance.state < "20" %}
        {% if states.sun.sun.state == ‘below_horizon’ %}
          Night
        {% else %}
          Closed
       {% endif %}
     {% else %}
       Open
     {% endif %}
     {% else %}
       n/a
     {% endif %}'

Yes. What you typed out is correct but hard to read without indents. Also, you should use formatting and if you are doing multiline (use the > without quotes):

value_template: >
 {% if states.sensor.arbeitszimmer_dach_motion_sensor_luminance %}
   {% if states.sensor.arbeitszimmer_dach_motion_sensor_luminance.state < "20" %}
     {% if states.sun.sun.state == "below_horizon" %}
       Night
     {% else %}
       Closed
     {% endif %}
   {% else %}
     Open
   {% endif %}
 {% else %}
   N/A
 {% endif %}

Hi,

I tried this config, but I have a very strange behaviour, although I cahnged the threshold from 20 to 20.0

If the luminace is 0.0 or 0.1 it shows Closed
If the lumincane is 0.2 up to 0.9 it shows Open
from 10.0 to 19.9 it is again Closed
from 20.0 it is again Open

Why is ist Open between 0.2 and 0.9?

Br,
JOhannes

try removing the quotes around the number and adding the float filter.

value_template: >
 {% if states.sensor.arbeitszimmer_dach_motion_sensor_luminance %}
   {% if states.sensor.arbeitszimmer_dach_motion_sensor_luminance.state | float < 20.0 %}
     {% if states.sun.sun.state == "below_horizon" %}
       Night
     {% else %}
       Closed
     {% endif %}
   {% else %}
     Open
   {% endif %}
 {% else %}
   N/A
 {% endif %}

MAny thanks. That solved the issue.

Br,
Johannes

1 Like