Wait_time automation not triggering other automations

I have an automation with a wait_time trigger that turns off a switch, and another automation with a state trigger for the same switch. For some reason, the timer automation is not triggering the second automation (the automation is not registered as triggered in the Automation list in the web interface).

Is this expected? I was under the impression that automations trigger other automations.

The blueprint for the timer automation is:

blueprint:
  name: Timer Light
  description: Turn off light when after a timer.
  domain: automation
  input:
    target_entity:
      name: Light
      selector:
        target:
          entity:
            domain: switch
    wait_time:
      name: Wait time
      description: Time to leave the light on.
      default: 5
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: minutes

mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input target_entity
  to: "on"
  for:
    seconds: !input wait_time

action:
  - service: switch.turn_off
    entity_id: !input target_entity

A target selector input needs to be applied to a target configuration key, not an entity_id key. But since you need it in both the service and trigger it would be better to use an Entity Selector.

Also, you probably did this for testing, but your time units for the input and state duration don’t match.

blueprint:
  name: Timer Light
  description: Turn off light when after a timer.
  domain: automation
  input:
    target_entity:
      name: Light
      selector:
        entity:
          filter:
            - domain: switch
    wait_time:
      name: Wait time
      description: Time to leave the light on.
      default: 5
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: minutes

mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input target_entity
  to: "on"
  for:
    seconds: !input wait_time

action:
  - service: switch.turn_off
    target: 
      entity_id: !input target_entity

Thanks! I’ve made both of these changes, but the issue remains.
This timer automation is being triggered and the switch is being turned off, but then another automation that should be triggered by the switch being turned off is not triggered (when I go to Automation in Settings, the “Last triggered” column shows that an automation based on this timer is not trigger the other one).

To be precise, I found out today that in some rare cases the correct thing happens (the timer automation triggers the other one) but 90% of the cases it doesn’t! Is there a way to debug this?

Post the other automation.


For future reference, a State Trigger’s for option is cancelled when Home Assistant is restarted. So if it is set to 30 seconds and is in the middle of counting down to 30 seconds, that countdown is lost and reset on startup.

1 Like

@Taras, thanks. I am aware of this limitation, but I am sure that home assistant is not restarting. I am also testing with 10 seconds timers and can reliably reproduce the issue.

Here is the blueprint for the other automation (note however that the automation is not triggered at all, so the condition/actions in the automation are not relevant AFAIK):

blueprint:
  name: Synchronize states
  description: Synchronize the on/off state of 2 entities
  domain: automation
  input:
    entity_1:
      name: First entity
      selector:
        entity: {}
    entity_2:
      name: Second entity
      selector:
        entity: {}
mode: restart
max_exceeded: silent
variables:
  entity_1: !input 'entity_1'
  entity_2: !input 'entity_2'
trigger:
  - platform: state
    entity_id: !input 'entity_1'
    to:
      - "off"
      - "on"
  - platform: state
    entity_id: !input 'entity_2'
    to:
      - "off"
      - "on"
condition:
  - condition: template
    value_template: '{{ states(entity_1) != states(entity_2) }}'
  - condition: template
    value_template: '{{ trigger.to_state.state != trigger.from_state.state }}'
  - condition: template
    value_template: '{{ trigger.to_state.context.parent_id is none or (trigger.to_state.context.id != this.context.id and trigger.to_state.context.parent_id != this.context.id) }}'
action:
  - service_template: >
      {% if trigger.to_state.state == 'on' %}
      switch.turn_on
      {% elif trigger.to_state.state == 'off' %}
      switch.turn_off
      {% endif %}
    data_template:
      entity_id: >
        {% if trigger.entity_id == entity_1 %}
        {{ entity_2 }}
        {% elif trigger.entity_id == entity_2 %}
        {{ entity_1 }}
        {% endif %}

I add both automation from the blueprints as:


- id: '1609505285530'
  alias: Synchronize fan with athomplug
  description: ''
  use_blueprint:
    path: synchronize-the-on-off-state-of-2-entities.yaml
    input:
      entity_1: switch.kitchen_fan
      entity_2: switch.athomplug

- id: '1611318399062'
  alias: Timer - AthomPlug
  description: ''
  use_blueprint:
    path: timer_light.yaml
    input:
      target_entity: switch.athomplug
      wait_time: 10

I am expecting that the “Timer - AthomPlug” turns off the switch “switch.athomplug”, and that the automation “Synchronize fan with athomplug” turns off the “switch.kitchen_fan”. The latter automation works flawlessly when I turn the switches on/off myself rather than through a timer.

this is not necessarily correct:

an automation is not considered triggered until the conditions are also met. so it’s possible that it’s trying to trigger, but then getting blocked by your condition and therefore not triggering.

one thing i’d do to check is to get rid of this condition block… at least for testing.

@armedad, when I check the Trace of an automation, it shows me which conditions were true and which were false, even if ultimately the automation is not triggered due to a false condtion.

All the conditions (including the state ones) are to prevent repeated triggering of the automation. The automation synchronizes two switches, and I want to avoid turning on switch_1 which triggering turning on switch_2, which triggers turning on switch_1 again… etc.

When I remove these conditions, I invariably end up in situations when the automation keeps getting triggered which makes testing difficult.

for that one that syncs 2, any reason you don’t use:

@armedad, I use an earlier version of that blueprint, but the logic is not that different between the two (the one you linked allows more than two entities which I don’t need)

Check the second automation’s trace. It’s probably triggering correctly but its multiple conditions occasionally prevent it from executing its actions.


On a separate note, throughout this topic you use the word “timer” but nowhere in either automation is there an actual timer entity. A State Trigger’s for option isn’t normally described as a timer because it doesn’t simply count down the time (like a timer entity). It measures the amount of time an entity’s state value remains at a desired value.

It may behave outwardly like some sort of “internal timer” but, unlike an actual timer entity which can be started/paused/stopped and simply counts down time, it is automatically reset whenever the entity’s state value changes (or Home Assistant is restarted).

@Taras, thanks. Yes, I’ve done this. The second automation is not started at all (after the first one runs, the second one doesn’t run at all and the last trace is from an earlier execution).

Ah I see regarding the timer distinction. Thanks for the info. I don’t think I need the more complicated timer entity for now.

Update: I’ve now confirmed two tests (assuming a “wait_time” automation of 10 seconds on “entity_1” and a sync automation for “entity_1/entity_2”)

  • First test: Turn entity_1 on → “wait_time” automation starts → entity_2 is sync’ed on → wait 10 seconds → entity_1 is turned off → entity_2 is sync’ed off.

This is as expected.

  • Second test: Turn entity_2 on → entity_1 is sync’ed on → “wait_time” automation starts → wait 10 seconds → entity_1 is turned off

This is the issue, since the automation to sync entity_2 is never called. I am mostly unsure how to debug this, since there is no trace that I can check.