#Turning on automation at different times depending on the day

1 messages · Page 1 of 1 (latest)

true bluff
#

Hi i need some help regarding automation to turn on HVAC unit based on days of week. I have it like this:```yaml
alias: HVAC
description: ""
trigger:

  • platform: time
    at: "8:00:00"
    condition:
  • condition: time
    weekday:
    • mon
    • tue
    • wed
    • thu
    • fri
      action:
  • device_id: ******
    domain: climate
    entity_id: climate.HVAC
    type: set_hvac_mode
    hvac_mode: cool
    mode: single``` and it only turns on at 8:00, i want to have it so that it turns on at different times depending on the day. Ex: Monday: at 11:00, Tuesday: at 9:45, etc... Can this be done?
odd lava
#

If you want to keep the configuration inside the yaml of this automation you can use a template trigger with a template like this:


{% set map = {1:'mon', 2:'tue', 3:'wed', 4:'thu', 5:'fri', 6:'sat', 7:'sun'} %}
{% set schedule = {'mon':'08:00', 'tue':'09:45','sun':'03:50'} %}
{% set dayofweek = map[now().isoweekday()] %}
{{ now() > today_at(schedule.get(dayofweek)) }}
#

But the simple way is to create a schedule helper, and set your trigger to


trigger:
  - platform: state
    entity_id:
      - schedule.test
    from: "off"
    to: "on"
#

Helpers can be found at settings -> devices and services, then the ‘helpers’ tab

true bluff
#

Thanks i will try the first method and see if it works

true bluff
odd lava
#

You just need to leave those days out of the schedule but keep them in the map. Otherwise you will have to handle the error when the dayofweek variable is set and there is no day to map it to

true bluff
#

👍🏻

#

Thanks

odd lava
#

You can play around with it in the template editor to make sure you know what it is doing. Keep in mind it will only trigger when it goes from false to true, and it will stay true on days that you don’t want it to run. Which is ok because it never goes from false to true so it still won’t run. On days you want it to run it will go to false after midnight and then go to true at the time you specify.

true bluff
#

I hope it will work only from the time it's specified, i will turn it off manually. I just need this to keep the room cool when i'm not home and when i'm home i will turn it off.

#

And since i don't have a fix time that i'm away i wanted to automate this and not use a fix hour like 8:00 for every day.

odd lava
#

Yep it will do that.
If you don’t like it being true on days it doesn’t run you can change the last line to


{{ false if dayofweek not in schedule.keys() else now() > today_at(schedule.get(dayofweek)) }}

But it will make no difference to the automation actually triggering or not

true bluff
#

Thank you! You're awesome!