BeSt79
June 3, 2025, 11:47am
1
Hello everyone
I am using the proximity integration and would now like to display a badge on my dashboard that shows a different icon depending on the state of the proximity sensor.
To do this, I have changed the proximity sensor in a customize.yaml as follows:
sensor.home_bewegung_von_benni:
icon: |
{% if is_state('sensor.home_bewegung_von_benni', 'arrived') %}
mdi:home-outline
{% elif is_state ('sensor.home_bewegung_von_benni', 'stationary') %}
mdi:home-off-outline
{% elif is_state ('sensor.home_bewegung_von_benni', 'away_from') %}
mdi:home-export-outline
{% elif is_state ('sensor.home_bewegung_von_benni', 'towards') %}
mdi:home-import-outline
{% else %}
mdi:home-search-outline
{% endif %}
I integrate the customize.yaml into my configuration.yaml as follows:
homeassistant:
customize: !include customize.yaml
However, after restarting the HA and restarting the entire host, the icon is not displayed correctly.
If I look at the Proximity Sensor in the developer tools under States, the following is displayed:
I am on this version:
Thanks for any help.
Regards,
Benni
It is not (well) documented but you cannot use templating here…a pity indeed but …well
1 Like
you can instead create a template sensor and use this one in your dashboard
Or you resolve the icon-choice in the card, assuming you will only need to see this in a card
THANK YOU, wow, this forum is lightning-fast
I now try to create a template sensor:
template:
- sensor:
- name: "Benni Bewegung Icon Helper" # Neuer Sensorname
unique_id: benni_bewegung_icon_helper # Eindeutige ID
state: "{{ states('sensor.home_bewegung_von_benni') }}" # Wichtig, damit der Sensor bei Änderungen aktualisiert wird
attributes:
calculated_icon: | # Attribut, das das Icon enthält
{% if is_state('sensor.home_bewegung_von_benni', 'arrived') %}
mdi:home-outline
{% elif is_state ('sensor.home_bewegung_von_benni', 'stationary') %}
mdi:home-off-outline
{% elif is_state ('sensor.home_bewegung_von_benni', 'away_from') %}
mdi:home-export-outline
{% elif is_state ('sensor.home_bewegung_von_benni', 'towards') %}
mdi:home-import-outline
{% else %}
mdi:home-search-outline
{% endif %}
In the developer tools it is shown correctly:
Then I inserted this template sensor into the badge on my dashboard:
type: entity
show_name: true
show_state: true
show_icon: true
entity: sensor.home_bewegung_von_benni
name: Benni
icon: "{{ state_attr('sensor.benni_bewegung_icon_helper', 'calculated_icon') }}"
show_entity_picture: false
But sadly the icon is not shown. It seems, that there is a “space” for the icon, but I can´t see it:
oh, you should directly use sensor.benni_bewegung_icon_helper
as entity_id, no extra need for the icon part
template sensor like this:
- sensor:
- name: "Benni Bewegung Icon Helper" # Neuer Sensorname
unique_id: benni_bewegung_icon_helper # Eindeutige ID
state: "{{ states('sensor.home_bewegung_von_benni') }}"
device_class: motion
icon: >
{% if is_state('sensor.home_bewegung_von_benni', 'arrived') %}
mdi:home-outline
{% elif is_state ('sensor.home_bewegung_von_benni', 'stationary') %}
mdi:home-off-outline
{% elif is_state ('sensor.home_bewegung_von_benni', 'away_from') %}
mdi:home-export-outline
{% elif is_state ('sensor.home_bewegung_von_benni', 'towards') %}
mdi:home-import-outline
{% else %}
mdi:home-search-outline
{% endif %}
Awesome. It works. THANK YOU!
May I ask a follow-up question?
This is now displayed correctly in the badge. I already have a tile card for each person in my household on the dashboard:
Is it possible to display a text depending on the status of “sensor.home_movement_of_benni” plus the “dynamic” icon here instead of “Home”, for example?
Like this, for example?
My question is: Is it possible to create any kind of “helper” that contains an icon and dynamic text, that can be placed into the tile-card?
This is the tile-card-yaml:
cards:
- type: horizontal-stack
cards:
- type: tile
entity: person.benni
state_content:
- state
- last-changed
show_entity_picture: true
features_position: bottom
vertical: false
I guess you can just set state
in the template sensor to the text you want to display then