Automation shows trigger but doesn't do the action

I’ve got a automation that should do two things:

  1. warn whenever a door is being opened,
  2. warn whenever the automation is being enabled.

The first trigger work without issue, the second part however doesn’t. Whenever the automation is being enabled I see the trigger being activated, but it does do the thing it should do.

alias: Melding - Slaapkamerdeur open
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.slaapkamer_1_contact
      - binary_sensor.slaapkamer_2_contact
      - binary_sensor.slaapkamer_3_contact
    from: "off"
    to: "on"
    id: Geopende deuren
  - platform: state
    entity_id:
      - automation.melding_slaapkamerdeur_open
    from: null
    to: "on"
    id: Automatisering ingeschakeld
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Geopende deuren
        sequence:
          - service: tts.cloud_say
            data_template:
              entity_id: media_player.woonkamer
              message: >-
                {{trigger.to_state.name}} heeft zojuist de slaapkamerdeur
                geopend.
      - conditions:
          - condition: trigger
            id:
              - Automatisering ingeschakeld
        sequence:
          - service: tts.cloud_say
            data_template:
              entity_id: media_player.woonkamer
              message: De slaapkamerdeur meldingen zijn ingeschakeld.
mode: single

Get rid of the from: null in your trigger. It will not be going from null to on but off to on so will not trigger.

Sorry, tried that and tried it again but that didn’t do the trick.
It might be that the trigger is the automation itself, so whenever this automation is turned on this automation should do something.

Ok, explain your use case more. What is running the automation apart from your contact sensors and under what situation are you looking for it to notify the automation is turned on?

Oh, actually i think i get the issue. You are looking to send a notification when the automation is enabled? Ie goes from disabled to enabled? This is not the same as the automation being on or off. On means the automation is running, not that it is enabled. There is no event that happens when you enable automations to trigger from.

I think your best best is to have an input boolean helper that defines if your automation is enabled/disabled and use this as a condition in your automation so that it will not notify if your input boolean is On when a contact sensor triggers it. Then have another automation that triggers when your input boolean is turned on to notify automation is enabled and maybe again when turned off to notify disabled etc.

Accoriding to my reasoning it should work:

  1. The state of the automation is on or off according to the Developer Tools:
  2. The automation shows the trigger (the state of the automation) being triggered when I turn on the automation:

I hope there is some other option than creating more sensors.

The first three triggers are the doors of our children and the automation will warn us that our private time is going to be interupted by one :slight_smile:
I could implement a helper “private time” and use it as a condition in the automation, that way I never have to turn on/off the automation.

Yes, had a bit of a play and you are right, however, i think then it is because you cannot do thisnon itself. If i try with another automation it works but not itself. Probably because the trigger maybe runs before the automation is re-enabled.

I would def use the private time helper method and then you can have as a switch on a dashboard to enable/disable.

Alternatively just put padlocks on the outside of their doors! :smiley:

That is 100% incorrect.

the automation state of on means that the automation is enabled. not that the automation is currently running.

And to the OP, yes, I think you need a second automation to detect the first automation is enabled (to the ‘on’ state).

Or better yet try to work out a way that the first automation shouldn’t need to be disabled and actually use logic to do what disabling the automation accomplishes for you.

1 Like

Actually, it’s the opposite.

Go to Developer Tools > States and check the states of your automations. Unless you have disabled any, they’ll all be on which means that they’re enabled.

An automation that’s running (i.e. is busy executing its actions) will have its current attribute set to 1 (or higher if multiple instances of it are running).

When an automation is disabled, none of its triggers are functional. They become functional only after the automation is enabled. That’s why an automation cannot detect when it has been enabled.

I’ve launched a ticket on github Automation won’t trigger to its own state when enabled · Issue #97090 · home-assistant/core (github.com)

When you turn on the automation, is a trace produced?

If there’s a trace, post it.

There is no trace, only thing that shows the trigger is de HA frontend.

Which is what I had suspected. The automation never triggered when it was turned on.

An automation cannot detect itself being turned on because the trigger responsible for detecting it isn’t functional until after the automation is turned on (at which point it’s too late to be useful).

1 Like

I have to agree to you on that. I also think that I’m the only one looking at this as an “issue”, it would be nice if one could include some actions that happen aftere the automation has been enabled?

I could think of some usecases: One could have some automations running during the year, but when going on holiday you enable the holiday automation; a message will confirm that the regular automations have been disabled and the holiday automation has been enabled. Ofcourse you could place a switch on your desktop that does the same, but why be reminded the entire year of that single event :slight_smile:

I’ve settled with a helper and made an indiscrete button :slight_smile:
When the helper is off:
image
When the helper is on:
image

I agree because it’s not an issue.

It’s the way the system is expected to work. And by the very nature of the way automations work it HAS to be that way.

There is no way to sense an automation that is enabled in the automation itself because as mentioned several times the automation is disabled when the trigger comes that it has been enabled.

Again, try to come up with a way that doesn’t require the automation to be disabled because that is generally bad practice.

Please explain the general bad practice part of turning on and off an automation.

From my point of view for each automation there is a process monitoring entities, services, etc. How limited they might be in resources, why should you take up these resources when not needed? Again from my point of view doing some actions when an automation is being restarted is nothing more than executing some commands after an IOT device has been woken up. I can create an automation that monitors the state of the automation and will execute some actions when states change (like broadcasting a message what automations have been turned on).

Optimally, an automation should work only when required. In other words, its designed to execute its actions only for specific reasons and not execute them for all other reasons. It should make decisions without manual intervention.

It shouldn’t need to be taken in and out of service as part of its normal operations. Reserve the act of disabling an automation for maintenance purposes. More here:

1 Like