#Shopping List Automation

11 messages · Page 1 of 1 (latest)

final thistle
#

I'd like to make an automation which sends a notification to anyone who enters a shop to prompt them to open the shopping list if it has items in it, I have created a label and applied it to all shop zones. I believe i'm going to need a template similar to this in order to get this working but wanted to check to see if there is a more elegant solution: ```
{% set shops = label_entities("shop_zone") %}
{{ states.person | selectattr("state", "in", shops) | map(attribute='entity_id') | map('replace', 'person.', '') | list | length > 0 }}

small cloak
#

I would use a trigger that just sums up the state of all the shops, which results in the number of people currently in any shop:

{{ label_entities('shops') | map('states') | map('int', 0) | list | sum }}

You can then make this only execute when it increases (people entering, not leaving) by doing a template condition of

{{ trigger.to_state.state | int(0) > trigger.from_state.state | int(0) }}
#

It’s possible to go the way you suggested, iterating through the states object, but that will be rate limited to rendering once/minute, so you could have up to a one minute delay after entering a shop. Starting from the states of the zones eliminates any rate limits.

final thistle
fiery widget
#

Why not just a zone trigger and select your shop zones?

#

im pretty sure the zone trigger will have the persons in its trigger data

final thistle
#

you have to specify the entity which enters / exists the zone, i don't want to have to update every person based location when i add someone to my home

#

not that it changes often but it'd be a massive pain if i do ever have to

small cloak
#

You can look at the persons attribute of the zone, which from the trigger object would be trigger.to_state.attributes.persons
That will contain a list of all the people in the zone that just changed. You can compare it to the from_state and only send the notification to the people who entered the zone. Or, if there are more than one persons in that zone, perhaps you don’t want to notify the second person since the first one arriving already got a notification.

final thistle
small cloak
#