Calendar Switch Y2: switch any device with a calendar

Inteoduction

The Calendar Switch Y2 blueprint turns one or more devices on and and off according to events in a calendar. I use it for a hot water system (controlled by a zone valve connected to a smart switch), and an immersion heater with a smart switch, but the blueprint will operate any device in the domain switch.

Calendar switch Y2 can stand alone or be used as part of the suite that includes Heating X2: Schedule thermostat by calendar, and Zone Switch Z2: operate a heating zone valve from a heat demand sensor

The required helpers, timers, templates, automations etc. can be created by hand, or with the assistance of the Heating XYZ Code Generator.

Features

  • Schedule by calendar: switch one or more devices on and and off according to events in a calendar
  • Multiple devices: Two or more devices are synchronised together, i.e. turning one on turns them all on, turning one off turns them all off
  • Manual override: if a device is switched manually on its smart switch, from a dashboard or by voice assistant remains, the new setting stays in effect for a defined period (default 2 hours)
  • Away mode: turns the device(s) off when there is no one at home
  • Notifications: if devices do not respond to a new setting, go offline, or come back online
  • Logging: optional recording of key events from the switching automations into a log file
  • Robust: Graceful degradation when a device is offline
  • Battery-efficient: conserves device battery life (where applicable) by only transmitting real changes

Ancestry

Calendar Switch Y2 is essentially a stripped down version of Heating X2, which controls thermostats from calendars.

Installation

Get the Calendar Switch Y2 Blueprint


Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Or use this link to copy the code manually from GitHub.


Switched devices

Calendar Switch Y2-based automations can control anything with domain ‘switch’. One or more may be listed in the same automation.

Calendars

Calendar Switch Y2 uses any Calendar to program the device(s). Typically you would create a calendar using the Home Assistant Local Calendar integration (you need Home Assistant 2022.12.1 or later). The blueprint should also work with any external calendar linked to Home Assistant that has domain calendar.

Add an Event to the calendar for each period that you want to turn the device(s) on.

  • In the Summary field put the title of the event as you want it to appear on the dashboard in the reason text. I recommend including the device name as an aid to picking up errors.

  • In the Description field add descriptive text – optional, not used by the automation.

  • Set the Event start and end times as usual. Consecutive and overlapping events are allowed, though since all events mean “on”, the only change is the name on the dashboard.

  • Set the events to Repeat daily or on specific days of the week as required.

Helpers and Timers

The blueprint requires a number of helpers and timers, which are used as global variables. Create the helpers in the UI or with YAML for each automation (device or group of devices) that you are going to create with the blueprint.

Input Text

  • Setting reason – into which the automation writes the reason for the current setting for display on dashboards. Make the length 255 characters.

Input_booleans

  • Manual state – into which the automation writes the state (on or off) specified by manual override.

  • Required state – into which the automation writes the state (on or off) currently set for the device (to optimise radio traffic and check response)

Timers

  • Manual override timer – which the automation uses for the time remaining for a manual intervention before it reverts to the calendar schedule

  • Echoblock timer – which the automation uses to time the response from the device(s) before checking its setting, and to distinguish manual changes to the set state from those made by the automation.

Logging

Logging is optional, so skip this step if you do not want it. The default blank in the blueprint logging service name indicates that no logging is required.

To enable logging

  1. If you want to keep your log fles in a folder, then add the folder to /CONFIG/ – in my example it is called log_files.
  2. In configuration.yaml add an entry for each automation like this
      notify:
        - name: immersion_heater_log 
          platform: file
          filename: log_files/immersion_heater_log.txt
          timestamp: true 
  1. Specify the service name (not the file name), exactly as defined, in the blueprint parameters (below). In my example the name is immersion_heater_log

The Automations

Create one automation for each device, or group of devices that are controlled by one calendar, using the UI. Select the Blueprint Calendar Switch Y2 and specify in the inputs the devices, calendar, helpers and timers described above, plus …

  • Logging service name – if logging is enabled, enter the logging service name exactly as specified in the configuration.yaml file. Do not include a notify. prefix. Leave blank if no logging is required.

  • Manual override period – the time period for which a manual intervention (on or off) will override the schedule. Default 2 hours.

Starter Dashboard

My recommended starter dashboard has a card for each device (or device group). Construct it as a vertical stack with the name of the device as its title, the device switch as a button sub-card, the reason text as a markdown sub-card (because the text is too long for a regular text entity) and the manual override timer in an entities sub-card (so that it can be reset).

While testing, you might like to add some more of the helper and timer entities to the dashboard cards, so that you can better see what is going on. Adding timers allows them to be cancelled from the dashboard as well.

More details

The guide “Smart Heat Your Home with Heating XYZ”, with hardware and software configuration tips and detailed instructions for using the code generator, is bundled with the Code Generator download.

Good Luck!

:+1:

Minor updates (for robustness)

  • 05-Mar-2024: 1.0.01 Added detail to the trigger line of the log entries
  • 08-Mar-2024: 1.0.02 Corrected the trigger line of the log entries when triggers have no entity_id (e.g. calendars)
  • 08-Mar-2024: 1.0.03 Tidied up logic of ACTION[6] using choose, to ensure there is always a log message
  • 08-Mar-2024: 1.0.04 Improved notifications. Additional unknown and unavailable checks every time a setting is needed. Notification automatically dismissed when device comes back online (instead of a new notification). Only ever one notification per device.
  • 13-Mar-2024: 1.0.05 Added ‘continue_on_error’ and ‘parallel’ to device service call, ‘continue_on_error’ to logs and notifications, because failure her should not stop the main device switching function