Help with automation with trigger-based-choices

Hi all,

I currently have 3 automations based on 3 different triggers, but all the automations work exactly the same, only the trigger is different and the action is different. Can i combine this in 1 automation?

So, for example:
When trigger is A, do action 1
When trigger is B, do action 2,
etc

I combined my triggers as follows, and the action (example) i want is commented out:

- id: "vacation_mode_lights"
  alias: "Vacation Mode: Lights"
  description: "Simulate last weeks lights during vacation mode"
  trigger:
    - entity_id: sensor.vacation_sensor_zithoek
      platform: state
    - entity_id: sensor.vacation_sensor_eetkamer
      platform: state
    - entity_id: sensor.vacation_sensor_kitchen
      platform: state
  action:
    # - choose:
    #     - conditions:
    #         - condition: state
    #           entity_id: sensor.vacation_sensor_zithoek # <---- this one changes based on trigger
    #           state: 1
    #       sequence:
    #         - service: light.turn_on
    #           entity_id: light.woonkamer_tv # <---- this one changes based on trigger
    #     - conditions:
    #         - condition: state
    #           entity_id: sensor.vacation_sensor_zithoek  # <---- this one changes based on trigger
    #           state: 0
    #       sequence:
    #         - service: light.turn_off 
    #           entity_id: light.woonkamer_tv # <---- this one changes based on trigger

Yes, with {{ trigger.entity_id }}. Start here:

Hi Troon,

Thanks, I found that one I think, but the issue is that I struggle with the IF/ELSE afterwards. How would I use this template variable in an if/else in an action?

Eric

See the second example here:

EDIT: sorry, needed to use string, not int

Thanks, this is what I ended up doing, but it gives an error. Error is:

Invalid config for [automation]: expected str for dictionary value @ data['action'][0]['choose'][0]['sequence'][0]['choose'][0]['conditions'][0]['state']. Got None. (See /config/configuration.yaml, line 4).
Invalid config for [automation]: expected str for dictionary value @ data['action'][0]['choose'][0]['sequence'][0]['choose'][1]['conditions'][0]['state']. Got None. (See /config/configuration.yaml, line 4).

Automation is:

- id: "vacation_mode_lights"
  alias: "Vacation Mode: Lights"
  description: "Simulate last weeks lights during vacation mode"
  trigger:
    - entity_id: sensor.vacation_sensor_zithoek
      platform: state
    - entity_id: sensor.vacation_sensor_eetkamer
      platform: state
    - entity_id: sensor.vacation_sensor_kitchen
      platform: state
  condition:
    - condition: state
      entity_id: input_boolean.vacation_mode
      state: "on"
  action:
    - choose:
        - conditions:
            - condition: template
              value_template: "{{ trigger.entity_id == 'sensor.vacation_sensor_zithoek' }}"
          sequence:
            choose:
              - conditions:
                  - condition: state
                    entity_id: sensor.vacation_sensor_zithoek
                    state: "1"
                sequence:
                  - service: light.turn_on
                    entity_id: light.woonkamer_tv
              - conditions:
                  - condition: state
                    entity_id: sensor.vacation_sensor_zithoek
                    state: 0
                sequence:
                  - service: light.turn_off
                    entity_id: light.woonkamer_tv
        - conditions:
            - condition: template
              value_template: "{{ trigger.entity_id == 'sensor.vacation_sensor_eetkamer' }}"
          sequence:
            choose:
              - conditions:
                  - condition: state
                    entity_id: sensor.vacation_sensor_eetkamer
                    state: 1
                sequence:
                  - service: light.turn_on
                    entity_id: light.eetkamer1
                  - service: light.turn_on
                    entity_id: light.eetkamer2
              - conditions:
                  - condition: state
                    entity_id: sensor.vacation_sensor_eetkamer
                    state: 0
                sequence:
                  - service: light.turn_off
                    entity_id: light.eetkamer1
                  - service: light.turn_off
                    entity_id: light.eetkamer2
        - conditions:
            - condition: template
              value_template: "{{ trigger.entity_id == 'sensor.vacation_sensor_kitchen' }}"
          sequence:
            choose:
              - conditions:
                  - condition: state
                    entity_id: sensor.vacation_sensor_kitchen
                    state: 1
                sequence:
                  - service: light.turn_on
                    entity_id: light.woonkamer_keuken
              - conditions:
                  - condition: state
                    entity_id: sensor.vacation_sensor_kitchen
                    state: 0
                sequence:
                  - service: light.turn_off
                    entity_id: light.woonkamer_keuken