If Davide pass:
condition: template
value_template: >-
{% set person = states.person|selectattr('attributes.user_id','eq',trigger.event.context.user_id)|first%}
{{ 'Davide' in person.attributes.friendly_name }}
enabled: true
If Davide pass:
condition: template
value_template: >-
{% set person = states.person|selectattr('attributes.user_id','eq',trigger.event.context.user_id)|first%}
{{ 'Davide' in person.attributes.friendly_name }}
enabled: true
Device name:
{% set dev_name = expand(device_entities(trigger.event.data.device_id)) |
selectattr('domain', 'eq', 'device_tracker') | map(attribute='name') | join
%} Test NFC - device: {{ dev_name }}
that does not work for me either. same result. It does not choose
why do you have your condition? It defeats the purpose by restricting to only one person… and they person isn’t the one in the choose… so it will never work…
it looks like I copied it wrong…
alias: Ruimte1_nfctag
description: ""
trigger:
- platform: event
event_type: tag_scanned
context: {}
event_data: {}
condition:
- condition: template
value_template: "{{ trigger.event.data.tag_id == '0b3128d7-a0fc-4f56-a7fa-ad6041ea207c'}}"
action:
- choose:
- conditions:
- condition: template
value_template: "{{ this.context.user_id == '63ae2011ba54413ea0df17a78f6b0f7a' }}"
sequence:
- service: notify.mobile_app_gsm_x
data:
title: test
message: x heeft de tag in ruimte 1 gescanned
- conditions:
- condition: template
value_template: >-
{{ trigger.context.user_id == '7ed612d37b704e1cb33004322b946082'
}}
sequence:
- service: notify.mobile_app_gsm_x
...
the condition is to know what tag is scanned…
trigger:
Why into condition?
In fact, that is not my problem. That is working.
The problem is the choose …
It’s not clear what you want.
user is 63ae2011ba54413ea0df17a78f6b0f7a, why isn’t it a normal name?
what is the difficulty?
description: Who tag
mode: single
trigger:
- platform: tag
tag_id: ac83XXXXX-XX-XXXXX-XXXXXXXXXXX
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: >-
{% set person =
states.person|selectattr('attributes.user_id','eq',trigger.event.context.user_id)|first%}
{{ 'Davide' in person.attributes.friendly_name }}
enabled: true
sequence:
- service: notify.notify
data:
title: Centralina Allarme
message: Davide scan tag
data:
ttl: 0
priority: high
actions:
- action: CLOSE
title: Segna come letto
- conditions:
- condition: template
value_template: >-
{% set person =
states.person|selectattr('attributes.user_id','eq',trigger.event.context.user_id)|first%}
{{ 'Sara' in person.attributes.friendly_name }}
enabled: true
sequence:
- service: notify.notify
data:
title: Centralina Allarme
message: Sara scan tag
data:
ttl: 0
priority: high
actions:
- action: CLOSE
title: Segna come letto
the trigger condition a problem. I’m not asking about the choose conditions. Why is that there? the trigger condition in an automation is checked and enforced. So this condition you have means it will only allow that one person. If the user_id is not that one, the automation stops.
get rid of the trigger condition… keep the choose conditions
alias: Ruimte1_nfctag
description: ""
trigger:
- platform: event
event_type: tag_scanned
context: {}
event_data: {}
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ this.context.user_id == '63ae2011ba54413ea0df17a78f6b0f7a' }}"
sequence:
- service: notify.mobile_app_gsm_x
data:
title: test
message: x heeft de tag in ruimte 1 gescanned
- conditions:
- condition: template
value_template: >-
{{ trigger.context.user_id == '7ed612d37b704e1cb33004322b946082'
}}
sequence:
- service: notify.mobile_app_gsm_x
...
If I’m understanding the OP right, the condition is for the tag_id
, not the user_id
. It’s the check, that this tag really is supported.
automation:
- id: handle_tag_scan
alias: "Handle Tag Scan"
mode: single
[...]
trigger:
platform: event
event_type: tag_scanned
condition:
# Test that we support this device and tag
- "{{ trigger.event.data.tag_id in tags }}"
- "{{ trigger.event.data.device_id in media_players }}"
action:
- variables:
media_player_entity_id: "{{ media_players[trigger.event.data.device_id] }}"
media_content_id: "{{ tags[trigger.event.data.tag_id].media_content_id }}"
media_content_type: "{{ tags[trigger.event.data.tag_id].media_content_type }}"
[...]
@Faecon
What isn’t working with the choose? The screenshot you posted before - in that screen go to the upper right and download the trace of the last failed automation and post it here. There should be a reason listed, why it is failing.
On a first glance there seems nothing wrong with the automation, but maybe you post what you have right now, or is it still the same, as in this post above? Just to be on the same page…
the condition is the tag, not the person.
so the trigger is the scanning of a specific tag :
0b3128d7-a0fc-4f56-a7fa-ad6041ea207c
that works.
then it goes further to 3 options (the choose).
I’ve made a test automation
They all don’t work so I doubt the
alias: test
description: ""
trigger:
- platform: event
event_type: tag_scanned
context: {}
event_data: {}
condition:
- condition: template
value_template: "{{ trigger.event.data.tag_id == '0b3128d7-a0fc-4f56-a7fa-ad6041ea207c'}} "
action:
- choose:
- conditions:
- condition: template
value_template: "{{ this.context.user_id == '5fa8377fe546493fb4c541aac336d2c6' }}"
sequence:
- service: notify.mobile_app_gsm_joachim
data:
title: test
message: >-
5fa8377fe546493fb4c541aac336d2c6 heeft de tag in ruimte 1
gescanned
- conditions:
- condition: template
value_template: "{{ this.context.user_id == 'joachim' }}"
enabled: true
sequence:
- service: notify.mobile_app_gsm_joachim
data:
title: test
message: joachim heeft de tag in ruimte 1 gescanned
- conditions:
- condition: template
value_template: "{{ this.context.user_id == 'Joachim' }}"
enabled: true
sequence:
- service: notify.mobile_app_gsm_joachim
data:
title: test
message: joachim heeft de tag in ruimte 1 gescanned
mode: single
choose:
- conditions:
- condition: template
value_template: |2-
{% set person =
states.person|selectattr('attributes.user_id','eq',trigger.event.context.user_id)|first%}
{{ 'Joachim' in person.attributes.friendly_name }}
sequence:
- service: notify.mobile_app_gsm_joachim
data:
title: test
message: Joachim optie1 heeft de tag in ruimte 1 gescanned
does not work for me
my code was wrong, this is ok. It checks the tag, not the person
I think it’s related to this bug, Context user_id ist not propagated when an automation is triggered by a MobileApp event. · Issue #90669 · home-assistant/core · GitHub. Also the example code only work when I manually triggered it, it did not work from the mobile device.
Please post the dowmloaded trace, I’m not familiar with Dutch, so I (and others) can’t read what’s happening there…
It’s still unclear what you want and what doesn’t work, my example works 100%, what do you need to check?
the tag id ??
You still don’t understand that activating a condition is not formally correct.
what is the difference between:
trigger->event->condition->tag_id
or
trigger->tag_id
???