Help: which entity was last triggered

Hello. I have a routine that is triggered from my Google Home minis/nest, and I need to know witch media_player was used to trigger the routine, is this possible?
At least, as an assumption, I could use the .last_changed attribute to find out witch one has used, but how can I get the entity_id of the the sensor that has the “minimum” value of that attribute (closest to now() - probably the highest)?

Having this list:

{% set colunas = ['media_player.coluna_da_sala','media_player.coluna_da_cozinha','media_player.coluna_da_cave'] %}

How can I get the entity_id of the one that was .last_changed?

Probably pretty basic, but I could not find a direct solution for this other than comparing one by one… any help, please? Thanks in advance!

{% set colunas = ['media_player.coluna_da_sala', 'media_player.coluna_da_cozinha', 'media_player.coluna_da_cave'] %}
{{ expand(colunas) | sort(attribute='last_changed', reverse=true) | map(attribute='entity_id') | first }}
1 Like

OMG, really? THANKS! I’m really gonna try that! Is there any other way to know from witch media_player has the script been triggered from (as a routine in Google Home)? Can’t mark your post as a solution, I think because of trust level, but your answer is a solution to my question, I’m very thankfull to you. It seems it doesn’t solve my problem, because the last_changed does not correctlly choose the media_player that triggered the routine, but that’s another matter! :slight_smile: Thanks again, that was quite a bit of learning to me!!! :slight_smile: :star_struck:

I don’t use Google Home, but there may be something in the event bus that you can use to identify the device triggering the script.

1 Like

Ok, thanks again! That’s what I needed next, a direction :slight_smile: 5*

There is a way to get the device you talked to.
I (still) haven’t done it myself but it’s here on the forum somewhere.

It had something to do with playing a white noise after each command.
Try and search for it.

1 Like