Automation is triggered by state change from off to off

Hi there,

my automation is configured to be triggered by state changes from any to any state. Then a notification is sent to me.

Currently I receive a lot of notifications saying “Changed to off, from off”

In my opinion this should not happen. What could be the reason for that behaviour?

thanks
Thomas

Please share you automation yaml when asking questions like this. And format it for the forum correctly.

I’m guessing you have something like this:

trigger:
  - platform: state
    entity_id: sensor.foo

This will trigger on all state and attribute changes.

If you only want to trigger on all state changes but not attribute changes supply a null to:

trigger:
  - platform: state
    entity_id: sensor.foo
    to:

Another option that only triggers on state changes and ignores unknown states:

trigger:
  - platform: state
    entity_id: sensor.foo
    not_to:
      - unknown
      - unavailable
1 Like

The Automation is as follows:

alias: "Papa - Wohnungstür "
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.papa_wohnungstur
    for:
      hours: 0
      minutes: 0
      seconds: 1
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.papa_wohnungstur
            state: "on"
        sequence:
          - service: notify.automation_papa_group
            metadata: {}
            data:
              message: "Papa: Wohnungstür geöffnet"
      - conditions:
          - condition: state
            entity_id: binary_sensor.papa_wohnungstur
            state: "off"
        sequence:
          - service: notify.automation_papa_group
            metadata: {}
            data:
              message: >-
                Papa: Wohnungstür geschlossen / Changed to
                {{trigger.to_state.state}}, from {{trigger.from_state.state}}
    default:
      - service: notify.automation_papa_group
        metadata: {}
        data:
          message: >-
            Papa Wohnungstür in undefiniertem Zustand: {{
            states('binary_sensor.papa_wohnungstur') }}   Changed to
            {{trigger.to_state.state}}, from {{trigger.from_state.state}}
mode: single

trigger:
  - platform: state
    entity_id:
      - binary_sensor.papa_wohnungstur
    to: # null to only triggers on state not attribute changes as I wrote above.
    for:
      hours: 0
      minutes: 0
      seconds: 1
1 Like

Thanks!

I was so fixated on your

so I did´t properly read the rest - shame on me!

Just to be curious: can I find out which attribute triggered the change? I am somewhat confused by the documentation, especially which variables and functions are available at each point. Sometimes things are on the trigger page, then on the automation trigger page and anoth time on the notification page… Surely there is a system, I am just unable to grasp that yet :sweat_smile:

I’m often guilty of doing that too.

I can’t think of a way to do that. Someone else might.

Yeah it takes time to know where things are.

There are integration specific pages, like https://www.home-assistant.io/integrations/lifx/ which is a light , and then there are generic integrations like https://www.home-assistant.io/integrations/light/ that also have service information for all the individual light integrations. There are generic pages like that for each domain (light, switch, climate, etc…).

All can be found by searching here: https://www.home-assistant.io/integrations/

Other than that my main goto pages are:

https://www.home-assistant.io/docs/automation/trigger/

https://www.home-assistant.io/docs/automation/templating/#trigger-state-object

https://www.home-assistant.io/docs/scripts/conditions/

https://www.home-assistant.io/docs/scripts (automations are just scripts with triggers so this applies to both scripts and automations).

https://www.home-assistant.io/integrations/script/#waiting-for-script-to-complete

https://www.home-assistant.io/docs/configuration/state_object/

https://www.home-assistant.io/docs/configuration/templating/

https://www.home-assistant.io/dashboards/

1 Like