Help - Automation, action based on sensor_id or entity_id

Trying to setup a automation that could apply on my 3 climate entities.
I want the ‘climate’ action triggered by the corresponding sensor.

Here where I am today after multiple tries, but not working so far even I think I’m close.

I took care to name my entities with same name when they are supposed to work together.

My climate are named ‘climate.thermostat.name1’ name2 etc…

alias: Climate turn off when window open
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.window_name1_opening
      - binary_sensor.window_name2_opening
      - binary_sensor.window_name3_opening
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - service: climate.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: |
        climate.thermostat_{{ trigger.to_state.object_id.split('_')[3] }}
mode: single

Indexing counts from 0. name1 is the third item, which is [2].

action:
  - service: climate.turn_off
    target:
      entity_id: climate.thermostat_{{ trigger.entity_id.split('_')[2] }}

1 Like

Brilliant ! Works like a charm
Thanks for the developer tool, I will do good use of it.

1 Like