#Variable in condition template value

1 messages · Page 1 of 1 (latest)

supple edge
#

Hi

I would like to create an automation that change an input select based on person's state and current select's value.
For example, if person A is "not_home" and select is "home", then select change to "just left". If select is "just arrived" then select change to "away".

It works great with one person and hard coded entity id. But we're four people in my house and I would like to create one automation to handle this for everyone.

What I did is to set a trigger id that looks like : people.state.person or people.state
Then I split the trigger id to get the part I want for example :

metadata: {}
data_template:
  option: "{{trigger.id.split('.')[1]}}"
target:
  entity_id: input_select.{{trigger.id.split('.')[0]|lower}}_presence_dropdown```

The problem is that I need to use select in a condition template to check is current value. I don't achieve to check select value based on a variable name.

I tried several thing like :

```condition: template
value_template: >-
  {% set test = 'input_select.'+trigger.id.split('.')[0]+'_presence_dropdown'
  %} 
  {{ test == 'Away'}}```

or

```condition: template
value_template: >-
 {{ 'input_select.'+trigger.id.split('.')[0]+'_presence_dropdown' == 'Away'}}```

But I don't find a way to do this.

Do you think it's possible ?

Thanks for your help.
dusk forge
#

you're just constructing the entity_id and not actually reading the state

#

you're essentially testing for "input_select.xxx" == "Away"

supple edge
#

Thanks for your help

#

So I tried to add "states." in test variable like that

dusk forge
#

that's not the right way to do it

#

{{ is_state('input_select.'+trigger.id.split('.')[0]+'_presence_dropdown', 'Away') }}

#

see the big yellow warning:

Avoid using states.sensor.temperature.state, instead use states('sensor.temperature'). It is strongly advised to use the states(), is_state(), state_attr() and is_state_attr() as much as possible, to avoid errors and error message when the entity isn’t ready yet (e.g., during Home Assistant startup).

supple edge
#

I tried this (thanks for the warning) but it didn’t work. It’s always false

dusk forge
#

what is the state of that entity? are you sure that the entity_id is being constructed properly?

#

what is an example of a trigger.id?

#

is it something like person.rob? I'm not sure what the point of the parsing is

#

What I did is to set a trigger id that looks like : people.state.person or people.state
This sounds like you're overcomplicating it

supple edge
#

trigger.id looks like : rob.away or rob.extended away or rob.not_home.person

dusk forge
#

ok. then I have the other questions above

supple edge
dusk forge
#

then the condition won't be false

supple edge
#

Indeed there’s something else

#

I don’t how to see if the entity is well constructed

dusk forge
#

use the trace

supple edge
#

I checked variable and split part

dusk forge
#

or print it in the log, or a persistent_notification

supple edge
#

If I print {{ state('input_select.'+trigger.id.split('.')[0]+'_presence_dropdown') }} it’s good ?

dusk forge
#

I would also print the entity_id that you're constructing

supple edge
dusk forge
#

you have it backward

#

it's input_select

#

and it's states() not state()

#

and you apparently have "input select." wth a space in it somewhere

#

a bunch of typos

supple edge
#

I don’t see these problems in the yaml

dusk forge
#

i'm just reading your screenshot

#

lots of obvious issues in there

#

you're clearly constructing the entity_id wrong there

#

see select_input

#

and input select

supple edge
#

I’m going crazy I don’t see these errors 🤪

#

Ok I rebooted HA and it’s better.

dusk forge
#

sounds like you weren't reloading the automation

#

again, it's states(), not state()

#

these are all just typos

supple edge
#

it's work great

#

thanks a lot for your help !

supple edge
#

do you know if it's possible to get the event_id for an input_select ?

#

when I try to ouput {{trigger.entity_id}}, it works for person.rob trigger but not for input_select trigger

manic jasper
#

If you actually use a state trigger trigger.entity_id should just work for an input_select as well.

supple edge
#

For input select the result is empty

#

It works great for person trigger

manic jasper
#

Can you post the yaml? As I did a quick test with:

alias: Test input select entity id
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_select.test
conditions: []
actions:
  - action: persistent_notification.create
    metadata: {}
    data:
      message: "{{ trigger.entity_id }}"
mode: single

And that just gives me a notification with "input_select.test".

supple edge
manic jasper
#

I assume you're talking about the telegram_bot.send_message?
Did you also had a look at the trace?

supple edge
#

I saw entity id : input_select.erwann_presence_dropdown

#

for the trigger

#

and for the telgram send message :

#

so the message seems to be good on trace

manic jasper
#

So it is good in the trace but not in the received message?

I do notice a random question mark behind it which I can't explain with the code you showed...

supple edge
#

yes I remove it but same problem

#

by the way, is it possible to test if entity_id contain a specific string ?

manic jasper
#

Remove it? The question mark you mean? As I don't see it at all in the automation...

#

And trigger.entity_is is just a string, you can do with it whatever you can do with any string. It's nothing special

supple edge
#

Ok I achieve to test trigger.entity_id and it works

#

thanks for your help !