Automations or script

Hi, i am trying to control my boiler. I have it all working on Zwave but i was wondering how best to do the control ie.
between 21:00 and 5am the living room at 16 day time 22 weekends are different. Does this all have to be done with lots of automations or is there somewhere i can write one script for everything.
Paul.

You can do a single automation, but it’s going to be complicated and hard to read.

Better to do one automation for each target temperature. You can then use multiple triggers and conditions, eg:

automation:
  alias: 'Morning warm'
  initial_state: 'on'
  trigger:
    - platform: time
      at: '05:00:00'
    - platform: time
      at: '08:45:00'
    - platform: numeric_state
      entity_id: sensor.living_room_temperature
      below: 22
    - platform: homeassistant
      event: start
  condition:
    - condition: numeric_state
      entity_id: sensor.living_room_temperature
      below: 22
    - condition: or
      conditions:
        - condition: time
          after: '04:59:59'
          before: '21:00:00'
          weekday:
            - mon
            - tue
            - wed
            - thu
            - fri
        - condition: time
          after: '08:44:59'
          before: '22:00:00'
          weekday:
            - sat
            - sun
  action:
    - service: switch.turn_on
      entity_id: switch.my_heater

Before you start wondering at the complexity, it’s designed so that the automation will trigger when:

  1. It’s 05:00
  2. It’s 08:45
  3. The temperature drops below 22
  4. Home Assistant starts

Then, after it triggers, the automation checks to see that:

  1. The temperature is below 22
  2. It’s either after 04:59:59 and before 21:00 (weekdays) or after 08:44:59 and before 22:00 (weekends)

This means that the automation will work if it’s already too cold before the start time is reached, or if you restart Home Assistant during operating hours.

If the conditions are met, the heater is turned on. Clearly you’ll need another automation to turn it off :wink: