#How to use trigger_variables with a calendar trigger

1 messages · Page 1 of 1 (latest)

gentle narwhal
#

I'm trying to build a couple of automations that need to be able to trigger on user defined pre and post offsets to a calendar event.

Unfortunately everytime I try to use trigger_variables with the calendar trigger type I get format errors for the offset definition like:

offset {{ pre_offset }} should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['offset']. Got None

I've tried the following form of the blueprint setup. NOTE I've validated that the formating string I'm creating works correctly in the dev tools template editor

blueprint:
  name: Testing
  domain: automation

  input:
    test_calendar:
      name: Test Calendar
      selector:
        domain: calendar
    pre_offset:
      name: Pre-event offset
      default: 0
      selector:
        number:
          min: 0
          max: 30
          unit_of_measurement: hours
    post_offset:
      name: Post-event offset
      default: 0
      selector:
        number:
          min: 0
          max: 30
          unit_of_measurement: hours

mode: restart

trigger_variables:
  input_pre_offset: !input pre_offset
  input_post_offset: !input post_offset
  pre_offset: "-{{ '{:02d}'.format(input_pre_trip_offset) }}:00:00"
  post_offset: "{{ '{:02d}'.format(input_post_trip_offset) }}:00:00"

triggers:
  - trigger: calendar
    entity_id: !input test_calendar
    event: start
    offset: "{{ pre_offset }}"
    id: pre_event
  - trigger: calendar
    entity_id: !input test_calendar
    event: end
    offset: "{{ post_offset }}"
    id: post_event

If I have to use a template trigger, then how would I go about this? I'm not certain how I would create the appropriate template trigger to trigger on a calendar event with offsets without using the calendar trigger type itself.

austere pagoda
#

AFAIK, the Calendar trigger does not accept templates, so you will need to use inputs. Your options are to use Trigger Selector inputs to build out the trigger or you could use Text selector inputs to provide the "-1:0:0".

...
    pre_offset:
      name: Pre-event offset (-H:M:S)
      default: "-0:0:0"
    post_offset:
      name: Post-event offset (H:M:S)
      default: "0:0:0"
...

triggers:
  - trigger: calendar
    entity_id: !input test_calendar
    event: start
    offset: !input pre_offset
    id: pre_event
  - trigger: calendar
    entity_id: !input test_calendar
    event: end
    offset: !input post_offset
    id: post_event
....
gentle narwhal
#

Well it passes validation, but the triggers don't seem to be properly working. I'm going to do some testing with some hard-coded automations and see if there's just something funky with the offsets that I'm not understanding.

austere pagoda
#

Your calendar entity selector is missing some parts.

blueprint:
  name: Testing Calendar Trigger inputs
  domain: automation

  input:
    test_calendar:
      name: Test Calendar
      selector:
        entity:
          multiple: false
          filter:
            - domain: calendar
    pre_offset:
      name: Pre-event offset (-H:M:S)
      default: "-0:0:0"
    post_offset:
      name: Post-event offset (H:M:S)
      default: "0:0:0"

mode: restart
triggers:
  - trigger: calendar
    entity_id: !input test_calendar
    event: start
    offset: !input pre_offset
    id: pre_event
  - trigger: calendar
    entity_id: !input test_calendar
    event: end
    offset: !input post_offset
    id: post_event
conditions: []
actions:
....

I've tested the config above and it is working. If you continue to experience issues, it may be due to the 15 minute rule for calendar events.

https://community.home-assistant.io/t/wth-when-testing-make-sure-you-do-not-plan-events-less-than-15-minutes-away-from-the-current-time-or-your-trigger-might-not-fire/812703/7

https://community.home-assistant.io/t/is-there-any-life-hack-for-using-calendar-for-events-less-than-15-minutes-in-the-future/898619/2

grand tree
austere pagoda
grand tree
#

Hmm right

#

Good point

gentle narwhal
#

I'm verifying that right now. The input does go red when I put a negative number in one of the spots, but it allows me to save it. I've currently removed all use of the pre/post values so that I can work on the rest of my logic but I'm going to output what I get in my debugging to see what it does.

austere pagoda
#

Apologies @grand tree... I just tested it to make sure. It does seem to work, but as @gentle narwhal said the input box shows red as if it's an inappropriate input.

austere pagoda