[solved] Still don't get my time based binary_sensor to update... (got entity_id: sensor.time)

Dear community

After hours and hours of trying… I still don’t get my binary_sensor to update? When placing the code inside the template module it runs correctly… but somehow not as binary_sensor? Also when i try to update it with the service “homeassistant.update_entity” - it doesn’t change to on…

I of course played with the conditions to test it… (under template), but binary_sensor.aussenbeleuchtung always stays “off” - any idea?

      aussenbeleuchtung:
    friendly_name: "Timer Aussenbeleuchtung"
    entity_id: sensor.time
    value_template: >-
        {% set tag = now().weekday() %}
        {% set std = now().hour %}
        {% set hell_o = states('sensor.wetterstation_helligkeit_o') | int %}
        {% set hell_w = states('sensor.wetterstation_helligkeit_w') | int %}
        {% if (tag < 4) %}
          {% if (std >= 6) and (std < 10) and  (hell_o > 1) %}
          on
          {% elif (hell_w < 1) and (std > 10) and (std <= 22) %}
          on
          {% else %}
          off
          {% endif %}  
        {% elif tag == 4 %}
          {% if (std >= 6) and (std < 10) and  (hell_o < 1) %}
          on
          {% elif (hell_w < 1) and (std > 10) and (std <= 24) %}
          on
          {% else %}
          off
          {% endif %}  
        {% elif tag == 5 %}
          {% if (std >= 7) and (std < 10) and  (hell_o < 1) %}
          on
          {% elif (hell_w < 1) and (std > 10) and (std <= 24) %}
          on
          {% else %}
          off
          {% endif %}  
        {% elif tag == 6 %}
          {% if (std >= 7) and (std < 10) and  (hell_o < 1) %}
          on
          {% elif (hell_w < 1) and (std > 10) and (std <= 22) %}
          on
          {% else %}
          off
          {% endif %}  
        {% endif %}

Try this, if it works I’ll try and tell you why:

    value_template: >-
        {% set tag = now().weekday() %}
        {% set std = now().hour %}
        {% set hell_o = states('sensor.wetterstation_helligkeit_o') | int %}
        {% set hell_w = states('sensor.wetterstation_helligkeit_w') | int %}
        {% if (tag < 4) %}
          {{ ((std >= 6) and (std < 10) and (hell_o > 1)) or ((hell_w < 1) and (std > 10) and (std <= 22)) }}
        {% elif tag == 4 %}
          {{ ((std >= 6) and (std < 10) and (hell_o < 1)) or ((hell_w < 1) and (std > 10) and (std <= 24)) }}
        {% elif tag == 5 %}
          {{ ((std >= 7) and (std < 10) and (hell_o < 1)) or ((hell_w < 1) and (std > 10) and (std <= 24)) }}
        {% elif tag == 6 %}
          {{ ((std >= 7) and (std < 10) and  (hell_o < 1)) or ((hell_w < 1) and (std > 10) and (std <= 22)) }}
        {% endif %}
1 Like

:clap::+1::pray::upside_down_face::slightly_smiling_face::star_struck:

yes it does :slight_smile: thanks a lot… so “on” and “off” was the problem?

Yes. The template binary sensor is expecting the value template to resolve to the state True or False. Not the strings “True” or “False”. So I dont think replacing your on/off with True/False would have worked. Not 100% on this last bit.