[SOLVED] Google Calendar and Holiday lighting

A technique that I use with Google Calendars is to have an input_boolean that gets flipped to “true” based on a calendar event. Then I have an automation that runs at end of day to reset the booleans. I use this for “is today trash day / is tomorrow trash day”, then, knowing that today is trash day, I can trigger spoken notifications at certain times during that day based on motion in a particular room. I cluster the calendar events around 12:30am so they’re valued before we start our day.

thank you @ih8gates thats an interesting approach to that.

Right now I’ve got it setup like this. I’ll have to add another event to the calendar since we only run ours through the 31st of Dec but well I can always just create an event for tonight and see what happens.

- 
  action: 
    - 
      entity_id: group.christmas_lights
      service: light.turn_on
  alias: "Christmas Lights"
  id: christmas_lights
  trigger: 
    - 
      entity_id: calendar.christmas_lights
      platform: state
      to: "True"
    - 
      event: sunset
      offset: "00:20:00"
      platform: sun

Just what I was looking to do this year, but couldn’t really figure it out. Would any of you know where I could find an example on how to turn on an Input_Boolean from a calendar entry? Should that entry be an all day event?

Also do you need one entry for every day or one single entry at the beginning of December to turn the input_boolean “on” and one at the end of December to turn it “off”? I can see the reasoning of having one entry per day, this way if the system is down on the day that it is supposed to be turned off, then it will correct itself by the end of the day.

With my example, I have the boolean set every day. That’s because I clear them every day. You can determine what works best for you.

Some sample code:

- alias: Reset Daily Booleans
  trigger:
    - platform: time
      at: '00:01:00'
  action:
    - service: homeassistant.turn_off
      entity_id:
        - input_boolean.trash_day
        - input_boolean.recycle_day
        - input_boolean.trash_tomorrow
        - input_boolean.recycle_tomorrow
        - input_boolean.school_holiday

## set bools from calendar sensor ##
- alias: Trash Today
  trigger:
    - platform: state
      entity_id: calendar.trash_today
      to: 'on'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.trash_day

- alias: Trash Tomorrow
  trigger:
    - platform: state
      entity_id: calendar.trash_tomorrow
      to: 'on'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.trash_tomorrow

- alias: Recycle Today
  trigger:
    - platform: state
      entity_id: calendar.recycle_today
      to: 'on'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.recycle_day

- alias: Recycle Tomorrow
  trigger:
    - platform: state
      entity_id: calendar.recycle_tomorrow
      to: 'on'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.recycle_tomorrow
      
- alias: School Holiday
  trigger:
    - platform: state
      entity_id: calendar.school_holiday
      to: 'on'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.school_holiday
2 Likes

Thanks … this is a great start and good examples. Now your calendar entry … is it for an “All Day” even or do you schedule it for a specific time of the day? And does your Subject line just lists “trash_today” … “recycle_today”? I am assuming that the text in your calendar should match closely your entity_id … correct?

The event only needs to be a minute long since the boolean keeps state. You could probably have an all-day event and do the exact same thing, skipping the boolean entirely.

I use a search key to match the name of my event. Read up here:

That’ll also let you configure the entity_id of your calendar sensor.

Well mine did not fire off like it should’ve tonight. It shows in the attributes that the event is true but it didn’t turn on the lights at 20 mins after sunset. Time to diagnose. I am using an all day event for mine.

Set the sunset as a trigger and the calendar entry as a condition. The way you’ve set things, the automation will trigger once when the calendar sensor is true, then never trigger again unless the calendar goes false then back to true. And then the trigger will coincide with the calendar, not sunset.

Ah that makes total sense. Making the changes now :slight_smile:

Ok so this is what I have but its still not firing off. Wish it would spit something out in the logs

- 
  action: 
    - 
      entity_id: group.christmas_lights
      service: light.turn_on
    - 
      delay: "04:00:00"
    - 
      entity_id: group.christmas_lights
      service: light.turn_off
  alias: "Christmas Lights on for 4 hours at 20 mins after sunset"
  condition: 
    condition: state
    entity_id: calendar.christmas_lights
    state: "on"
  id: christmas_lights_normal
  trigger: 
    - 
      event: sunset
      offset: "01:00:00"
      platform: sun

EDIT btw I know my offset is for an hour after sunset because I keep playing with the time to see if it’ll fire off

Couple of things to check:

  1. Look at the states dev tool. Make sure that calendar.christmas_lights has a state of “on”
  2. Look at the automation in the states dev tool - does it have a “last_triggered” value?
  3. What happens if you manually trigger the automation? Do the lights behave correctly?
  4. Is that really what your YAML looks like? I don’t have newlines after dashes (-). But that might be fine notation - just not how I do it. Make sure there are no errors in your home_assistant.log

Some additional advice: I’m not sure I’d go with a 4 hour delay in the action. Set up 2 automations, one for turning the lights on, one for turning them off. Use a 4 hour offset for the off.

Also - I sometimes notice issues when I restart my HA within the window of sunset-based automations that use offsets.

Sorry but why you need the trash day in HA?

My system speaks reminders so that my kids remember to take cans to the curb. They get a couple reminders the evening before, then one more the morning of.

Also, I can ask: “Alexa, is tomorrow recycle day?” (we get recycling every other week)

you in Africa? :blush: :stuck_out_tongue:

We have it every single day … and each day something different (paper, plastic, etc…)

In the UK it’s fortnightly most places. Usually alternating weekly between recyclable and landfill, with a monthly garden waste collection.

Yeah the formatting is from the yamlint checker. It does that apparently to make it ruby compliant. I’m like eh whatever lol.

Ok so I moved the event from yesterday to, today and it is now showing up as on. However when I trigger the automation nothing happens. Is this because I need to call a different service to turn on a group? Time to google that one.

EDIT: This explains it all https://home-assistant.io/getting-started/automation-2/

I can’t do the light.turn_on because I have switches and lights tied together in the group. So I have to use homeassistant.turn_on to turn on the group. Now to test it out but I think this might be the kicker

EDIT2: Yep that was it. So obvious now to see if it turns on the lights after sunset tonight.

Oh I also took your advice to separate the turn off so its no longer in the turn on automation instead I did it where it will turn off 6 hours and 20 mins after sunset. I forgot that I wanted 6 hours and not 4

Just wanted to post an update my lights turned on just like they should. Thank you for your help with this I greatly appreciate it.

1 Like

Could you share how you set up the voice reminders? @ih8gates

I use a motion sensor on my security system to trigger so that I know someone’s there to hear it. I set a boolean at times throughout the day to say “hey - there’s a message waiting”.

My code for valuing the “trash today/trash tomorrow” type bools is above.

I have the “message waiting” automation fire off several scripts. Each of the scripts has a condition to exit if it doesn’t apply. Then it turns off the “message waiting” bool.

I use a script to handle speech so that I can easily change TTS. I also include some booleans to make sure my wife and I are awake before speaking. I describe that in this thread:

automations:

- alias: Enable Trash Message Indicator
  trigger: 
    - platform: time
      at: '6:20'
    - platform: time
      at: '14:30'
    - platform: time
      at: '18:00'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.trash_message_waiting

- alias: Announce Trash on Motion if Message Indicator
  trigger:
    - platform: state
      entity_id: binary_sensor.livingroom_motion
      from: 'off'
      to: 'on'
  condition:
    - condition: state
      entity_id: input_boolean.trash_message_waiting
      state: 'on'
    - condition: state
      entity_id: sensor.everyone_awake
      state: 'on'
  action: 
    - service: script.announcetrashtoday
    - service: script.announcetrashrecyclingtoday
    - service: script.announcetrashtomorrow
    - service: script.announcetrashrecyclingtomorrow
    - service: homeassistant.turn_off
      entity_id:
        - input_boolean.trash_message_waiting

scripts:

announcetrashtoday:
  alias: Announce if trash today
  sequence:
    - condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.trash_day
          state: 'on'
        - condition: state
          entity_id: input_boolean.recycle_day
          state: 'off'
    - service: script.speak
      data_template:
        message: "Today is trash day."
    
announcetrashtomorrow:
  alias: Announce if trash tomorrow
  sequence:
    - condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.trash_tomorrow
          state: 'on'
        - condition: state
          entity_id: input_boolean.recycle_tomorrow
          state: 'off'
    - service: script.speak
      data_template:
        message: "Tomorrow is trash day."
    
announcetrashrecyclingtoday:
  alias: Announce if trash and recycling today
  sequence:
    - condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.trash_day
          state: 'on'
        - condition: state
          entity_id: input_boolean.recycle_day
          state: 'on'
    - service: script.speak
      data_template:
        message: "Today is trash and recycling day."
    
announcetrashrecyclingtomorrow:
  alias: Announce if trash and recycling tomorrow
  sequence:
    - condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.trash_tomorrow
          state: 'on'
        - condition: state
          entity_id: input_boolean.recycle_tomorrow
          state: 'on'
    - service: script.speak
      data_template:
        message: "Tomorrow is trash and recycling day."


speak: 
  alias: TTS Handler
  sequence: 
    - condition: or
      conditions:
        - condition: template
          value_template: "{{ unmute == 'true' }}"
        - condition: and
          conditions:
            - condition: state
              entity_id: input_boolean.me_awake
              state: 'on'
            - condition: state
              entity_id: input_boolean.wife_awake
              state: 'on'
    - service: tts.google_say
      entity_id: media_player.squeezelite
      data_template:
        message: "{{ message }}"