[SOLVED] Google Calendar and Holiday lighting

So I just got my first automation working with the google calendar plugin today. I’m currently a SmartThings user but I’m working on moving some stuff over to HASSIO.

I created a calendar for me to plug in things that I want to fire off based off the date. For example right now I turn on my Christmas lights at 20 mins after sunset. Since there isn’t a way to plug sunset into the calendar. Should I just create the event as an all day event and then in the automation to turn on those lights would I just add a condition for sunset with a 20 min offset? Thanks for your help, I can’t believe everything that you can do with this platform its just incredible.

Edit: Or rather than a condition just add it to the trigger section?

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