With the current versions on Home Assistant, I would hope there is a less complex way to have an automation config that has an action to turn on a light at one time on a weekday and another time on a weekend. But it still seems overly complicated. This is what I’ve come up with, can anyone let me know if there is a simpler solution to handle this?
alias: Basement Light On
description: ""
trigger:
- platform: time
at: "06:00:00"
id: weekday
alias: Weekday Trigger
- platform: time
at: "09:00:00"
id: weekend
alias: Weekend Trigger
condition: []
action:
- if:
- condition: trigger
id: weekday
- condition: state
entity_id: binary_sensor.workday_sensor
state: "on"
then:
- service: light.turn_on
data: {}
target:
entity_id: light.basement
alias: Weekday action
- if:
- condition: trigger
id: weekend
- condition: state
entity_id: binary_sensor.workday_sensor
state: "off"
then:
- service: light.turn_on
data: {}
target:
entity_id: light.basement
alias: Weekend action
mode: single
1 Like
How are you defining “simpler”?
petro
(Petro)
May 2, 2023, 2:16pm
3
You can create a template sensor and trigger off that.
template:
- sensor:
- name: Basement Light Time
device_class: timestamp
state: >
{% set weekday = today_at("06:00") %}
{% set weekend = today_at("09:00") %}
{{ iif(is_state('binary_sensor.workday_sensor', 'on'), weekday, weekend) }}
And then your automation
alias: Basement Light On
description: ""
trigger:
- platform: time
at: sensor.basement_light_time
action:
- service: light.turn_on
target:
entity_id: light.basement
1 Like
Troon
(Troon)
May 2, 2023, 2:20pm
4
Set up a Schedule helper via the UI. Then:
alias: Basement Light manager
trigger:
- platform: state
entity_id: schedule.basement_light
action:
- service: light.turn_{{ trigger.to_state.state }}
target:
entity_id: light.basement
This also turns it off based on your schedule — if that’s not time-based, how are you switching it off?
Alternatively, yet another way to do exactly what you’ve asked for:
alias: Basement Light On
trigger:
- platform: time
at: "06:00:00"
id: wk_on
- platform: time
at: "09:00:00"
id: wk_off
condition:
- "{{ is_state('binary_sensor.workday_sensor', trigger.id.split('_')[1]) }}"
action:
- service: light.turn_on
target:
entity_id: light.basement
1 Like
Honestly, the way you have it seems to be pretty ‘simple’. You could also just have two different automations - and, while simpler, does create an extra automation.
Always multiple ways to do things in HA - really comes down to finding a ‘relatively standardized’ process (in your head anyways) and sticking w/ that.
1 Like
Thanks everyone. I was trying to avoid referencing the same action twice, and these are some great ideas to explore.