Determining entity based on value of another entity

Need some help.

I currently have an action that assigns the name of a user into a Helper entity (triggered by the opening of a door using the keypad).

service: input_text.set_value
target:
  entity_id: input_text.side_door_lock_last_user
data:
  value: >-
    {% set mapper = {   0:'Master',   1:'Neil',   2:'Carole',   3:'Julia',  
    4:'Benjamin',   5:'Cleaning',   6:'Bryan'} %} {% set selection =
    trigger.event.data['parameters']['userId'] %} {{ mapper[selection] if
    selection in mapper else 'Error' }}

I currently have another action where it’s announced using Google Home.

service: tts.google_translate_say
data:
  entity_id: media_player.kitchen_2
  message: 'Welcome {{ states(''input_text.side_door_lock_last_user'') }}'

I would like this to be smarter where instead of always announcing I would do this when the person arrived home. I have a Person Entity defined for each person (ex person.neil) which tracks if the person is Home or Away. So my thought is to simply check to see if they have been home for at least 5 mins and if so I would not announce anything.

I am trying to figure out how I can template the Entity Id of the person based on the value of “input_text.side_door_lock_last_user”. So in effect I am concatenating a variable that needs to be made lowercase and a fixed string (person.) that I then want to use to look up another value which I will use in a condition.

{% set who = 'person.' ~ states('input_text.side_door_lock_last_user') | lower %}

Ran this in Developer Tools and your solution worked. But tried to extend this and can’t quite get it the syntax.

I was hoping ‘testh’ would contain the state of person.benjamin as per the screen shot of the output.


{% set who = 'person.' ~ states('input_text.side_door_lock_last_user') | lower %}
{{who}}
{{ states('person.benjamin')}}
{% set testh = states('{{who}}') %}
{{testh}}

image

{% set testh = states(who) %}

Perfect, Thanks so much.

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has an accepted solution. It helps users find answers to similar questions.