bikerchris
(Chris Ellwood)
November 11, 2021, 4:18pm
1
Hi all,
I’m very sorry about asking what might be a trivial question, I promise I’ve searched for a while first!
I can understand how to setup an automation, such as turn something off/on at a certain times, but I’m looking for an easy way to say:
turn off at 11:30pm IF Saturday or Sunday
turn off at 10pm IF Monday-Friday.
Is there a way of doing this, without having to learn too much
Thanks in advance!
Chris
My config if background info is helpful (it’s on a Pi)
AllHailJ
(J Gent)
November 11, 2021, 4:32pm
2
Here is an automation that does similar things to what you are describing.
alias: Roomba - FR and Study Lights on
description: Vacuum Study and Family Room - Control Lights
trigger:
- platform: time
at: input_datetime.roomba_start
- platform: time
at: input_datetime.roomba_end
condition: []
action:
- service: homeassistant.turn_on
target:
entity_id: input_boolean.vacuum
- choose:
- conditions:
- condition: time
after: input_datetime.roomba_start
weekday:
- mon
- wed
- fri
before: input_datetime.roomba_end
sequence:
- type: turn_on
device_id: ad401f2424017d0df206d3ca3f1cd602
entity_id: light.study_cans_current_value
domain: light
brightness_pct: 60
- type: turn_on
device_id: 7260181aea2544798fc29aa843d5cc71
entity_id: switch.kitchen_table_light
domain: switch
- type: turn_on
device_id: 5fdaa8f94d25448f5c1464839d4dd783
entity_id: switch.family_room_standing_lamp
domain: switch
- conditions:
- condition: time
after: input_datetime.roomba_end
weekday:
- mon
- wed
- fri
before: '23:57:00'
sequence:
- type: turn_off
device_id: ad401f2424017d0df206d3ca3f1cd602
entity_id: light.study_cans_current_value
domain: light
- type: turn_off
device_id: 5fdaa8f94d25448f5c1464839d4dd783
entity_id: switch.family_room_standing_lamp
domain: switch
- type: turn_off
device_id: 7260181aea2544798fc29aa843d5cc71
entity_id: switch.kitchen_table_light
domain: switch
- service: homeassistant.turn_off
target:
entity_id: input_boolean.vacuum
default: []
mode: single
This is what it looks like from the GUI:
Here is a sample automation
alias: Trigger Time and Day
description: ''
trigger:
- platform: time
at: '22:00:00'
condition:
- condition: time
after: '22:00:00'
weekday:
- mon
- tue
- wed
- thu
- fri
action:
- service: switch.turn_off
target:
entity_id: switch.family_room_fan_light
mode: single
1 Like
bikerchris
(Chris Ellwood)
November 11, 2021, 4:33pm
3
Thank you @AllHailJ for responding so quickly, I’ll give this a go. Really appreciated!
The built-in method that @AllHailJ showed does require the least learning, but if you end up needing to do a lot of automations that differentiate between weekdays and non-weekdays it can get annoying toggling all those switches.
I use a template binary sensor . It is “on” if it’s a weekday and “off” if it’s the weekend.
### configuration.yaml
template:
binary_sensor:
- name: Weekday
icon: mdi:calendar-check
state: >-
{{ 1 <= now().isoweekday() <= 5 }}
Example Automation
alias: Turn off the switch every night
description: 'Turn switch off at specified times for weekdays and weekends'
trigger:
- platform: time
at: '22:00:00'
id: Weekday
- platform: time
at: '23:30:00'
id: Weekend
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: Weekday
- condition: state
entity_id: binary_sensor.weekday
state: "on"
sequence:
- service: switch.turn_off
target:
entity_id: switch.family_room_fan_light
- conditions:
- condition: trigger
id: Weekend
- condition: state
entity_id: binary_sensor.weekday
state: "off"
sequence:
- service: switch.turn_off
target:
entity_id: switch.family_room_fan_light
default: []
mode: single
1 Like
bikerchris
(Chris Ellwood)
November 11, 2021, 7:42pm
5
Thank you very much for that.
I am in the early days and in honesty, don’t understand the majority (no IT background) of what I’m seeing, but I’m getting there…very slowly!
nickrout
(Nick Rout)
November 11, 2021, 8:01pm
6
The workday sensor of course
1 Like