Automation - Choose - How to get information about which option was chosen?

I want to create a notification containing which option was chosen, I can’t figure it out! Any help would be appreciated!

alias: test
description: ""
triggers:
  - trigger: state
    entity_id:
      - light.lounge_big_light
conditions: []
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.lounge_big_light
            state: "on"
        sequence:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: "{{chosen.option}} fired"
      - conditions:
          - condition: state
            entity_id: light.lounge_big_light
            state: "off"
        sequence:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: "{{chosen.option}} fired"
mode: single

Hello RGx01,

Where are you creating that?

My guess is you are not, and that is your problem.
Instead of:

Why not this?

            data:
              message: "Choice 1 fired"

Hi @Sir_Goodenough, The example I’ve given is a simplified automation. My real automation is complex, I have numerous options that are still being developed, rearranged etc. I’d like to know which option generated the message.

The trigger object contains information about your automation’s State Trigger.

trigger.entity_id will contain the entity_id of whichever entity was responsible for triggering the State Trigger (useful if there is more than one entity listed in the State Trigger).

trigger.to_state.state will contain the entity’s new state. For example, on or off.

Reference

Automation Trigger Variable - State Trigger


alias: test
description: ""
triggers:
  - trigger: state
    entity_id:
      - light.lounge_big_light
      - light.kitchen 
      - light.bedroom
      - light.bathroom
conditions: []
actions:
  - action: persistent_notification.create
    metadata: {}
    data:
      message: "{{ trigger.entity_id }} fired and its state is {{ trigger.to_state.state }}."
mode: single

Well, I came up with a simplified answer to match.
I have tried mind reading, but it didn’t work out as expected…

{{chosen.option}}

Doesn’t exist so you cannot use it.

Trace Timeline knows which option was selected, just wondered if it was exposed for us to use.

What do you mean by “option”?

  • Which trigger if there’s more than one?
  • Which entity in a trigger if there’s more than one?

In either case, the trigger object (what I explained in my previous post) can be used to determine it.

He’s trying to know which choose path was taken from this. data or somewhere…
Pretty sure not a thing without creating a variable that’s updated based on path taken…

To my knowledge, there’s no accessible index value for the options of a choose statement. So you can’t self-referentially determine that the third choose option was selected.

In any case, there should be no need for a so-called choose.option given that you can hard code the index value directly in the option. It’s unclear why the OP needs this capability (i.e. this seems to be an XY problem).

1 Like

How to help us help you - or How to ask a good question.

Appreciate your help. Happy to accept that it’s not possible.

In future, I’ll better explain the root issue so you can tell me what’s possible. Merry Christmas.