Just wanted to say your edit in your comment helped me solve my frustration. Never knew Trigger Variables existed! Many thanks.
Hi Iām trying to create a blueprint that has a input named remote_id
of type text
, how can I use the input in a condition?
{{ trigger.event.data.id_string.startswith( states(remote_id) + ':') }}
does not seem to match the event data correctly?
blueprint:
input:
remote_id:
name: Remote id
selector:
text:
variables:
remote_id: !input remote_id
trigger:
- platform: event
event_type: rfxtrx_event
condition:
- condition: template
value_template: "{{ trigger.event.data.id_string.startswith( states(remote_id) + ':') }}"
event:
remote_id: 1599e6a
all_off_action:
...
1_on_action:
...
1_off_action:
...
2_on_action: []
2_off_action: []
3_on_action: []
3_off_action: []
this:
entity_id: automation.sovrum_fjarrkontroll
state: 'on'
attributes:
last_triggered: null
mode: single
current: 0
id: '1679664439381'
friendly_name: Sovrum fjƤrrkontroll
last_changed: '2023-03-24T13:48:33.395274+00:00'
last_updated: '2023-03-24T13:48:33.395274+00:00'
context:
id: 01GW9Y1M7KQYMTGT9JY3YBFF27
parent_id: null
user_id: null
trigger:
id: '0'
idx: '0'
alias: null
platform: event
event:
event_type: rfxtrx_event
data:
packet_type: 17
sub_type: 0
type_string: AC
id_string: 1599e6a:1
data: 0b1100ca01599e6a01010f70
values:
Command: 'On'
Rssi numeric: 7
device_id: 2c28bbd198de769adf9f7bb42707d2d9
origin: LOCAL
time_fired: '2023-03-24T13:48:39.200384+00:00'
context:
id: 01GW9Y1SX0BT964F95XTANHVGJ
parent_id: null
user_id: null
description: event 'rfxtrx_event'
What am I doing wrong here?
The remote_id
is specified as 1599e6a
and trigger.event.data.id_string
is 1599e6a:1
, so why doesnāt {{ trigger.event.data.id_string.startswith( states(remote_id) + ':') }}
match the event?
The full source of the blueprint can be found here
I didnāt understand what states()
did, but removing it and just using remote_id
solved my issue
Hello,
You are very close. The only change you need is to use a different name for the input variable in the blueprint section. One may apply an input_ prefix to the variable name as follows.
blueprint:
input:
input_alarm_trigger:
variables:
alarm_trigger: !input input_alarm_trigger
trigger:
- platform: template
value_template: "{{ states('alarm_trigger') == true }}"
Placing the variables under the variables: OR the trigger_variables: stanza worked for me.
I feel like this should be better explained in Blueprint Entity Selector Tutorial.
Thanks to @bverkron for finding and @joshcrosby for pointing it out after I skimmed passed it.
kristofferbas I am rewriting it here, so people coming off the Google train donāt have to read so much, in-case you want to mark it as answer.
P.S.
I think trankillity is correct in stating that the rendering engine should be able to handle this. If technically feasible, a input() Jinja call, in addition to states() would make this work-around not needed.
This is a very old post, but I think I need to set it straight.
The name as long as it is valid doesnāt matter. What you show @vittorio88 will not work.
If you want to put a variable into a trigger, it has to be built using the trigger_variables: key.
This is because that key is rendered when you save the automation (or blueprint) and will exist for the trigger to use.
Variables:, no matter where they are in the automation (or blueprint) are rendered after the trigger and do not exist before, so when put in the trigger are probably āunavailableā or ;nullā or something.
This is also why template_triggers: are limited in what they can do as they only have access to some of the jinga and only information available when the automation (or blueprint) is saved. They know what the !inputs are, so that works fine. Not a lot beyond that.
The documentation is covered here:
Automation Trigger - Home Assistant.
(PS, pinging people years after they posted something is not a great idea. )