Automation Trigger via All Entities in Domain

I’ve done some searching and my assumption is that what I’m after isn’t really possible currently, but figured I’d ask as I’ve certainly been wrong before. :slight_smile:

Currently I have an automation to let me know if any plants need to be watered. As it is, I explicitly list every plant (which also happens to be every entity in the plant domain). Is there an (easy) way to do this, but simply trigger via ANY entity in the plant domain (and still allow me to use the friendly name of the triggering entity later on in the actions, so I know which plant needs watered) ? There’s also the added complication that I’m actually wanting to trigger on an ATTRIBUTE changing for a specified period of time. I know wildcards have been a long-standing FR and all the workarounds I’ve come across still require you to manually specify the entities (for instance, via a group or tags). I don’t frequently add/remove plants from HA, but it’s in that sweet spot where it’s frequent enough to be annoying but infrequent enough that I usually forget to modify this automation. Here’s a truncated version of my current automation:

alias: Indoor Plant Water Notifications
description: ""
triggers:
  - entity_id:
      - plant.aloe_vera
      - plant.bromeliad_kitchen
      - plant.christmas_cactus
    attribute: moisture_status
    to: Low
    for:
      hours: 4
      minutes: 0
      seconds: 0
    trigger: state
conditions: []
actions:
  - data:
      message: >-
        The {{ trigger.from_state.attributes.friendly_name }} needs to be
        watered.
      title: "{{ trigger.from_state.attributes.friendly_name }}"
      notification_id: "{{ trigger.from_state.attributes.friendly_name }}"
    action: persistent_notification.create
mode: single

What about a template trigger? Something like states.plant should give you a list of state object for each entity.

Edit: Automation Trigger - Home Assistant

As far as I’m aware (as well as tested myself), you can’t grab an entire domain with a template.

{{ states.plant | map(attribute='entity_id') | select('is_state_attr', 'humidity_status', 'Low') | list | count > 0}}

This works for me to test if there are plants with humidity_status Low.

(there might be faster / more elegant solutions …)

Edit: And

{{ states.plant | map(attribute='entity_id') | select('is_state_attr', 'humidity_status',  'Low') | map('state_attr','friendly_name') | join(',') }}

would give you the list friendly names to be used in the notification.

1 Like

Thanks for the help! This got me basically to what I was after (I think).

I’ve setup a template sensor to give me the count of plants that need watering that I trigger the automation on when it changes for 4 hours (as well as a condition of it not being zero, so it doesn’t trigger when I actually water them):

{{ states.plant | map(attribute='entity_id') | select('is_state_attr', 'moisture_status',  'Low') | list | count}}

And then have my notifications give me a list of the plants that actually need watering:

  - data:
      message: >-
        {{ states.plant | map(attribute='entity_id') | select('is_state_attr',
        'moisture_status',  'Low') | map('state_attr','friendly_name') | join(',
        ') }}
      title: Plants Need Watering
      notification_id: Plants Need Watering
    action: persistent_notification.create

For now I’m going to run this automation in parallel with my existing one. The only issue I see, is that if a plant is hovering right around the low moisture threshold (so frequently going above and below) it would keep the automation from firing even if other plants have firmly gone below. I know this happens frequently (and is why I arrived at the 4 hour number), but I’ve never really paid attention to how LONG they do this, so it might not really matter.

  • It will trigger when the count changes from 0 to a positive integer.

  • After it triggers, the count must first return to 0 before it can be triggered again.

  • It won’t trigger if the count changes from one positive number to another.

If that fits requirements, you’re good to go.

Reference

Template Trigger

I’m aware of this, but that’s not what I want (and why I setup a template sensor instead of a trigger template). If subsequent plants go low (so the count goes up), I want it to trigger again (after the 4 hours debouncing time) so that the list of plants needing watering in my notifications gets updated.

I do suspect that I may be entering the realm where I’m going to spend more time/effort automating my automation compared to just trying to remember to add plants to my existing automation (which actually works exactly as I want). :slight_smile:

I see. So your automation uses a State Trigger to monitor the Template Sensor?

Yep. We’ll see if it works well enough for my needs.

Here’s my current automation (using the template sensor mentioned above as the trigger), just to clarify. I’d still prefer to use a single state trigger (somehow) automatically populated by all entities in the plant domain, but I think this is as close to that as I’m going to get.

alias: Plant Water Notifications
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.plants_needing_water
    for:
      hours: 4
      minutes: 0
      seconds: 0
conditions:
  - condition: not
    conditions:
      - condition: numeric_state
        entity_id: sensor.plants_needing_water
        below: 1
actions:
  - data:
      message: >-
        {{ states.plant | map(attribute='entity_id') | select('is_state_attr',
        'moisture_status',  'Low') | map('state_attr','friendly_name') | join(',
        ') }}
      title: Plants Need Watering
      notification_id: Plants Need Watering
    action: persistent_notification.create
mode: single