Automation based on calendar offset_reached is not triggering

Hello, I set up a simple automation to turn on my heater based on google calendar events identifying my workouts. In the description of such events, I include !!-01:00 in order to activate the offset_reached attribute 1 hour in advance. This works, the event gets updated in Home Assistant and the attribute offset_reached is correctly changed to true an hour befor the actual start of the calendar entry.
Now, I set up the following automation:

alias: Heater on from Google Calendar
description: ''
trigger:
  - platform: state
    entity_id: calendar.heater_on
condition:
  - condition: state
    entity_id: calendar.heater_on
    state: 'on'
    attribute: offset_reached
action:
  - device_id: XXXXXX
    domain: switch
    entity_id: switch.shelly_shsw_pm_YYYYYY
    type: turn_on
mode: single

This automation doesnā€™t get triggered, i canā€™t understand why and how to correct.
Wasnā€™t working on 0.117 and still not working on 0.118.5.
Any clue?

Thanks!

1 Like

Hi,

unfortunately I cannot really support you - besides Iā€™m struggling with the same type of issue ā€¦ and Iā€™m lost too although reading that much docu, discord, reddit :woozy_face:

Can you maybe post the config of your ā€œheater_onā€ calendar so I can compare my settings at least.

Regards

Michael

Yeah the calendar configuration is:

- cal_id: [email protected]
  entities:
  - device_id: heater_on
    ignore_availability: true
    name: Accensione Scaldabagno
    track: true
    search: "#scaldabagno"
    offset: "!!"

As I mentioned, the corresponding entity in HA gets updated correctly, and so is the attribute offset_reached . I really canā€™t understand whatā€™s wrong with the automation.

Found a solution (or better, a workaround) to make the thing work.
I set up a template bynary sensor like this:

binary_sensor:
  - platform: template
    sensors: 
      heater_on_offset_reached:
        friendly_name: "Reached offset for switching heater on"
        value_template: "{{ is_state_attr('calendar.heater_on', 'offset_reached', true) }}"

Now the trigger for the automation is the following, without conditions:

trigger:
  - platform: state
    entity_id: binary_sensor.heater_on_offset_reached
    to: 'on'

Not ideal, but works

2 Likes

Cool - thank you for sharing :+1:

Thanks! Iā€™ve spend so much time trying to get this to work and use your sensor and it works perfectly. I donā€™t understand why triggering based on the attribute doesnā€™t work in automation though!

EDIT:
I added in an or so the state will also trigger the binary_sensor. This way if thereā€™s no offset it will still work.

- platform: template
  sensors:
    calendar_gia_offset_reached:
      value_template: >-
        {{ is_state_attr('calendar.gia_school', 'offset_reached', true)
          or is_state('calendar.gia_school', 'on') }}

It works with true instead of ā€˜onā€™ for the state value.

condition:
  - condition: state
    entity_id: calendar.heater_on
    state: true
    attribute: offset_reached

I have done exactly as above suggested and my Automation is not triggering. I can confirm via developer tools that the binary sensor is properly being updated, however the automation trigger seems to be ignoring the status update. I also tried using direct trigger using the attribute ā€œoff-setā€ and as seen by everyone posting, that didnā€™t trigger.

google_calendar.yaml

- cal_id: [email protected]
  entities:
  - device_id: ashak4031_gmail_com
    ignore_availability: true
    name: [email protected]
    track: true
    offset: "!!"

configuration.yaml (relevant section)

binary_sensor:
  - platform: template
    sensors: 
      calendar_ashak_offset_reached:
        value_template: "{{ is_state_attr('calendar.ashak4031_gmail_com', 'offset_reached', true) }}"

automation.yaml (relevant section)

- id: '10'
  alias: Broadcast Meeting
  description: ''
  trigger:
  - platform: state
    to: 'on'
    entity_id: binary_sensor.reached_offset_for_ashak_calendar
  condition: []
  action:
  - service: media_player.volume_set
    target:
      entity_id: media_player.master_bedroom_speaker
    data:
      volume_level: 0.60
  - service: rest_command.assistant_relay
    data:
      message: broadcast to family room Your meeting {{ state_attr("calendar.ashak4031_gmail_com","message")
        }} is starting {{ state_attr("calendar.ashak4031_gmail_com","start_time") }}