State_changed automation creates loop

It seems like this automation creates a loop. If it is triggered then its last_triggered: attribute updates which is a state change which triggers it again. Does anyone know a way to stop the state machine from observing this automation entity?

- alias: Test Event
  initial_state: True
  trigger:
    platform: event
    event_type: state_changed
  action:
    - service: system_log.write
      data_template:
        title: test
        level: error
        message: >
          "{{trigger.event.data}}"

Yeah, that’s quite the trigger you have. You are triggering on ALL STATES OF EVERYTHING! Automations have their own states too lol. So when the automation fires, it will change its own state, firing again.

If you ignore the automation domain, it would help.

Put in this condition:

condition:
  - "{{ trigger.event.data.new_state.domain != 'automation' }}"

Or, if you only want to ignore this exact automation only…

  - "{{ trigger.event.data.entity_id != automation.test_event }}"

Hey, @jocnnor

Thanks for the reply! Yeah I thought about adding the condition but it would still continuously trigger. I know a time_changed event would continuously trigger and that makes sense. I just feel that you should be able to deny an entity from being observed or something. Having this thing constantly trigger feels wrong to me(OCD thing maybe). I will probably look into the source code to see what I can do about it although its a little above my Python skill level still. Luckily there is more than one way to skin a cat in HA. Once again I appreciate you chiming in!!

What’s the end goal of this?

Passing all the data available via state_update event about the entity to a separate application.

I can do something similar with this:

- alias: Test State Message
  initial_state: False
  trigger:
    platform: state
    entity_id:
      - sensor.test_sensor
      - binary_sensor.token
  action:
    - service: persistent_notification.create
      data_template:
        title: Test
        message: >
          "{{trigger.to_state.old_state}}",
          "{{trigger.to_state.entity_id}}",
          "{{trigger.to_state.state}}",
          "{{trigger.to_state.attributes.unit_of_measurement}}",
          "{{trigger.to_state.last_changed}}",
          "{{trigger.to_state.context.id}}",
          "{{trigger.to_state.attributes.rssi}}",
          "{{trigger.to_state.attributes.snr}}",
          "{{trigger.to_state.attributes.friendly_name}}"

This doesn’t seem to have the old state info though.

The old state is accessed via from_state, not to_state

"{{trigger.from_state.state}}"

Anyway, why not write the data to your db and read it from there? And what do you do with the other application?

@Burningstone Well that makes sense lol!

The other app is a local webserver. Besides HA being a great Home Automation tool, I am using it to learn Python and other programming disciplines. I am just messing around but in the last 4 years I have never used an state_updated event trigger so I thought it was weird how it acted even though it makes sense.