Looking for Help: Automating Heating Control Based on Google Calendar Events

I’m looking for someone who can help me with an automation project. Specifically, I want to automate my heating control based on calendar entries. I already have a connection to Google Calendar.

The logic should work as follows:

  • If there is an all-day event in Google Calendar, the heating should remain on the standard profile.
  • If there is no all-day event, the heating should switch to an alternative profile 10 hours after the last all-day event.

I’ve already tried quite a few things, but it’s not working exactly as I want it to. I’d be really happy if someone from the community would be willing to take a look at my automation remotely and give me some tips on how to improve it.

I’m also willing to compensate for the help because it’s important to me that this automation runs smoothly.

Thanks in advance to anyone out there who considers themselves a specialist in automations related to calendar events!

Just post the automation here. Open the automation and click on the three dots, go to yaml-mode and copy it here.

Just remember to post it in a code block </>

alias: Mitte Alternativprofil 2
description: ""
triggers:
  - trigger: state
    entity_id:
      - calendar.bergdohle_mitte
    attribute: all_day
    from: "true"
    to: "false"
conditions: []
actions:
  - delay:
      hours: 10
      minutes: 0
      seconds: 0
  - device_id: 775ee32b051c6a9465294013e746b775
    domain: climate
    entity_id: 7e87995032ae011081e2627dfa4bfdcc
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: 5151e1a9b90e874235f1783720046f32
    domain: climate
    entity_id: cb30400cf6d4458fedc388bba4ce392b
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: e4d7b7997487cac2a9cc97b729996972
    domain: climate
    entity_id: c364e54e25ccfea5c3f429ecc63449d1
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: 7ae08e56e1acc7140fc167422c5d67ed
    domain: climate
    entity_id: 856c1345ce8f23f5a180459a3ef23478
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: 6e1b036f8a80aa6932dde908c3524a1a
    domain: climate
    entity_id: e40c22529deb1f2f24f3bbd022e68ba4
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: 2c02664258f773045d3083ecafcfe228
    domain: climate
    entity_id: 34f5f3251a03f8557b35cc4a5c20982b
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: ffe9bf7987e50e1c63fcadcafd5fc4c2
    domain: climate
    entity_id: 5e1a3ef56666b5e81fd168a105bf01f6
    type: set_preset_mode
    preset_mode: Alternative 2
mode: single

I think you need to remove the quotes.
In attributes the values are as they should, only in state is if forced to string.

Thank you. I’ll try this.

Keep in mind a 10 hour delay can easily be stopped by reloading automation or restarting HA

Maybe you have a better solution. This is how I currently do it: I rent out vacation apartments and have a separate Google Calendar for each apartment. When I have guests in an apartment for a week, for example, it is marked as an all-day event. This means the guest’s name appears on each day they are staying in the apartment.

Now, when the guest checks out and there is no new booking on the following day (the check-out day), I want the heating to switch to an alternative energy-saving profile at around 10 AM—roughly the time the guest leaves.

However, if a new guest is arriving on the same day, meaning the all-day event ends at midnight and a new all-day event begins for the next guest, then the heating should not change and should remain on the standard profile.

I want to avoid a situation where the heating switches to the energy-saving mode at midnight when the all-day event ends. Instead, I want it to change only around the check-out time (10 AM) and only if there is no new all-day event.

I hope you understand what I am trying to achieve. Maybe you have an alternative idea for how I can implement this.

I should also add that I have a second automation that activates 12 hours before the start of an all-day event. This means that the heating switches to the standard profile 12 hours before a booking appears in the calendar.

this is to activate the sdandard profile

alias: Mitte Standardprofil
description: ""
triggers:
  - trigger: calendar
    entity_id: calendar.bergdohle_mitte
    event: start
    offset: "-12:0:0"
conditions: []
actions:
  - device_id: 775ee32b051c6a9465294013e746b775
    domain: climate
    entity_id: 7e87995032ae011081e2627dfa4bfdcc
    type: set_preset_mode
    preset_mode: Default
  - device_id: 5151e1a9b90e874235f1783720046f32
    domain: climate
    entity_id: cb30400cf6d4458fedc388bba4ce392b
    type: set_preset_mode
    preset_mode: Default
  - device_id: e4d7b7997487cac2a9cc97b729996972
    domain: climate
    entity_id: c364e54e25ccfea5c3f429ecc63449d1
    type: set_preset_mode
    preset_mode: Default
  - device_id: 7ae08e56e1acc7140fc167422c5d67ed
    domain: climate
    entity_id: 856c1345ce8f23f5a180459a3ef23478
    type: set_preset_mode
    preset_mode: Default
  - device_id: 6e1b036f8a80aa6932dde908c3524a1a
    domain: climate
    entity_id: e40c22529deb1f2f24f3bbd022e68ba4
    type: set_preset_mode
    preset_mode: Default
  - device_id: 2c02664258f773045d3083ecafcfe228
    domain: climate
    entity_id: 34f5f3251a03f8557b35cc4a5c20982b
    type: set_preset_mode
    preset_mode: Default
  - device_id: ffe9bf7987e50e1c63fcadcafd5fc4c2
    domain: climate
    entity_id: 5e1a3ef56666b5e81fd168a105bf01f6
    type: set_preset_mode
    preset_mode: Default
mode: single

And this to activate the energy saving profile, 10h after the all day event is finisehd and if no new all day event is there

alias: Mitte Alternativprofil 2
description: ""
triggers:
  - trigger: state
    entity_id:
      - calendar.bergdohle_mitte
    attribute: all_day
    from: true
    to: false
conditions: []
actions:
  - delay:
      hours: 10
      minutes: 0
      seconds: 0
  - device_id: 775ee32b051c6a9465294013e746b775
    domain: climate
    entity_id: 7e87995032ae011081e2627dfa4bfdcc
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: 5151e1a9b90e874235f1783720046f32
    domain: climate
    entity_id: cb30400cf6d4458fedc388bba4ce392b
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: e4d7b7997487cac2a9cc97b729996972
    domain: climate
    entity_id: c364e54e25ccfea5c3f429ecc63449d1
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: 7ae08e56e1acc7140fc167422c5d67ed
    domain: climate
    entity_id: 856c1345ce8f23f5a180459a3ef23478
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: 6e1b036f8a80aa6932dde908c3524a1a
    domain: climate
    entity_id: e40c22529deb1f2f24f3bbd022e68ba4
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: 2c02664258f773045d3083ecafcfe228
    domain: climate
    entity_id: 34f5f3251a03f8557b35cc4a5c20982b
    type: set_preset_mode
    preset_mode: Alternative 2
  - device_id: ffe9bf7987e50e1c63fcadcafd5fc4c2
    domain: climate
    entity_id: 5e1a3ef56666b5e81fd168a105bf01f6
    type: set_preset_mode
    preset_mode: Alternative 2
mode: single

would be great if you or anybody could help me to get this done in the best ever way. thank you

I believe a better solution than the delay is to set a datetime helper with the time.
That way you can trigger on this time and there is no delays.

triggers:
  - trigger: state
    entity_id:
      - calendar.bergdohle_mitte
    attribute: all_day
    from: true
    to: false
    id: set_time
    
  - trigger: time
    at: input_datetime.switch_off
    id: switch_off
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: set_time
        sequence:
          - action: input_datetime.set_datetime
            metadata: {}
            data:
              timestamp: "{{ (now().timestamp() + 11*3600) }}"
            target:
              entity_id: input_datetime.switch_off

      - conditions:
          - condition: trigger
            id: switch_off
        sequence:
          - device_id: 775ee32b051c6a9465294013e746b775
            domain: climate
            entity_id: 7e87995032ae011081e2627dfa4bfdcc
            type: set_preset_mode
            preset_mode: Alternative 2

I would also change the device actions to climate actions on the entities.
Device triggers and actions should be avoided if you can since they are bound to the device. If you replace it then the automation is not as easily changed to get it working again.

thank you - but now I’m at the end of my rope and don’t understand anything anymore with my layman knowledge :-(. Would you be willing to check and set it up via remote desktop?

What part is it that is the issue? Device → entity trigger?
Here is what the yaml looks like:

Climate - Home Assistant

When you add an action type climate and click here:

Then click entity:


And choose the entity name you gave the climate device.
In preset mode you type “Alternative 2”

so i wonder if this will work:)

alias: Mitte Alternativprofil 2 (neu)
description: ""
triggers:
  - trigger: state
    entity_id:
      - calendar.bergdohle_mitte
    attribute: all_day
    from: true
    to: false
    id: set_time
  - trigger: time
    at: input_datetime.switch_off
    id: switch_off
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: set_time
        sequence:
          - action: input_datetime.set_datetime
            metadata: {}
            data:
              timestamp: "{{ (now().timestamp() + 11*3600) }}"
            target:
              entity_id: input_datetime.switch_off
      - conditions:
          - condition: trigger
            id: switch_off
        sequence:
          - action: climate.set_preset_mode
            metadata: {}
            data:
              preset_mode: Alternative 2
            target:
              entity_id: climate.1_wohnzimmer
mode: single

Can I also group devices? For example, can I group all radiators in Apartment A together?

No you can’t group climate entities.
But the code looks good.
What you could do is to loop through a list of them like this:

      - conditions:
          - condition: trigger
            id: switch_off
        sequence:
          - repeat:
              for_each:
                - climate.1_wohnzimmer
                - climate.1_schlafzimmer
                - climate.2_schlafzimmer
              sequence:
                - action: climate.set_preset_mode
                  metadata: {}
                  data:
                    preset_mode: Alternative 2
                  target:
                    entity_id: "{{ repeat.item }}"

thank you again. so I set this up and will check when we have next changings in guest stay.