RESOLVED - Google Calendar based lights

Go to 4th post for a better solution.

I am trying to turn on lights in the morning (and evening)) and off at a set time using a google calendar based event as I work shifts so can’t just hard code them.

I am trying to follow the setup @ih8gates mentions in the thread [SOLVED] Google Calendar and Holiday lighting

I don’t think I have set it up just right though as it will not trigger at all. I can manually trigger it though.
My calendar is called ‘Home-Assistant’ and the trigger / meeting is ‘test’
Quote marks are not part of the actual name.

configuration.yaml

google:
  client_id: id.apps.googleusercontent.com
  client_secret: Pass

Home Assistant generates the following file
google_calendars.yaml

- cal_id: [email protected]
  entities:
  - device_id: homeassistant
    ignore_availability: true
    name: Home-Assistant
    track: true

automation.yaml

# Clear previous days booleans
- alias: Reset Daily Booleans
  trigger:
    - platform: time
      at: '20:00:00'
  action:
    - service: homeassistant.turn_off
      entity_id:
        - input_boolean.test

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

- alias: "LightsOutTest"
  trigger:
    platform: time
    at: '13:20:00'
  condition:
    condition: state
    entity_id: input_boolean.test
    state: 'on'
  action:
    service: homeassistant.turn_off
    entity_id: group.AllLights

I have also tried the following changes:

- alias: test
  trigger:
    - platform: state
      entity_id: calendar.homeassistant
      to: 'on'
  condition:
    - condition: state
      entity_id: calendar.homeassistant
      state: 'test'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.test

Also:

- alias: test
  trigger:
    - platform: state
      entity_id: calendar.homeassistant
      to: 'on'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.test

But I can’t seem to get the lights to trigger.
Can anyone else think off an alternative way to time light Mon-Fri but alternating every other week?

1 Like

Well I have made a little progress in the form I can switch a light on / off by checking the Calendar state as below:

- alias: LightsOn1
  trigger:
    platform: state
    entity_id: calendar.halights
    to: 'on'
  action:
    service: light.turn_on
    entity_id: group.HallLights

- alias: LightsOff1
  trigger:
    platform: state
    entity_id: calendar.halights
    to: 'off'
  action:
    service: light.turn_off
    entity_id: group.HallLights

While it works it is not very flexible and requires constant internet connection.
What I would like to do is check the Calendar at say 20:30 store a value (early_shift or late_shift) to use later on to trigger lights turning on / off a certain times depending on what shift I am working that week. Is there another way, instead of using the input_boolean? As I can’t seem to get input_boolean to work.

Managed to resolve this by my self.
For some reason I couldn’t find the docs to read for “input_boolean” at first, but found them in the end.

Input Boolean

I didn’t declare the input_boolean.
So I added the below to configuration.yaml

input_boolean:        
  test:

Ooops :slight_smile:

I have worked on this some more to clean it up and improve the functionality, I no longer need separate calendars. I can search within one calendar now. I still can’t get the offset to work though, so I have moved my timers in the calendar to 8:30PM.

configuration.yaml

# Track calendar false is needed to prevent Hass from overwriting the google_calendar.yaml file.
google:
  client_id: id.apps.googleusercontent.com
  client_secret: password
  track_new_calendar: false

input_boolean:        
  early_shift:
  late_shift:

google_calendars.yaml

- cal_id: [email protected]
  entities:
  - device_id: early_shift
    name: Early Shift
    track: true
    search: "#early_shift"
  - device_id: late_shift
    name: Late Shift
    track: true
    search: "#late_shift"

automations.yaml

# Clear previous days booleans
- alias: Reset Daily Booleans
  trigger:
    - platform: time
      at: '20:00:00'
  action:
    - service: homeassistant.turn_off
      entity_id:
        - input_boolean.early_shift
        - input_boolean.late_shift

# Set Booleans from calendar
- alias: Early Shift
  trigger:
    - platform: state
      entity_id: calendar.early_shift
      to: 'on'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.early_shift

- alias: Late Shift
  trigger:
    - platform: state
      entity_id: calendar.late_shift
      to: 'on'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.late_shift
 
# Automation for when to turn lights off after going bed.
# Time for bed...
- alias: "LightsOutBedEarly"
  trigger:
    platform: time
    at: '22:15:00'
  condition:
    condition: state
    entity_id: input_boolean.early_shift
    state: 'on'
  action:
    service: homeassistant.turn_off
    entity_id: group.AllLights

- alias: "LightsOutBedLate"
  trigger:
    platform: time
    at: '01:00:00'
  condition:
    condition: state
    entity_id: input_boolean.late_shift
    state: 'on'
  action:
    service: homeassistant.turn_off
    entity_id: group.AllLights

# Automation for when to turn lights off when going to work.
# Time for work...
- alias: "LightsOutWorkEarly"
  trigger:
    platform: time
    at: '05:20:00'
  condition:
    condition: state
    entity_id: input_boolean.early_shift
    state: 'on'
  action:
    service: homeassistant.turn_off
    entity_id: group.AllLights

- alias: "LightsOutWorkLate"
  trigger:
    platform: time
    at: '12:40:00'
  condition:
    condition: state
    entity_id: input_boolean.late_shift
    state: 'on'
  action:
    service: homeassistant.turn_off
    entity_id: group.AllLights

# Automation for when to turn lights on in the mornings.
# Time to get up earlies...
# Condition ideally needs to check light lux for summer months, no need for kitchen
# lights then.
- alias: "LightsOnMorningEarly"
  trigger:
    platform: time
    at: '04:45:00'
  condition:
    condition: state
    entity_id: input_boolean.early_shift
    state: 'on'
  action:
    - service: homeassistant.turn_on
      entity_id: group.HallLights
    - delay: 00:00:10
    - service: homeassistant.turn_on
      entity_id: group.LivingRoomLights
    - delay: 00:00:10
    - service: homeassistant.turn_on
      entity_id: light.KitchenCeiling

Hopefully this will help someone out who is trying to get lights etc working from a calendar. I needed my lights to be different each week as I work shifts. My calendar triggers at 8:30PM the day before. So when I work Mon - Fri my calendar is Sun - Thurs, unless I work overtime on Sat, then I put an overtime trigger into the calendar on Fri. I did it this was so I could trigger lights before going bed and when I get up.

3 Likes

Thanks for posting your solution, this really helped me understanding how things worked!

Glad it helped someone out.

@wills106 Thanks. I started trying to mess with this component. I see it in my Developer Tools/STATES tab. It is showing off.
I created an all day entry, do these work? Or does it have to be a start/end time?
Does the case matter for the event title?
What is offset used for? That maybe my issue.
[Edit: More Info]
Also, looking at the logs I was getting an error and I had to rem out the name under the change_air_filter.

cal_id: [email protected]
  entities:
  # - device_id: home_assistant
    # ignore_availability: true
    # name: Home Assistant
    # track: false
  - device_id: change_air_filter
    # name: Change Air Filters
    ignore_availability: true
    name: Home Assistant
    track: true
    search: "#change air filter"

My goal is to set a date, then when that date arrives, it toggles an input switch. Then when I turn the switch off, it sets the next event a month out. Then I can do more automation around that if the switch is not off in an x amount of time, then send another alert and so on.

Posting this reply for anyone else who lands here with google calendar issues.

I may have discovered what is tripping me up. Digging through the code, I found that the calendar is updated once every 15 minutes. I was setting it just a couple of minutes ahead. If you are doing that kind of testing you will have to restart to force a read of the calendar.

Also, I noticed if you look at the state, if you have your entity configured correctly then you will see more info in the description. Here are screenshots of my Change air filter vs Holidays.


Actually, my Change Air Filter is correctly configured, just that all events are in the past.

As far as my issue with the name, it told me I had two, I was just so confused about the update issue, I could not see past the mountain in front of me. I guess it was a case of “cut and paste” is my friend.