Automation with many couple of time and temperature condition

Hello, I want to improve the behaviour of thermostats.

For that, I will start the heating earlier if the temperature is below one of couple time / temp.

For exemple I will start the heater if:
at 6h30 the temperature is below 18.8 or
at 5h30 if the temperature is below 17,7 or

I don’t know how to write the automation…

Many thanks for your help !

Best regards

Try something like this.

trigger:
  - platform: time
    at: '05:30:00'
condition:
  - condition: state
    entity_id: sensor.temperature
    below: 17.7
action:
  - service: climate.set_temperature
   data:
     entity_id: climate.thermostat
     temperature: 20.0
     hvac_mode: heat

and then add another one for 6:30 at 18.8

Hello,
Thanks for your reply.

I have one automation per file.
I do what you explain me with your post.

But, with this technique, I will have one file for each point, so a lot of different file.
I would like to have for one thermostat all points

Thanks.

There is a way by using trigger.now
I’m not at the computer at the moment but there is more info here:

I can try and explain a bit more later

Simply create a file containing multiple automations.

Sometimes it’s much simpler to create and maintain multiple short and simple automations rather than attempt to consolidate it into a single long and complex automation.

Each short automation can call a script and pass it the desired temperature.

- alias: 'Scheduled Temperature 05:30'
  trigger:
    - platform: time
      at: '05:30:00'
  condition:
    - condition: state
      entity_id: sensor.temperature
      below: 17.7
  action:
    - service: script.setpoint_temperature
      data:
        setpoint: 20

- alias: 'Scheduled Temperature 06:30'
  trigger:
    - platform: time
      at: '06:30:00'
  condition:
    - condition: state
      entity_id: sensor.temperature
      below: 18.8
  action:
    - service: script.setpoint_temperature
      data:
        setpoint: 22

The script sets the thermostat at the desired setpoint temperature:

#script:
  setpoint_temperature:
    sequence:
      - service: climate.set_temperature
        data:
          entity_id: climate.thermostat
          temperature: '{{setpoint}}'
          hvac_mode: heat

EDIT

If you really want to consolidate it into a single automation, here’s one possible way to do it:

- alias: 'Scheduled Temperature'
  trigger:
    - platform: time
      at: 
        - '05:30:00'
        - '06:30:00'
  action:
    choose:
      - conditions: "{{(trigger.now.time()|string)[:5] == '05:30' and states('sensor.temperature') < 17.7 }}"
        sequence:
          - service: script.setpoint_temperature
            data:
              setpoint: 20
      - conditions: "{{(trigger.now.time()|string)[:5] == '06:30' and states('sensor.temperature') < 18.8 }}"
        sequence:
          - service: script.setpoint_temperature
            data:
              setpoint: 22

If you don’t like this:

(trigger.now.time()|string)[:5] == '05:30' 

you can replace it with:

trigger.now.hour == 5 and trigger.now.minute == 30
2 Likes

Sorry, I never see you comment.
Many thanks for your help.
A question:
what does means: string)[:5] ?

Thanks a lot ! I never see conditions in the action part !

It’s python’s slice notation. It’s extracting the first 5 characters from the string containing the time.

The time is presented like this:
21:45:00
and we only need the first five characters containing the hours and minutes.

They are part of choose. For more information about choose, refer to the documentation:

Choose a group of actions

1 Like