Time-dependent Automation not working unless manually executed

Please advise what’s wrong?
Simple task - after certain time I need to adjust Thermostat temperature automatically:

alias: 'Climate: Bedroom'
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.bme280_temperature
    below: '10'
condition:
  - condition: or
    conditions:
      - condition: time
        after: '17:30:01'
      - condition: time
        after: '06:30:01'
action:
  - service: climate.set_temperature
    data:
      temperature: '24.5'
    entity_id: climate.termostat_khoz_spalnia
mode: single

Automatically it doesn’t work after time reaches the set figure, but manually if I launch it, it works based on set condition.

Does it work with just one condition? If it is after 06:30:01 it is by definition after 17:30:01 surely?

2 Likes

First of all, the first time condition is redundant because the second one already includes all times greater than 06:30:01.

Imagine this scenario:

  • The time is 05:00 and the temperature is 11.
  • At 06:00 the temperature decreases to 10.
  • It triggers the automation which checks the condition. It’s not after 06:30:01 yet so the action is not executed.
  • The temperature continues to decrease but it doesn’t trigger the automation again. Why not? Because that’s how a Numeric State Trigger works. It only triggers at the moment the value crosses the threshold. If the value continues beyond the threshold, (continues decreasing below 10) it doesn’t cause another trigger. It would have to first rise above 10 then fall below it to cause another trigger.

You will need to redesign your automation to make it work the way you want.

When you manually execute an automation it skips the trigger and the condition and simply runs the action section.

@123,
Yes, I thought about it too.
My idea is to adjust temperature to 24.5C in time periods:
between 17:30 and 23:00 (evening)
and
between 6:30 and 9:30 (morning)

I’ve been trying to desing with different options, but I understand that time it works recursively with mentioned exact time frames.
I can try to bind to sunset+couple of hours (don’t know if it works as I need), but I was wondering if there’s any way to stick to static time.

This one (with fixed time frames) does not work either.
The Default condition is not executed if Time is beyond the set frame in two conditions.
Strange…

alias: 'Climate: Хоз.спальня, зимнее отопление Вкл вечером и утром'
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.bme280_temperature
    below: '10'
condition: []
action:
  - choose:
      - conditions:
          - condition: time
            after: '19:00:00'
            before: '22:00:00'
        sequence:
          - service: climate.set_preset_mode
            data:
              preset_mode: none
            entity_id: climate.termostat_khoz_spalnia
      - conditions:
          - condition: time
            after: '06:00:00'
            before: '08:00:00'
        sequence:
          - service: climate.set_preset_mode
            data:
              preset_mode: none
            entity_id: climate.termostat_khoz_spalnia
    default:
      - service: climate.set_preset_mode
        data:
          preset_mode: eco
        entity_id: climate.termostat_khoz_spalnia
mode: single

It doesn’t work because it is virtually the same logic as the first example (which also failed to work) I suggest you read my explanation again (in my previous post) to understand why it fails. If it’s still unclear, let me know and I’ll help you redesign it.

@123,
I understood. HA treats condition after 6AM and after 7PM as same (after 6AM anyway), but how would you recommend to program my simple task?
Use Input Boolean or timer?

When you look at the History of sensor.bme280_temperature at what time, during the 24 hours of a day, does its value decrease below 10?

This sensor just triggers automation in cold weather (below 10 degrees). When it’s higher than 10C, - no need to turn off Thermostat at all.
Now it is always below 10C, and Automation triggers everyday at time frames in Condition settings, but is may vary depending on weather/temperature.

The temperature never rises above 10. It’s always below 10. That’s why the Numeric State Trigger is never triggered. It’s not working for precisely the reason I explained in my first post.

It only triggers at the moment the value crosses the threshold . If the value continues beyond the threshold, (continues decreasing below 10) it doesn’t cause another trigger. It would have to first rise above 10 then fall below it to cause another trigger.

Would this help? Trigger every 15 minutes, but with a condition that temperature is below 10. Then handle the time frames in choose conditions. Remember to also handle the case when you get outside your time frame and you need to switch off the heating.

alias: 'Climate: Хоз.спальня, зимнее отопление Вкл вечером и утром'
description: ''
trigger:
  - platform: time_pattern
    minutes: /15
condition: numeric_state
  - entity_id: sensor.bme280_temperature
    below: 10
action:
  - choose:
      - conditions:
          - condition: time
            after: '19:00:00'
            before: '22:00:00'
        sequence:
          - service: climate.set_preset_mode
            data:
              preset_mode: none
            entity_id: climate.termostat_khoz_spalnia
      - conditions:
          - condition: time
            after: '06:00:00'
            before: '08:00:00'
        sequence:
          - service: climate.set_preset_mode
            data:
              preset_mode: none
            entity_id: climate.termostat_khoz_spalnia
    default:
      - service: climate.set_preset_mode
        data:
          preset_mode: eco
        entity_id: climate.termostat_khoz_spalnia
mode: single

That’s better but if the temperature is below 10 during a time range, it will execute the same service every 15 minutes. Not terrible, but not great either.

Also, your Numeric State Condition isn’t written correctly.


This automation is basically a schedule. At certain times of the day, it sets the thermostat to a specific mode but only if the temperature is below 10. That means the automation simply needs Time Triggers added to the existing Numeric State Trigger.

Writing without HA, so this may need some corrections. Trigger to each start and end time of your time frame. Also trigger to temp going below 10. This way you can switch on your thermostat even when the temp limit was not reached at the start-time of your time frame.

alias: 'Climate: Хоз.спальня, зимнее отопление Вкл вечером и утром'
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.bme280_temperature
    below: 10
  - platform: time
    at: '19:00:00'
  - platform: time
    at: '22:00:00'
  - platform: time
    at: '06:00:00'
  - platform: time
    at: '08:00:00'
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            - conditions:
              - condition: or
                - conditions:
                  - condition: time
                    after: '19:00:00'
                    before: '22:00:00'
                  - condition: time
                    after: '06:00:00'
                    before: '08:00:00'
              - condition: numeric_state
                entity_id: sensor.bme280_temperature
                below: 10
        sequence:
          - service: climate.set_preset_mode
            data:
              preset_mode: none
            entity_id: climate.termostat_khoz_spalnia
      
    default:
      - service: climate.set_preset_mode
        data:
          preset_mode: eco
        entity_id: climate.termostat_khoz_spalnia
mode: single

You do realize that is exactly what I had suggested in my previous post? :thinking:

This latest version also contains the malformed Numeric State Condition.

Good. Must be the solution then? We’re here to help @SuperMaximus
I corrected my code and fixed numeric_state formatting

If I told you it can be much shorter, without choose, will you accept the challenge to create it?

Can’t think of a better solution, but not saying there can’t be one. Maybe splitting into two automations. Please share you solution, we’re curious :slight_smile:

alias: 'Climate: Хоз.спальня, зимнее отопление Вкл вечером и утром'
trigger:
- platform: numeric_state
  entity_id: sensor.bme280_temperature
  below: 10
- platform: time
  at: 
  - '19:00:00'
  - '22:00:00'
  - '06:00:00'
  - '08:00:00'
action:
- service: climate.set_preset_mode
  data:
    entity_id: climate.termostat_khoz_spalnia
    preset_mode: >
      {% set h = now().hour %}
      {% set t = states('sensor.bme280_temperature') | float %}
      {{ 'none' if t <= 10 and (19 <= h < 22 or 6 <= h < 8) else 'eco' }}

EDIT

Correction. Changed last line of preset_mode template. Excluded the hours of 22 and 8 from their respective time ranges by changing <= to <.

2 Likes

Whilst ‘choose’ has its place, since its introduction I have noticed a horrendous uptick in people making really really messy and complicated automations because they’re defaulting to choose rather than use another method (like the condition block of the automation, or a really simple template), which would often be far more efficient.

The above is a perfect example. 19 lines with a basic template, rather than 42 lines in an automation of awkwardly nested choose options from which it was generated.

1 Like