#Automation with Template (Wildcards)

1 messages · Page 1 of 1 (latest)

west sorrel
#

Hi all, I am trying to make an automation using a template. If I specify one entity it gets triggered, but when I get more advanced, it doesn't seem to do anything. Am I approaching this correctly ? My aim is to increment a counter when any light.xxxxxxxx entity is activated. The aim is for my elderly parents where I want a notification if nothing has been triggered by 10am or so.

viscid torrent
#

that template won't work sadly for a few reasons

  1. it doesn't know what entity_id is in that context
  2. it doesn't have a trigger variable to check the to_state of
  3. template triggers need to return false sometimes in order to trigger when they transition to true
#

There are a few ways you could do this - one of the simplest imo would be to create a Light Group Helper (don't check "hide members") which will be on if any of the lights you add to it is on
You can then make a History Stats Helper pointed at that light group set to count with a start of {{today_at()}} (midnight today) and an end of {{now()}} - this will count the number of times the lights have gone from all off to at least one on today
You could then have your automation trigger at 10am, have a condition (and if) to check if the history stats helper is 0 (no lights have been on) - you could also add something like a button on the dashboard to press if they're going on holiday - and add "input_boolean.holiday_time" is off as another condition so you don't get spammed while they're away from the house - and then notify you if necessary

This approach has a couple of downsides, but the main one is that if they left a light on somewhere overnight, it would confuse the count in the morning and you'd get a notification (it has to go from all lights off to at least one off for the group state to change) - you could get around this with a triggered template binary sensor instead - trigger off any of the lights going from off to on - turn on the template and give it an auto_off of 1s, this will make it "blip" on every time a light is switched but then turn off, giving you a much more accurate count with your history stats

west sorrel
#

Thanks! I'll take a look and see what I can cobble up. I dont want to add lights manually as their lighting system has about 90 lights on HA ! (its a RAKO light controller)

viscid torrent
#

ah gotcha

#

In that case, you can do it automatically, if a bit less responsive as it will only check once per minute:

{{ states.light | rejectattr('attributes.entity_id', 'defined') | selectattr('state', 'eq', 'on') | list | count > 0 }}

Will return true if any lights are on, false if they're all off

#

Basically: (everything that lists itself as a light) (reject some things that are not real lights) (select only the ones that are on) (as a list) (count how many)

west sorrel
#

I ended up writing an integration.

#

increments by one when a light goes from OFF to ON. (with Exclude Areas.. dont care about outside lights) Still early days though, I'll see how this goes. (the numbers reset on reboot.. but not worried about that)

sturdy pecan
viscid torrent
#

Oh fair enough