Hi all,
Running home assistant on VM (esxi) for over 4 years now:
Version - core-2024.12.2
Supervisor - 2024.11.4
Installation Type - Home Assistant OS (14.0)
Frontend - 20241127.7
I have an issue with a relatively simple template.
My specific goal:
=> to get a notification on iphones when someone pushes the gatebutton (opening/closing the gate), listing who pressed the button, except if a certain user is doing this (simple if then else logic)
For this i have made one automation, making use of a template that I made from several posts on the forums here. The part of the automation that sends the notification is below:
metadata: {}
data:
message: >-
{% set user_id = states.input_button.poorttogglebutton.context.user_id %}
{% set triggered_by = (states.person | selectattr('attributes.user_id','==', user_id)) | list %}
{% set first_name = "System" if not triggered_by else state_attr((triggered_by |
first).entity_id, 'friendly_name').split()[0] %}
{% if is_state('first_name', 'Ben') %}
de poort wordt opengedaan!
{% else %}
{{ first_name }} heeft de poort opengedaan!
{% endif %}
enabled: true
action: notify.mobile_app_iben2024
The problem:
When the user âBenâ presses the poorttogglebutton, I still get this message below insted of âde poort wordt opengedaan!â
Ben heeft de poort opengedaan!
even though I know that
{{ first_name }}
resolves in
Ben
As I checked this in the Developer tools template tab.
Off note and probably important to this, when I was troubleshooting and check the below in Dev tools template tab
{% set user_id = states.input_button.poorttogglebutton.context.user_id%}
{% set triggered_by = (states.person | selectattr('attributes.user_id','==', user_id)) | list %}
{% set first_name = "System" if not triggered_by else state_attr((triggered_by |
first).entity_id, "friendly_name").split()[0] %}
{% if is_state('first_name', 'Ben') %}
de poort wordt opengedaan!
{% else %}
{{ first_name }} heeft de poort opengedaan!
{% endif %}
{{first_name}}
{{states('first_name')}}
I get the following output:
Result
Result type: string
Ben heeft de poort opengedaan!
Ben
unknown
This template listens for the following state changed events:
Domain: person
Entity: first_name
Entity: input_button.poorttogglebutton
Entity: person.touchscreenkeuken
So the problem probably is related to {{states(âfirst_nameâ)}} resolving into âunknownâ, but I donât know the reason for this, neither what to do to resolve this.
Many thanks for reading and of course would appreciate any help if possible!
kind regards,
Ben