Conditional between multiple entities with an attribute of another entity

Hello folks,

I am working on a blueprint to automate presense detection. It is based on PIR (binary sensors) and ESPresense room occupancy via mqtt_room.

The mqtt_room entities are sensors that output a string corresponding to the room that the tracked device is currently detected to be at.

The particular snippet I am interested in is this:

        - condition: state
          entity_id: !input espresense_devices
          match: any
          state: "{{ state_attr(occupancy_room, 'friendly_name') }}"

In this example, the “entity_id” (!input espresense_devices) is an array of mqtt_room sensors, which all have a string value of the room they are detected at, i.e. “living_room”.

The “state” rule to match, is the “friendly_name” attribute of the custom binary_input entity “occupancy_room”. The value of the “friendly_name” is the exact same string as the one outputted by the mqtt_room, for our example say the value is “living_room”.

I cannot manage to get a match between the multiple presense entities and an attribute of an entity… I’ve tried all sorts of ways and combinations to now avail…

I am pasting the entire blueprint where I am using a variable to use in the “state” property of the condition.

blueprint:
  name: Presense v1
  description: Setups presense automation for a room. This Blueprint will
    Trigger when any of the following happen
    * Any of the binary motion sensors detect motion
    * A tracked device changes room
    Will then turn on presense for the configured room or turn it off
    when there is no person or motion detected.
    Inspired by this post https://community.home-assistant.io/t/my-espresense-setup-and-lovelace-dashboard/472705
    Blueprint version 1
  domain: automation
  source_url: https://gist.github.com/thanpolas/TBD
  input:
    motion_entities:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
          multiple: true
    espresense_devices:
      name: ESPResense Devices
      selector:
        entity:
          domain: sensor
          multiple: true
    occupancy_room:
      name: Occupancy Room
      selector:
        entity:
          domain: input_boolean
          multiple: false

#
# Automation Configuration start
#
mode: single
max_exceeded: silent
trigger:
  platform: state
  entity_id: !input motion_entities
condition: []
variables:
  occupancy_room: !input occupancy_room
  occupancy_room_id: "{{ state_attr(occupancy_room, 'friendly_name') }}"
  is_espresense_devices_in_room: is_state(!input espresense_devices, occupancy_room_id)
action:
  - choose:
    - conditions:
      - condition: or
        conditions:
        - condition: state
          entity_id: !input motion_entities
          state: "on"
          match: any
        - condition: state
          entity_id: !input espresense_devices
          match: any
          state: >
            {{ occupancy_room_id }}
      sequence:
        - service: input_boolean.turn_on
          data:
            entity_id: !input occupancy_room
    - conditions:
      - condition: state
        entity_id: !input motion_entities
        state: "off"
      - condition: not
        conditions:
        - condition: state
          entity_id: !input espresense_devices
          state: "{% state_attr(!input occupancy_room, 'friendly_name') %}"
          match: any

      sequence:
        - service: input_boolean.turn_off
          data:
            entity_id: !input occupancy_room

Hi,
Just wondering if you get this to work. Thanks