Running an automation when an attribute changes in whole domain

Hey. Im trying to run an automation whenever an attribute changes in a whole domain. There’s a previous thread regarding this: Templating with entity_id wildcard.
Im trying to make a notification whenever an attribute of any of my plants (plant. domain) changes and wrote a very similar trigger as the author of the thread above:

  - alias: Plant problem
    initial_state: true
    trigger:
      platform: event
      event_type: state_changed
      event_data:
        domain: plant

Unfortunately this never gets triggered.
I have replaced “domain: plant” with “entity_id: plant.bonsai” and it works fine, so the problem is definitely in “domain: plant”. Im not sure if it is a bug and “domain:” option doesnt work with “plant” domains or if I’m doing something wrong, but it’s really important for me to use a domain instead of a list of each plants as I’ve got more than few plant sensors and when i repot a plant I’m also changing it’s sensor name. Managing a list of all plant entities would be very cumbersome.

domain is not valid event data for state_changed. You get entity_id, old_state and new_state.

  - alias: Plant problem
    initial_state: true
    trigger:
      platform: event
      event_type: state_changed
    condition:
      - "{{ trigger.event.to_state.domain is 'plant' }}"

You might have to make sure event.to_state is not none in case the event is fired when you are removing something.

Also not sure if it’s trigger.event.to_state.domain or trigger.event.data.to_state.domain. one of those though lol

1 Like

Thanks and i appreciate providing a ready solution.

Unfortunately, this doesnt seem to work.
In fact, by listening to state_changed event in Developer Tools -> Events i found out that trigger.event.data doesnt provide domain name at all.

Sure, but that’s because ‘state.domain’ is a property of the state object, not the data itself.

The correct syntax is

{{ trigger.event.data.new_state.domain }}

I’m so used to to_state for state triggers…but event state_changed uses new_state.

I have it running right now sending me notifications to my phone every 10 seconds about what id and what domain is changing.