Getting started with Calendar Automation

Hello,
I’m just getting started with the local calendar add in and automation. I recently installed a number of smart TRVs and want to create a schedule to heat rooms in a predictable manner.

For example the bedroom should heat from 05:30 to 06:00
The office from 09:30 to 17:00
The kitchen a couple of different times and so on.

I installed the local calendar and tried to set up automations, but hit a couple of snags.

Also, some of my rooms have apostrophes in their names - Steve’s Office and Jacquie‘s Office are problematic.

I’ll start with a head’s up. The apostrophe / single quote above are different characters - I have a mixture of UK and Swiss keyboards and typing is not consistent between them. I am correcting the ‘ to ’ when I come across it. The associated entity names are also created differently steve_s_office or steves_office will be generated depending on the keyboard used - I’m adjusting these too.

Local calendar has a heating calendar and each event has the subject of the room name. I want to turn up and turn down the heating according to the schedule start and end and to use a numeric helper to set the temperatures.

alias: Steve’s Office Heating
description: ""
trigger:
  - platform: calendar
    event: start
    entity_id: calendar.heating
  - platform: calendar
    event: end
    entity_id: calendar.heating
condition:
  - condition: template
    value_template: "{{ trigger.calendar_event.summary == 'Steve\\'s Office' }}"
action:
  - if:
      - "{{ trigger.event == 'start' }}"
    then:
      - service: climate.set_temperature
        target:
          entity_id: climate.steves_office_heating_thermostat
        data:
          temperature: input_number.steves_office_heating_comfort
    else:
      - service: climate.set_temperature
        target:
          entity_id: climate.steves_office_heating_thermostat
        data:
          temperature: input_number.steves_office_heating_cool
mode: queued

In this case, the trigger condition is never matched - I can’t figure out the escape characters needed for the {{ mustache template string.

In this second config, for the kitchen this time, the YAML is corrupted on save:

alias: Kitchen Heating
description: ""
trigger:
  - platform: calendar
    event: start
    entity_id: calendar.heating
  - platform: calendar
    event: end
    entity_id: calendar.heating
condition:
  - condition: template
    value_template: "{{ trigger.calendar_event.summary == 'Kitchen' }}"
action:
  - if:
      - "{{ trigger.event == 'start' }}"
    then:
      - service: climate.set_temperature
        target:
          entity_id: climate.kitchen_heating_thermostat
        data:
          temperature:
            "[object Object]": null
    else:
      - service: climate.set_temperature
        target:
          entity_id: climate.kitchen_heating_thermostat
        data:
          temperature:
            "[object Object]": null
mode: queued

I tried to code {{ input_number.kitchen_heating_comfort }} but that does not work and temperature value is rendered as [object Object].

How to code the moustache template to read the float value from the number helper?

Steve

Hi @stevegroom

This doesn’t really answer your question but, have you looked at the Schedule helper? This is easier to work with than calendars. It may be just what you need.

alias: Steve’s Office Heating
description: ""
trigger:
  - id: input_number.steves_office_heating_comfort
    platform: calendar
    event: start
    entity_id: calendar.heating
  - id: input_number.steves_office_heating_cool
    platform: calendar
    event: end
    entity_id: calendar.heating
condition:
  - condition: template
    value_template: "{{ 'Steve' in trigger.calendar_event.summary }}"
action:
  - service: climate.set_temperature
     target:
       entity_id: climate.steves_office_heating_thermostat
     data:
       temperature: '{{ states(trigger.id) }}'
mode: queued
alias: Kitchen Heating
description: ""
trigger:
  - id: input_number.kitchen_heating_comfort
    platform: calendar
    event: start
    entity_id: calendar.heating
  - id: input_number.kitchen_heating_cool
    platform: calendar
    event: end
    entity_id: calendar.heating
condition:
  - condition: template
    value_template: "{{ trigger.calendar_event.summary == 'Kitchen' }}"
action:
  - service: climate.set_temperature
     target:
       entity_id: climate.kitchen_heating_thermostat
     data:
       temperature: '{{ states(trigger.id) }}'
mode: queued

Thank you @123 ,
the in filter solves this immediate problem
“{{ ‘Steve’ in trigger.calendar_event.summary }}”

I’m still curious to know how to escape special chars though.

For the second I see how you added id into each trigger and refer to that in the temperature: later on - the temperature is a float - are the quotes around ‘{{ states(trigger.id) }}’ required ?

regards
Steve

All templates that start on the same line as the option must be wrapped in quotes.

Reference

Important template rules

Stopped because an error was encountered at 29 September 2023 at 18:00:00 (runtime: 0.02 seconds)
expected float for dictionary value @ data['temperature']

The helper input_number.living_room_heating_target_comfort is defined with a step size of 0.1

How are you testing the automation I posted above?

It can only be tested by the Calendar Trigger actually triggering when the Calendar event occurs. If you attempt to test it another way, trigger.id will be undefined and this template will not produce a float value: {{ states(trigger.id) }}

I waited for the next calendar event.

Post your automation and the trace file produced when it failed.

Hi,
I searched for states(trigger.id) in the docs and found the trigger page. There I saw an example with a pipe to change the format. The automation is now working after adding |float

alias: Kitchen Heating
description: ""
trigger:
  - id: input_number.kitchen_heating_target_comfort
    platform: calendar
    event: start
    entity_id: calendar.heating
  - id: input_number.kitchen_heating_target_cool
    platform: calendar
    event: end
    entity_id: calendar.heating
condition:
  - condition: template
    value_template: "{{ trigger.calendar_event.summary == 'Kitchen' }}"
action:
  - if:
      - "{{ trigger.event == 'start' }}"
    then:
      - service: climate.set_temperature
        target:
          entity_id: climate.kitchen_heating_thermostat
        data:
          temperature: "{{ states(trigger.id)|float }}"
    else:
      - service: climate.set_temperature
        target:
          entity_id: climate.kitchen_heating_thermostat
        data:
          temperature: "{{ states(trigger.id)|float }}"
mode: queued

I now how have one script per room that has a smart TRV that sets the target temperature according to a calendar schedule. Thanks for the help.

It doesn’t need a float because Home Assistant’s uses native typing to detect the value’s type (string, float, int, boolean, list, etc) based on its appearance. So if a template’s result looks like a number, native typing will handle it as a number.

The if - then - else you added is redundant and unnecessary. The single service call in my example is all that’s needed.