Like the title says, I am trying to make a sensor with a template for pulling the names of all devices in a specific state at a specific time.
I can do this by specifying a ton of “if” statements for each device I’d like to look for, but I am hoping it is possible to template out easier and more dynamically.
I used HX711s, and a 16 in by 3 foot board to make a sensor to tell when a cat is possibly eating. I am also using Tiles and ESPresense at the moment for room tracking. I want to make a sensor that basically says "if the weight sensor is triggered, then the state is all devices in the state of “Laundry Room”. So that I know who is in there. I have 3 cats and sometimes they’ll eat together, sometimes they won’t, they’re weirdos.
Can this be done? Or am I writing out an annoying, lengthy “if”?
That will update the list of cats in the laundry room whenever one of the weight sensors changes state (assuming they’re binary_sensors and just report ‘on’/triggered or ‘off’/not triggered).
EDIT: Just read a little more on template sensors… I didn’t realize I could put triggers in. This opens a whole new world. I think I got it now. Will update with solution thank you for leading me down this path
Glad it helps. If you have a common naming scheme for your sensors, you can use a template to generate them as well. It gets more complicated in a trigger, but the sensor state could start with something like this:
{% set sensors = states.sensor|selectattr('object_id', 'match', 'cat')|map(attribute='entity_id')|list %}
That will generate a list of all entity_ids for sensors whose name starts with “cat”, such as sensor.cat_one.
You could do something similar with the template using a template trigger like this:
You are pretty rad. Thank you for your help. Now I need to figure out one more piece to the puzzle, and it’s a little more complicated…
How do I get it to read “Clear” or “Empty” after they jump off? As of this moment this sensor retains the state afterwards.