Filter out state triggers created when Template Sensors are reloaded

Hi,

I’m using triggers that track state change to any value, which during a template reload causes error messages in the log, and a lot of rapid automation executions.

    - platform: state
      entity_id: sensor.solarnet_power_photovoltaics
      to:

The Trace looks like this:

trigger:
  id: '8'
  idx: '8'
  alias: null
  platform: state
  entity_id: sensor.battery_level_sprinter
  from_state: null
  to_state:
    entity_id: sensor.battery_level_sprinter
    state: '100'
    attributes:
      unit_of_measurement: '%'
      device_class: battery
      friendly_name: Battery Level Sprinter
    last_changed: '2025-06-17T06:27:42.845454+00:00'
    last_reported: '2025-06-17T06:27:42.854335+00:00'
    last_updated: '2025-06-17T06:27:42.845454+00:00'
    context:
      id: 01JXY94XKXG7FRDQSGDQW7J0QV
      parent_id: null
      user_id: null
  for: null
  attribute: null
  description: state of sensor.battery_level_sprinter

There is no from_state.state, but there is a to_state.state. from_state == null

I’ve tried creating a bunch of different combinations to exclude to_state = null, but had no luck because I think these not_to and not_from address to_state.state and from_state.state, not to_state and from_state?

Any suggestions if there is a way to write this without a condition? A condition will still create a lot of executions.

    - platform: state
      entity_id: sensor.solarnet_power_photovoltaics
      not_from: null
    - platform: state
      entity_id: sensor.solarnet_power_photovoltaics
      not_from: 'null'
    - platform: state
      entity_id: sensor.solarnet_power_photovoltaics
      not_from: none

e.g. the above did not work.

try not_from unavailable and unknown.

that would only be the case if you position the condition in the action block of the automation.
If you put the condition in the condition block, and it is false, the automation doesn’t not fire the action block, and the last-triggered wont be set.

to rule out the template reload, you can even add that condition

condition: state
entity_id: binary_sensor.template_integration_reloaded
state: 'off'

after creating that binary.

template:

  - trigger:
      trigger: event
      event_type: automation_reloaded
    binary_sensor:
      - unique_id: automation_integration_reloaded
        <<: &config
          auto_off: 100
          state: 'on'

  - trigger:
      trigger: event
      event_type: event_template_reloaded
    binary_sensor:
      - unique_id: template_integration_reloaded
        <<: *config

which has a timespan built in to give you some slack (and /or template entities to be populated…)

Tried them both, they didnt work, I think its due to the trace above not having a from_state.state. It only has a to_state == null.

Thanks, I’ve never used that sort of templating before, for my knowledge, what is:

        <<: &config
          auto_off: 100
          state: 'on'

and

<<: &config

Those are yaml ‘anchors’

& creates it for the section below
* pastes the same section

You can use them to ‘copy and paste’ identical pieces of yaml (note: only inside a single file.)

You can leave it out if you only use the one template, but the indent needs to go 1 to the left. Same level as the unique_id

template:

  - trigger:
      trigger: event
      event_type: event_template_reloaded
    binary_sensor:
      - unique_id: template_integration_reloaded
        auto_off: 100
        state: 'on'

Worked great thanks

1 Like

glad to hear that.
please mark the solution post as solution, so others can find it too
you’re topic title is really succinct, so it will help others