Google Calendar event offset

Would be very nice if one could configure switches to turn on using an offset that’s not dependent on the event name including !!offset. I.e. something like switch_event_offset: -1h
Would be great for automation one wants initiated an hour before work for example.

I’ve been trying to achieve this with a template trigger, but no luck. Theoretically, you should be able to do a time-compare with the start or end time.

An offset for all calendar events would indeed be useful.

My use case is, that I want to control my light differently the day before a national holiday (typically turn off later, as I go to bed later, when the next day is a holiday, where I don’t need to get up early).
I have a shared google calendar with the holidays, but as I can’t change it, I can’t add the offset.

Another example where this may be useful it to cope with calendars in different timezones.

Also trying to achieve this, anyone figured this out yet?

Was going post this feature request when I stumbled upon this, has anyone found a solution?

The event name offset doesn’t seem to fully work anyway as it doesn’t seem to go over 2 digits (maximum 99 minutes I suppose).

There does seem to be quite a convoluted solution posted here: Help me wrap my head around Google Calendar
However, this could be made so much simpler with some kind of offset parameter for the calendar device.

The thread I linked to wasn’t as convoluted as I first thought (sorry), but I’ll explain how I got this working.

The idea of @ih8gates is to use a template sensor and compare the current time to the offset (without using the event naming)

Set up a date_time sensor (which will probably get entity_id of sensor.date__time) to trigger our sensor every minute:

- platform: time_date
  display_options:
    - 'date_time'

Then we can reference that entity_id to make sure the sensor updates. I also referenced the relevant calendar as an extra update:

- platform: template
  sensors:
    my_event_offset:
      friendly_name: "My Event offset"
      entity_id:
        - calendar.myevents
        - sensor.date__time
      value_template: >
        {% if as_timestamp(states.calendar.myevents.attributes.start_time) - as_timestamp(now()) < 21600  %}on{% else %}off{% endif %}

The value 21600 is chosen here as 6 hours (6 * 60 * 60).

Edit: Apparently the entity_id in a template sensor shouldn’t be used anymore. I’m not sure what to replace this with as it works for now.

Edit 2: I sorted how to work around the entity_id issue. The sensor template should look like below:

- platform: template
  sensors:
    my_event_offset:
      friendly_name: "My Event offset"
      value_template: >
        {% if as_timestamp(states.calendar.myevents.attributes.start_time) - as_timestamp( strptime(states.sensor.date__time.state, "%Y-%m-%d, %H:%M" ) ) < 21600  %}on{% else %}off{% endif %}

Since sensor.date__time changes each minute, so too should this offset detector.

5 Likes

Thanks @Kallb123 !

I’ve been thinking of doing this for quite some time now, but this was the first post that made it easy enough… :wink:

Finally being reminded BEFORE the garbage collector arrives!
/Johan

No problem, glad my post could help!

I also set up an automation so that when I arrive home (mobile joins WiFi), I get an extra notification if the calendar offset is met. That’s because if I’m not home, I may dismiss the notification and them forget. But then when I arrive home in the evening it’ll remind me again!

1 Like

It would simply be nice if the existing Google Calendar component could have the offset parameter adjusted to accept 3 digits so that it could be used to have an offset of hours rather than just a max of 99 minutes.

I would like to have a “default_offset” parameter in google_calendar.yaml that would cause the offset to be whatever I set if it is not set in the name of the event, so we could change it on the calendar level.

Modifying the event names to suit automation shouldn’t even be a thing. It’s really too bad that it couldn’t read the notifications out of the calendar itself, and have that be an option as well.

1 Like

Hi!

Worked beautifully until a few days ago… my current problem

Do you still use these? Works for you?

/Johan

my work around was create a calendar in side the calendar

image

must have the Google calendar plugin going

and MUST have #Gas-on or #Gas-off in message

- id: Google Calendar Gas on
  alias: Google Calendar gas on
  trigger:  # this turn on at the time in the calendar
    - platform: state
      entity_id: calendar.gas_heater
      to: 'on'
  condition:
    - condition: template # lookfor the #Gas in the message if there its True (pass go)
      value_template: >-  
        {% set lookfor = "#Gas" %}
        {% if state_attr('calendar.gas_heater','message').split('-')[0] == lookfor %}True{% else %}False{% endif %}
  action:
    - data:
        entity_id: input_boolean.livingroom_climate  
       # as we are here just need to read the bit after the - and do it
      service_template: input_boolean.turn_{{ state_attr('calendar.gas_heater','message').split('-')[1] }}

so the rules are

MUST turn ON MUST HAVE #Gas in the message MUST HAVE - and on or off after the -