I have a variable (in an automation) that is of the form:
users:
- full_name: Some Name
user_status: ACTIVE
ulp_id: XXXX-XXXX
keys:
- key_type: nfc
nfc_id: ABC123
The event data that triggers the automation has the nfc_id, and I want to match that to the full_name of the user containing that nfc_id. I currently am doing that with this code:
- variables:
name: >
{% set ns = namespace(name_ = "Unknown") %}
{% for user in keyring.users %}
{% for key in user['keys'] %}
{%
if key.key_type == "nfc" and
key.nfc_id == trigger.event.data.new_state.attributes.nfc_id
%}
{% set ns.name_ = user.full_name %}
{% endif %}
{% endfor %}
{% endfor %}
{{ ns.name_ }}
Is there a cleaner way of achieving my goal here?