Home / Home Assistant / Control Home Assistant with your calendar

Control Home Assistant with your calendar

The smart home only works well as long as everything is done the way you are used to. But what if something is not ‘normal’? Someone is staying over, you are on holiday or you are having a party. Of course, you don’t want your visitors to set off the alarm, and you still want to have lights on even though you are in bed. Even at a party, you don’t want the heating to be turned off at 9 p.m.

To get these exceptions more or less under control, I created a separate Google Calendar, which I integrated into Home Assistant via the Google Calendar integration.

I also created three Boolean helpers: holiday, visitor and party.

In the Home Assistant calendar, I enter all-day appointments, which are also called holiday, visitor or party.

Every morning at 4 a.m., an automation runs that checks this calendar to see if there are any entries with the above names. If so, the Boolean helpers are switched on. Every night at 3 a.m., an automation runs that resets these values.

Troubleshooting

During testing, I noticed that the helpers are set one day too early. This seems to have something to do with how all-day calendar entries are saved. To counteract this, I specified in the automation that the calendar entry should have a duration of at least one hour.

The code for the automation looks like this:

alias: "Switch: HA Calendar"
description: ""
triggers:
  - trigger: time
    at: "04:00:00"
conditions: []
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: calendar.ha_calendar
            attribute: message
            state:
              - Holiday
            for:
              hours: 1
              minutes: 0
              seconds: 0
        sequence:
          - action: input_boolean.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.holiday
      - conditions:
          - condition: state
            entity_id: calendar.ha_calendar
            attribute: message
            state:
              - Besuch
            for:
              hours: 1
              minutes: 0
              seconds: 0
        sequence:
          - action: input_boolean.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.visitor_mode
      - conditions:
          - condition: state
            entity_id: calendar.ha_calendar
            attribute: message
            state:
              - Party
            for:
              hours: 1
              minutes: 0
              seconds: 0
        sequence:
          - action: input_boolean.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.party_switch
mode: single

Benefits

This allows me to control the following:

The power socket in the office does not switch on at 7 a.m. when I am on holiday.

The heating does not switch off at 9 p.m. when we are having a party.

When guests stay overnight, the motion detectors continue to function even when we are asleep (see my blog entry on the bed sensor).

Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping