I managed to sync my wake up alarm with HA using this guide. I have an entity called ‘input_datetime.ios_sync’ that ‘receives’ the time of my wake up alarm each night at 03:00.
Now I want to turn an automation off based on the given time: if it’s a weekday and the alarm clock is set at 08:30, turn off automation X and turn back on again after X hours. I am not very good at YAML, any help is appreciated.
Thanks a lot, I’ve been thinking of doing this as an alternative! Is your calendar event called ‘start’? And off-set triggers the actions 6 hours from the start of the day (00:00h), do I understand this correctly?
It is generally a bad idea to automate disabling/enabling automations, instead you should design the conditional logic of your automations to keep their actions from being executed when you don’t want them to be executed.
Reserve disabling automations for when you need to debug existing automations or test new ones.
Thanks! Good to know. In that case I would like to have the automation to turn on my lights when movement is detected take into account the time of my alarm clock input_datetime.ios_sync. Any suggestions of how I would do that?
This is the YAML code for the current automation:
alias: Beweging slaapkamer aan (werkdagen)
description: >-
Als er beweging wordt gedetecteerd in de slaapkamer, als de lux is onder 25,
als het voor 22:30 is op een weekdag schakel dan de lichten in de slaapkamer
in.
trigger:
- type: motion
platform: device
device_id: 6cf96cb6e8a10411427c8a3ce13895eb
entity_id: binary_sensor.hue_motion_sensor_1_motion
domain: binary_sensor
condition:
- type: is_illuminance
condition: device
device_id: 6cf96cb6e8a10411427c8a3ce13895eb
entity_id: sensor.hue_motion_sensor_1_illuminance
domain: sensor
below: 25
- condition: time
before: "22:30:00"
weekday:
- mon
- tue
- wed
- thu
- fri
after: "06:45:00"
action:
- type: turn_on
device_id: 797cf80e91e860be277f7820c8c837ba
entity_id: light.slaapkamer
domain: light
brightness_pct: 50
mode: single
If on a weekday (Monday through Friday) my alarm is set to 08:30 or later then the lights should not turn on at movement.
Otherwise, the lights should turn on when movement is detected and the lux is below 25 starting from 06:45 (not before that time to prevent turning the lights on when going to the bathroom in the night).
In either case the lights should turn on when it’s dark enough in the room (hence the lux variable) and when its before 22:30.
Thanks a lot, I’ve been thinking of doing this as an alternative! Is your calendar event called ‘start’? And off-set triggers the actions 6 hours from the start of the day (00:00h), do I understand this correctly?
alias: Beweging slaapkamer aan (werkdagen)
description: >-
Als er beweging wordt gedetecteerd in de slaapkamer, als de lux is onder 25,
als het voor 22:30 is op een weekdag schakel dan de lichten in de slaapkamer
in.
trigger:
- type: motion
platform: device
device_id: 6cf96cb6e8a10411427c8a3ce13895eb
entity_id: binary_sensor.hue_motion_sensor_1_motion
domain: binary_sensor
condition:
- type: is_illuminance
condition: device
device_id: 6cf96cb6e8a10411427c8a3ce13895eb
entity_id: sensor.hue_motion_sensor_1_illuminance
domain: sensor
below: 25
- condition: time
before: "22:30:00"
weekday:
- mon
- tue
- wed
- thu
- fri
after: "06:45:00"
- condition: template
value_template: >
{{ states('input_datetime.ios_sync') < "08:30:00" }}
action:
- type: turn_on
device_id: 797cf80e91e860be277f7820c8c837ba
entity_id: light.slaapkamer
domain: light
brightness_pct: 50
mode: single
The above assumes your Input datetime is a time-only type. For a date & time type that includes the current day’s date you would use:
Is your calendar event called ‘start’? And off-set triggers the actions 6 hours from the start of the day (00:00h), do I understand this correctly?
I am not the king of Yaml and created this automation with the Visual Editor.
I come from the Universal Devices “eisy” environment and its Google calendar nodeserver (integration) only works with all day events, and I have not explored how to make an automation based on timed event. So, the answer is that the all day event starts at midnight and therefore there is an offset of 06:00:00, as this particular schedule should start at 6 am. I have some 6 different wake-up automations based on different wake-up times as per my wife’s and my schedule, depending on our work and other commitments.
Thanks! Should I create two automations to differentiate between the morning and the rest of the day? With the added condition, the lights don’t turn on when movement is detected when it’s dark enough while that is what I want to happen, despite my alarm clock in the morning.
That is a condition I have been thinking about for a while, so that lights go on when it is dark outside. During Summer, it would be sufficient to open the curtains, turn the TV on and have Alexa make an announcement. That is still on the drawing board.
Ok, add an “or” to the template in the condition so the condition passes if the current time is at least the time stored in the helper:
alias: Beweging slaapkamer aan (werkdagen)
description: >-
Als er beweging wordt gedetecteerd in de slaapkamer, als de lux is onder 25,
als het voor 22:30 is op een weekdag schakel dan de lichten in de slaapkamer
in.
trigger:
- type: motion
platform: device
device_id: 6cf96cb6e8a10411427c8a3ce13895eb
entity_id: binary_sensor.hue_motion_sensor_1_motion
domain: binary_sensor
condition:
- type: is_illuminance
condition: device
device_id: 6cf96cb6e8a10411427c8a3ce13895eb
entity_id: sensor.hue_motion_sensor_1_illuminance
domain: sensor
below: 25
- condition: time
before: "22:30:00"
weekday:
- mon
- tue
- wed
- thu
- fri
after: "06:45:00"
- condition: template
value_template: >
{% set alarm = states('input_datetime.ios_sync') %}
{{ alarm < "08:30:00" or now() >= today_at(alarm) }}
action:
- type: turn_on
device_id: 797cf80e91e860be277f7820c8c837ba
entity_id: light.slaapkamer
domain: light
brightness_pct: 50
mode: single