Check Google Calendar before turning on lights issue

Hi all -

I am still pretty new to HA and have run into an issue with my lights automation. Basically I have my home office lights turn on every day at 7:45am when I am working from home which is most of the time. Now there is 1 week out of the month that I will have to go into work and would like my home office lights to stay off. Since I normally list an entry of “Matt @ Work” on the google calendar for that week and I have some how managed to get my google calendar synced with Home assistant, I figured that I’d just add a condition to check if the “Matt @ Work” is not listed on the calendar. The problem is that I can never get the condition to function and I always registers as me being home. Here is what I have.

alias: Test turn home office lights on when not at work
description: Turn on home office lights durring the work week and I am at home
trigger:
  - platform: time
    at: "07:45:00"
    enabled: true
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  - condition: template
    value_template: "{{ not is_state('calendar.matt_s_work_calendar', 'Matt @ Work') }}"
action:
  - service: scene.turn_on
    target:
      entity_id: scene.office_lights_on
    metadata: {}
mode: single

I’ve tried looking through the other posts and can’t quite figure out why the condition is not preventing the lights from coming on - it always tests as “true” (i.e. no entry for “Matt @ Work”) when I clearly have a multi-day event showing “Matt @ Work” from the linked google calendar on the calendar page within Home Assistant.

What the heck am I missing here?

Thanks a bunch for your help!

The state is always on or off.
What you want is

{{ state_attr('calendar.matt_s_work_calendar','message') != 'Matt @ Work' }}

I have never had success with using Google Calendar time-specific events in HA automations. However what works perfectly for me has been to create sub-calendars in my Google Calendar account and then use whole day events. I have some 15 different sub-calendars such as days that cleaning lady comes, wake-up at 6 am, wake up at 7 am (etc), work days, trips, and more.
This is an example using my “Trip” sub-calendar to set the Nest thermostats in my home.
In my Google Calendar I create a whole day event, using the sub-calendar “Trip” for the days that we travel. In this example, these are on days that the cleaning lady does not come, and we have another automation for the days that she does come:

alias: "#96-16 Nest thermostats Trip"
description: ""
trigger:
  - platform: time
    at: "07:00:00"
  - platform: time
    at: "11:00:00"
  - platform: time
    at: "15:00:00"
  - platform: time
    at: "19:00:00"
  - platform: time
    at: "23:00:00"
  - platform: time
    at: "03:00:00"
condition:
  - condition: state
    entity_id: calendar.18_trips
    state: "on"
  - condition: state
    entity_id: calendar.17_cleaning_lady
    state: "off"
action:
  - service: climate.set_temperature
    data:
      temperature: 78
    target:
      entity_id: climate.bedrooms
  - service: climate.set_temperature
    data:
      temperature: 78
    target:
      entity_id: climate.living_room
mode: single

Interesting- I’ve been meaning to try something like this for my nest thermostat… thanks!

Oh- I think this is working! I’ll double check it in the morning to see if it still works for me. Thank you!

2 Likes