Creating trigger variables

I have this working automation which switches the light on or off, depending on the trigger.
But it is not possible to start it manually. Is there a way to specify a default for trigger.id?
I tried “variables:”, but had no success.

- alias: test_triggerid
  id: test_triggerid
  description: test trigger.id
  trigger:
  - platform: time_pattern
    minutes: /1
    seconds: '0'
    id: 'on'
  - platform: time_pattern
    minutes: /1
    seconds: '30'
    id: 'off'
  action:
  - service: light.turn_{{ trigger.id }}
    target:
      entity_id: light.osram_lightify_indoor_flex_rgbw_00adee9a_3
  mode: single

- alias: test_triggerid
  id: test_triggerid
  description: test trigger.id
  trigger:
  - platform: time_pattern
    minutes: /1
    seconds: '0'
    id: 'on'
  - platform: time_pattern
    minutes: /1
    seconds: '30'
    id: 'off'
  variables:
    id: "{{ trigger.id if trigger is defined else 'on' }}"
  action:
  - service: light.turn_{{ id }}
    target:
      entity_id: light.osram_lightify_indoor_flex_rgbw_00adee9a_3
  mode: single
1 Like

That’s seems like an unusual combination of Time Pattern Triggers.

  • The first turns on the light every minute.
  • The second turns off the light every 1.5 minutes.

Wouldn’t that combination cause the Time Pattern Triggers to fire simultaneously every 3 minutes?

0----------1----------2----------3----------4----------5----------6----------7
----------------1.5-------------3.0--------------4.5-------------6.0----------
                                 ^                                ^

EDIT

I was wrong about the duration of the second Time Pattern Trigger. It’s not 1.5 minutes but every minute except phase-shifted by 30 seconds with respect to the first Time Pattern Trigger.

the trigger runs every minute, “on” on second 0 and “off” on second 30

1 Like

You’re right; I was wrong about the duration of the off cycle. The two Time Pattern Triggers are simply phase-shifted by 30 seconds.

If you’re interested, this does the same thing (on for 30 seconds, off for 30 seconds; tested and confirmed to work like your original version) and can be executed manually.

- alias: test_triggerid
  id: test_triggerid
  description: test trigger.id
  trigger:
  - platform: time_pattern
    seconds: '/30'
  action:
  - service: light.turn_toggle
    target:
      entity_id: light.osram_lightify_indoor_flex_rgbw_00adee9a_3
  mode: single
1 Like