Button: how to get pressed by value?

Hi everybody,


UPDATE

I believe I got it: {{ states.button.kiosk_galaxy_tab_a_bring_to_foreground.context.user_id }} will give me a user_id, which I can check with person.<user>.

However, is there also a way to get the area? Let’s say I assigned it to office; what do I need to use in my template to get this value?


when I press a button via lovelace, it will display the name of the person in the UI:

There it says Ben. How can I get this value? I tried

{{ states("button.kiosk_galaxy_tab_a_bring_to_foreground") }}

{{ states.button.kiosk_galaxy_tab_a_bring_to_foreground }}

Which produces

2023-03-03T07:48:19.593672+00:00

<template TemplateState(<state button.kiosk_galaxy_tab_a_bring_to_foreground=2023-03-03T07:48:19.593672+00:00; friendly_name=Kiosk/Galaxy Tab A Bring to foreground @ 2023-03-03T08:48:19.593723+01:00>)>

Is there a way to see who last pressed this button without creating extra helper entities? If lovelace can display it, it must be saved somewhere, right?

Thank you in advance for your help :slight_smile:

1 Like
{{ area_name('button.kiosk_galaxy_tab_a_bring_to_foreground') }}
1 Like

Yes! Thank you.

I was hoping to create a template sensor that will show me all entities that are not assigned to any area. Usually, I do this by clicking on mqtt (which is where most of the related entries are) and scroll through - since everything should be mapped to an area, it is easy to see what is missing.

Is there some way to use area_name for this?

This might help

{% for id in expand(states.sensor) | map(attribute='entity_id')  %}
{% if not area_name(id) %}
{{ id }}: {{ area_name(id) }}
{% endif %}
{% endfor %}
1 Like

Perfect, thank you.


edit: actually, this causes an issue when I try to use it as a template sensor. They only allow 255 characters, but currently there are too many sensors and this value is exceeded. Is there an alternative way to create a sensor containing all these entities?

what’s the purpose? maybe there is another way in getting there…

I am trying to always assign new integrations, entities, etc. to the area they (the physical items) reside in.

Usually, I add all new entities manually; most of the times, those are tasmota or zigbee2mqtt or ESPHome devices, so there is one new item at the time and I can assign the area right away.

Recently, I added an openMQTTGateway with 433 protocol, and this device keeps adding things I don’t actually use - or even own. I get motion sensors, soil, temperature, etc. from around the neighborhood. I’d like to create a lovelace card on my dashboard displaying something like

Attention! There are <number> entities that have not been assigned an area. Please do so.

The entities are:
* <00000>
* <00001>
* etc.

I want to assign all these irrelevant entities to an area (third parties) so that I can always be sure not to include them in anything. Yesterday, I added about 30 devices (all of which containing at least rssi, battery, and then some sort of sensor, for example, motion) to this area. This morning, there were at least 30 more.

I thought it’d be easiest to get a card displaying all those entities that I need to fix.

You can use the markdown card for this, using above script create a formatted table.
The only downside I have currently seenn (or I donot know how) is that there is no ‘on click’ option

This would work too

type: custom:auto-entities
card:
  type: entities
filter:
  template: |
    {% for id in expand(states.sensor) | map(attribute='entity_id')  %}
    {% if not area_name(id) %}
    {{ id }}
    {% endif %}
    {% endfor %}
1 Like

That works perfectly, thank you.