Home Assistant powered meeting lights

Pairing smart lights with my calendar

Home Assistant Calendar and Light My wife and and I both work from home. We enjoy it, but it’s not without it’s issues. Using Home Assistant, I’m trying to create automations that make our work day smoother. The first automation turns on a light to notify us if we have an upcoming meeting.

Distractions Everywhere

Since the pandemic started, my wife and I have been working from home. Recently we made the change to working remotely permanently. Working remotely is great, but we’re in our house all the time. We no longer go to the office and we can’t avoid the unfolded laundry, the dirty dishes, and whatever mess our daughter made. It’s easy to get sidetracked with a little housework. Then there’s the TV. We often try to squeeze in another episode of whatever show we’re binging during lunch.

On multiple occasions, I’ve received a notification 15 minutes before my meeting, done some task for 20 minutes, realized I forgot, yelled the F word multiple times as I ran to my computer, and showed up late.

Indicator Lights

As anyone that’s seen my previous posts knows, I like indicator lights:

My thought was to rig up some kind of automation that would look at my calendar events and would trigger a script. There were plenty of command line tools to control smart lights (Lifx for example), but that felt like I would need to build something. Building something from scratch isn’t really my style (and honestly above my skill level), so I explored a few low code or prebuilt options.

Automation Options

Apple Shortcuts seemed promising at first. It can access my calendar and can control Homekit accessories. Unfortunately, shortcuts can’t be triggered off of a meeting notification.

Apple’s Calendar app on a Mac can open a file in place of a meeting notification. I could use the calendar to open an AppleScript that would run some command to turn on a light. Unfortunately, the “open a file” notification can’t be set as a default notification.

Finally I turned to Home Assistant. Home Assistant is built to control smart lights from pretty much any brand, has robust automation and has a calendar integration. It seemed like the easiest way to make this work. Spoiler alert, it was not easy.

Home Assistant Community Store

I’d already setup Home Assistant when I built my totally overkill Apple TV Sleep Timer, so I was familiar with it. I also had a couple of smart lights I thought would be a good fit for the project (one from Govee and one from Meross).

A little Googling led me to Home Assistant integrations for Govee and Meross. Both were available through the Home Assistant Community Store (HACS) add on. I won’t go into detail on set up, but at a high level:

Once that was done, I was able to control the lights with Home Assistant.

Home Assistant Calendar

The next step was to setup the calendar in Home Assistant. This was the most confusing part of the whole project. A calendar integration exists in Home Assistant, but the integration page doesn’t explain how to actually add your calendar. There are two additional integrations built in for CalDAV and Google Calendar. Both require setting up a project in Google Developer Console which I can’t do on my work Google account. Neither supports my wife’s Office 365 account.

A little searching led me to a custom repo for ICS calendar integration. Why ICS support isn’t in Home Assistant by default, I don’t understand, but it was fairly simple to install with HACS.

There’s no GUI to add an ICS calendar, so I needed to edit the configuration.yaml directly. There are several ways to do this, but I found the File editor add on is the easiest way to do this. I added something similar to this:

1
2
3
4
5
6
7
calendar:
- platform: ics_calendar
  calendars:
      - name: "Dustin work"
        url: "http://ICS-for-your-calendar"
      - name: "Other calendar"
        url: "http://ICS-for-another-calendar"

I restarted Home Assistant, and the calender integration was populated with events

Home Assistant calendar with test events

Notification light for meetings

Home Assistant automations have a built in calendar trigger. They can trigger from the start or the end of an event and you can set an offset for the trigger. I setup my Automation to trigger five minutes before the start of my meetings. Automation trigger

I skipped condition (for now) and setup my action. For my first pass, I setup the light to turn on and then turn off after 10 minutes (five minutes after my meeting starts).

Automation action

Still a ways to go before it had all the functionality I wanted, but it worked.

Automation improvements

The first simple improvement was another trigger for my wife’s calendar. I also added conditions to exclude events from triggering the light like Lunch Break or Trash Night. I used a Template condition type for that.

{{ 'Lunch Break' in trigger.calendar_event.summary }}.

Automation condition

The next thing I wanted to do was distinguish between my events and my wife’s. I created scenes for consistency. One scene was a red light, one was a blue light. I added an if statement to the action, and I set the light to blue for events triggered by my calendar, otherwise, it would be red.

This of course broke immediately when we both had events that started at the same time. So I added a little more logic. If the light is already on, make the light purple indicating we both have an event coming up. I also adjusted the triggers so my wife’s would fire five minutes and five seconds before the start to avoid two automations running in conflict.

Finally, I set up my two lights in the kitchen and living room so they’d be visible from the places I’m most likely to be if I’m not at my desk.

Wrap up

I’m really happy with how this turned out, and I’m excited to figure out some other calendar based automations to try with Home Assistant.

In the video below the light turns off after 30 seconds instead of 10 minutes for demonstration purposes. I also sped up the video because it’s not exactly action packed.

Prepare for edge of your seat excitement!

Below is the yaml if you’re interested in trying something similar.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
alias: Upcoming Event Combined
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-0:5:0"
    entity_id: calendar.dustinwork
    id: dustin work
  - platform: calendar
    event: start
    offset: "-0:5:5"
    entity_id: calendar.othercalendar
    id: other cal
condition:
  - condition: not
    conditions:
      - condition: template
        value_template: "{{ 'Lunch Break' in trigger.calendar_event.summary }}"
      - condition: template
        value_template: "{{ 'Trash Night' in trigger.calendar_event.summary }}"
action:
  - if:
      - condition: device
        type: is_on
        device_id: mydeviceID
        entity_id: light.meross_smart_light
        domain: light
    then:
      - service: scene.turn_on
        target:
          entity_id: scene.meross_purple
        metadata: {}
    else:
      - if:
          - condition: trigger
            id: dustin work
        then:
          - service: scene.turn_on
            target:
              entity_id: scene.meross_blue
            metadata: {}
        else:
          - service: scene.turn_on
            target:
              entity_id: scene.meross_red
            metadata: {}
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: mydeviceID
    entity_id: light.meross_smart_light
    domain: light
mode: restart


See also