#Using calendars to switch on lights, But..

1 messages · Page 1 of 1 (latest)

vapid bloom
#

When there is a power outage and the power resumes after the start time and within the event duration, the automation does not work. How can i modify the code, very new to YAML. Thanks in advance.

alias: gate light
description: ""
triggers:

  • trigger: calendar
    event: start
    entity_id: calendar.lighting_calendar
  • trigger: calendar
    event: end
    entity_id: calendar.lighting_calendar
    conditions:
  • condition: template
    value_template: "{{ 'Gate Lights' in trigger.calendar_event.summary }}"
    actions:
  • if:
    • condition: template
      value_template: "{{ trigger.event == 'start' }}"
      then:
    • action: switch.turn_on
      target:
      entity_id: switch.outdoor_lights_2_switch_2
      data: {}
    • action: persistent_notification.create
      data:
      title: gate lights
      message: switched on
      notification_id: "10"
      else:
    • action: switch.turn_off
      target:
      entity_id: switch.outdoor_lights_2_switch_2
      data: {}
      mode: single
sterile bridge
#

the way i would do this is:
create scene with lights on
create scene with lights off
then automation:
trigger: start
trigger: end
trigger: home assistant starts

action:
if block:
if light supposed to be on then activate scene with it on
else activate scene with it off

stoic monolith
#

Instead of calendar start, you do a state trigger if the calendar entity turns on - that will trigger both when the event starts, and whenever ha restarts and the event is ongoing

#

But that won't work if you have overlapping events etc, so Michael's should work

sterile bridge
#

mine is not perfect but its simple

stoic monolith
#

The only thing I'd caution you on is that it might be annoying if the automation turns lights on, you manually turn them off for whatever reason, then ha restarts and it turns then back on or vice versa, so you might want to have some way of checking if the automation has already turned the lights on/off today and not run if that's the case

sterile bridge
#

depends on how often you have power cuts i suspect. sometimes over engineering for corner cases leads to more problems

vapid bloom
#

Thank you.. Being a newbie finding this a bit over whelming.. Let me see if I can do this