Temperature & Time automation

I’m trying to setup an automation to turn on a switch when the external temperature drops below 12 degrees and the time is either between 6:30 - 8am or 4:45 - 6pm (i.e. it should trigger twice in a day).

The automation doesn’t trigger even though all criteria have been met.

I’m obviously doing something wrong.
Can anyone shed some light on it for me?

automation:
 - alias: "Turn on Heater"
   hide_entity: True
   trigger:
     platform: numeric_state
     entity_id: sensor.yr_temperature
     below: 12
   condition:
     - condition: or
       conditions:
         - condition: time
           after: '06:30:00'
           before: '08:00:00'
         - condition: time
           after: '16:45:00'
           before: '18:00:00'
   action:
     service: homeassistant.turn_on
     entity_id:
      - switch.heater

I think your switch is the issue. The proper service would be switch.turn_on not homeassistant.turn_on.

No, you can use homeassistant.turn_on

This will only trigger if the temperature drops below 12 in the given time periodes.
If the temperature drops to 11*C at 06:25 it will not trigger the automation at 06:30

Ah ok. That makes a bit of sense.

Is it even possible to do what I’m after then?
I tried changing the trigger to be time and the condition to be the temp, but that still doesn’t seem to work

It depends of what you really wants. But I guess you wants both

automation:
 - alias: "Turn on Heater"
   hide_entity: True
   trigger:
    - platform: numeric_state
      entity_id: sensor.yr_temperature
      below: 12
    - platform: time
      after: '06:30:00'
    - platform: time
      after: '16:45:00'
   condition:
     - condition: or
       conditions:
         - condition: time
           after: '06:30:00'
           before: '08:00:00'
         - condition: time
           after: '16:45:00'
           before: '18:00:00'
    - condition: numeric_state
       entity_id: sensor.yr_temperature
       below: 12
   action:
     service: homeassistant.turn_on
     entity_id:
      - switch.heater

You sir, are my new hero.
Take comfort in the fact that I will no longer have a wife that complains about how cold the kitchen is in the mornings :smiley:

2 Likes

The keyword “after” is not legal in ‘trigger’ section. “At” is legal and not relevant: it changes the meaning of the automation.

I think it can be even more simplified in the trigger section, because the conditions take care of all constraints. Even if the automation is triggered everytime the temperatur changes, it will not cause an action unless all conditions pass.

automation:
 - alias: "Turn on Heater"
   hide_entity: True
   trigger:
   - platform: numeric_state
     entity_id: sensor.yr_temperature
   condition:
   - condition: or
     conditions:
     - condition: time
       after: '06:30:00'
       before: '08:00:00'
     - condition: time
       after: '16:45:00'
       before: '18:00:00'
   - condition: numeric_state
      entity_id: sensor.yr_temperature
      below: 12
   action:
   - service: homeassistant.turn_on
     entity_id: switch.heater

Btw: Unless the heater switch is (time-) controlled by another automation, it will never turn off.