Automation.trigger with a trigger ID?

I’ve got automations which use trigger IDs and then choose and triggered by, so that multiple triggers selectively run bits of the automations.

Is there any way to trigger one automation from another, passing the ID?

To give an example and some context, I have an automation that turns various things on/off when I feed the fish in my aquarium.
It’s initially triggered by the time (with one ID), and as long as I’m at home, sends a notification to my phone and gives me options to feed or dismiss (with other IDs).

If I’m out at the usual trigger time though, I’d like my ‘get home’ automation to trigger the feeding automation with the ID that sends me the notification.

I’m aware it might make sense to split things out into scripts, but that’d mean re-thinking some (complex, at least for me) automations and isn’t what I’m hoping to do.

Thanks

Fire a custom event from the first automation and add an Event trigger to the second.

Or, set the actions of the second automation up as a Script then have both automations call the script, passing the necessary data in a variable.

You can’t overwrite the trigger variable, so you may need to make some modifications to the automation. But, different triggers can share the same ID, so it may only be a very small change… you’ll need to share the automations if you need more specific guidance.

2 Likes

A custom event sounds promising. Thanks.

I haven’t been lucky having a quick play, so I guess I’ve got some reading to do :smiling_face:

edit:
I would have shared an example automation, but tbh they’re getting a bit big so I thought it’d just complicate things. Thanks for not taking the ‘yaml or it’s impossible to help’ approach.

and now I’ve less reading since you kindly added links :wink:

Also check out actionable notifications in the companion app’s docs. You can pass custom payloads. It relates to D’s suggestion of events, and this mechanism uses events.

1 Like

Thanks. I’m already using those in a few automations, including the one I have for feeding my fish. Theyre dead useful.

I should have realised its all the same thing, but have only just ‘twigged’ when you said it and now I’ve gone back and compared the various bits.

Pretty sure I’ve got it doing what I want. When I manually run the action that creates the event, the corresponding trigger fires. I’m yet to use it while actually out and then getting home, that’ll be the proper test.

If I’m out while my washing finishes, the fish need feeding, or past my usual bedtime, all of those automations should give me a prod as I get back home (and then remind be every 30 mins until I do or dismiss them) :crossed_fingers:

It feels like I’m missing something though, as I couldn’t get the trigger to fire when using any event data. It does when I only set a unique event type.

Should setting only a unique event type be OK, or is it likely to cause trouble somehow?
There isnt anything set other then type in the example here, so I’m probably over-thinking it just because the field’s there.

Current action:

event: Ask fish feeding
event_data: {}

Current trigger:

trigger: event
event_type: Ask fish feeding
id: time to feed

It’s fine to do it that way, but you should be able to include event data.

For this kind of thing I usually use a more general custom event type, then include a more specific value in the event data. I almost always include the targets’ entity IDs in the event data, so I have a clue where else I may need to look if something isn’t working as expected.

  - event: custom_automation_trigger
    event_data: 
      automation: Ask fish feeding
      target:
        - automation.ask_fish_feeding 
id: time to feed
trigger: event
event_type: custom_automation_trigger
event_data:
  automation: Ask fish feeding

It’s not necessary, but it does make debugging a bit easier if you have one event type to listen for in the Event tool that covers all your custom trigger events.

1 Like

Cracked it before I’d read your last message, then saw you kindly spelled it out.
The effect seems to be the same as the ones above, but these more closely match how the actionable notifications to my mobile work.

Action:

event: custom event
event_data:
  action: Ask fish feeding

Trigger:

trigger: event
event_type: custom event
id: time to feed
event_data:
  action: Ask fish feeding

I notice the different labels we’ve used though, action vs automation. I just copied what I had in my actionable notifications.
Are we free to use whatever unique label makes sense, as long as the action and trigger match?

Yes, you can use whatever names you want for your event data variables.

1 Like

This fish feeding automation’s got 11 triggers and 7 different IDs used in a choose now, for turning pumps, CO2 and heaters on and off. I might have over done it a little :rofl:

In case anyone’s really bored (but I dont recommend it tbh):

automation yaml

alias: Fish feeding
description: 
triggers:
  - trigger: time_pattern
    minutes: /30
    id: asking
  - entity_id:
      - input_boolean.fish_feeding
    to: "on"
    enabled: true
    id: feeding started
    trigger: state
  - at: input_datetime.fish_feeding_time
    id: asking
    trigger: time
    enabled: false
  - event_type: timer.finished
    id: asking
    event_data:
      entity_id: timer.fish_need_feeding
    trigger: event
    enabled: false
  - event_type: mobile_app_notification_action
    event_data:
      action: START_FISHFEEDING
    id: feeding started
    trigger: event
  - entity_id:
      - input_boolean.fish_feeding
    to: "off"
    id: feeding finished
    trigger: state
  - event_type: timer.finished
    id: feeding finished
    event_data:
      entity_id: timer.fish_feeding
    trigger: event
  - event_type: mobile_app_notification_action
    event_data:
      action: DISMISS_ASKING_FISH_FEEDING
    id: dismiss
    trigger: event
  - trigger: event
    event_type: esphome.button_pressed
    event_data:
      message: IR button was pressed
    id: toggle feeding
  - at: "00:00:00"
    id: reset fed today
    trigger: time
  - trigger: state
    entity_id:
      - binary_sensor.fishfeeder_button
    from: "off"
    to: "on"
    id: feeding started
  - trigger: time
    at:
      entity_id: input_datetime.fish_feeding_time
      offset: "00:00:02"
    id: time to feed
  - trigger: event
    event_type: custom event
    id: time to feed
    event_data:
      action: Ask fish feeding
conditions:
  - condition: zone
    entity_id: person.james
    zone: zone.home
    enabled: true
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - time to feed
          - condition: state
            entity_id: input_boolean.fish_fed_today
            state:
              - "off"
          - condition: numeric_state
            entity_id: zone.home
            above: 0
          - condition: time
            before: input_datetime.fish_feeding_time_stop
        sequence:
          - metadata: {}
            data:
              message: Feed the fish now?
              title: It's fish feeding time
              data:
                ttl: 0
                priority: high
                notification_icon: mdi:fish
                tag: FishFeeding
                sticky: "true"
                actions:
                  - action: DISMISS_ASKING_FISH_FEEDING
                    title: Dismiss
                  - action: START_FISHFEEDING
                    title: Feed now
            action: notify.mobile_app_pixel_8
          - metadata: {}
            data:
              message: Feed the fish?
            action: notify.kodi_livingroom_notification
          - action: input_boolean.turn_on
            metadata: {}
            target:
              entity_id: input_boolean.fish_feeding_asking
            data: {}
          - action: script.tts_all
            metadata: {}
            data:
              message: The fish need feeding.
      - conditions:
          - condition: trigger
            id:
              - asking
          - condition: state
            entity_id: input_boolean.fish_fed_today
            state: "off"
          - condition: time
            before: input_datetime.fish_feeding_time_stop
            weekday:
              - sun
              - sat
              - fri
              - thu
              - wed
              - tue
              - mon
          - condition: state
            entity_id: input_boolean.fish_feeding_asking
            state:
              - "on"
        sequence:
          - metadata: {}
            data: {}
            target:
              entity_id: timer.fish_need_feeding
            action: timer.cancel
            enabled: false
          - metadata: {}
            data: {}
            target:
              entity_id: timer.fish_need_feeding
            action: timer.start
            enabled: false
          - metadata: {}
            data:
              message: Feed the fish now?
              title: It's fish feeding time
              data:
                ttl: 0
                priority: high
                notification_icon: mdi:fish
                tag: FishFeeding
                sticky: "true"
                actions:
                  - action: DISMISS_ASKING_FISH_FEEDING
                    title: Dismiss
                  - action: START_FISHFEEDING
                    title: Feed now
            action: notify.mobile_app_pixel_8
          - metadata: {}
            data:
              message: Feed the fish?
            action: notify.kodi_livingroom_notification
          - action: script.tts_all
            metadata: {}
            data:
              message: The fish need feeding.
      - conditions:
          - condition: trigger
            id:
              - feeding started
        sequence:
          - metadata: {}
            data:
              message: clear_notification
              title: FishFeeding
              data:
                ttl: 0
                priority: high
                tag: FishFeeding
            action: notify.mobile_app_pixel_8
          - metadata: {}
            data:
              message: Fish feeding started
            enabled: false
            action: notify.kodi_livingroom_notification
          - action: input_boolean.turn_off
            metadata: {}
            target:
              entity_id: input_boolean.fish_feeding_asking
            data: {}
          - metadata: {}
            data: {}
            target:
              entity_id: timer.fish_need_feeding
            action: timer.cancel
            enabled: false
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - switch.fishpower_large_filter
                - switch.small_filter
          - metadata: {}
            data: {}
            target:
              entity_id: button.fishfeeder_feed
            action: button.press
          - metadata: {}
            data: {}
            target:
              entity_id: input_boolean.fish_feeding
            action: input_boolean.turn_on
          - metadata: {}
            data: {}
            target:
              entity_id: timer.fish_feeding
            action: timer.cancel
          - metadata: {}
            data: {}
            target:
              entity_id: timer.fish_feeding
            action: timer.start
          - metadata: {}
            data: {}
            action: input_boolean.turn_on
            target:
              entity_id: input_boolean.fish_fed_today
          - data:
              title: Fish feeding started
              message: Fish feeding started
            action: script.debug_notification
      - conditions:
          - condition: trigger
            id:
              - feeding finished
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id:
                - switch.fishpower_large_filter
                - switch.small_filter
          - type: turn_on
            device_id: 2d03cbcc76b0b14239a3aab81fdae6ec
            entity_id: d718f1980341144462f865d1878b1c56
            domain: switch
            enabled: false
          - type: turn_on
            device_id: 3b08876dcb66860eadcf7dfb50ed8bc4
            entity_id: 06dcf4b5e757b4d451e68a5cca138e03
            domain: switch
            enabled: false
          - device_id: 2a9a2cbff8cc3947b770773c0c9c4e85
            domain: climate
            entity_id: 5bb538f6df9f5339c0e50800e03e88e2
            type: set_hvac_mode
            hvac_mode: heat
            enabled: false
          - action: climate.set_hvac_mode
            metadata: {}
            data:
              hvac_mode: heat
            target:
              entity_id: climate.fish_heater
            enabled: false
          - metadata: {}
            data: {}
            target:
              entity_id: input_boolean.fish_feeding
            action: input_boolean.turn_off
          - data:
              title: Fish feeding finished
              message: Fish feeding finished
            action: script.debug_notification
          - metadata: {}
            data: {}
            target:
              entity_id:
                - timer.fish_need_feeding
                - timer.fish_feeding
            action: timer.cancel
            enabled: false
      - conditions:
          - condition: trigger
            id:
              - dismiss
        sequence:
          - metadata: {}
            data:
              message: clear_notification
              title: FishFeeding
              data:
                ttl: 0
                priority: high
                tag: FishFeeding
            action: notify.mobile_app_pixel_8
          - metadata: {}
            data: {}
            target:
              entity_id: timer.fish_need_feeding
            action: timer.cancel
            enabled: false
          - action: input_boolean.turn_off
            metadata: {}
            target:
              entity_id: input_boolean.fish_feeding_asking
            data: {}
      - conditions:
          - condition: trigger
            id:
              - reset fed today
        sequence:
          - action: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.fish_fed_today
          - action: input_boolean.turn_off
            metadata: {}
            target:
              entity_id: input_boolean.fish_feeding_asking
            data: {}
      - conditions:
          - condition: trigger
            id:
              - toggle feeding
        sequence:
          - action: input_boolean.toggle
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.fish_feeding
          - action: input_boolean.toggle
            metadata: {}
            target:
              entity_id: input_boolean.fish_feeding_asking
            data: {}
    enabled: true
mode: single

I can’t think of any quick wins to simplify it though, there’s just various ways to trigger it and it does stuff in different stages. I’d rather it all be in the one automation instead of spread over a few.