Automation just stopped working

Hi there,

I’m losing my mind over this, my automation just stopped working for no reason at all. I made one change, reverted it, and ever since it just will not work. I followed this guide. My set up is EXACTLY the same. I don’t understand what the problem is, it worked earlier.

input_number:
    bedroomac_timer_minutes:
        name: "Bedroom AC Timer"
        min: 10
        max: 360
        step: 10
input_boolean:
    bedroomac_timer_on:
        name: "Bedroom AC Timer Switch"
        initial: off
        icon: mdi:timelapse

Edited automation in visual editor:

TRIGGERS

platform: state
entity_id: switch.bedroom_ac
to: 'on'

CONDITIONS

condition: state
entity_id: input_boolean.bedroomac_timer_on
state: 'on'

ACTIONS

delay:
  minutes: '{{ states(''input_number.bedroomac_timer_minutes'') | int }}'

service: switch.turn_off
target:
  entity_id: switch.bedroom_ac

Any help would be massively appreciated. It makes no sense.

I’ve tried run action directly from the Automation. That seem to work successfully, it’s just not triggering with anything else.

The step details also say the following:

Result:

result: false

entity_id/0
Executed: 25 July 2021, 19:26:38
Result:

result: false
state: 'off'
wanted_state: 'on'

Before you read the rest of my post, first confirm the automation is enabled. It’s possible to manually execute a disabled automation but it definitely won’t trigger.


Where is the configuration for switch.bedroom_ac? Is it automatically created by some integration you are using?

Go to Developer Tools > States, find switch.bedroom_ac see what it reports as its current state (should be on or off).

Once you find it, click the entity and its information will populate the form at the top of the page. In the State field, change off to on then click the Set State button. That will change the switch’s state to on and trigger your automation (because it is using a State Trigger to listen to the switch for a change to on.

Let us know if that worked or failed.

BTW, don’t post a summary of an automation. Post its YAML code. In the Automation Editor, click the overflow menu (three vertical dots) and select ‘Edit in YAML’. Copy the displayed YAML and paste it here.

switch.bedroom_ac is a tasmota switch, added by MQTT. It works fine with other automations.

I’m not trying to trigger it from switch.bedroom_ac being on I’m trying to trigger it from input_boolean.bedroomac_timer_on being on. As I say this worked fine before but now it doesn’t. I’m assuming the changes I made and reverted have caused a bug.

The yaml version is below, though I didnt post a summary to begin with:

alias: Bedroom AC Timer
description: ' '
trigger:
   - platform: state
     entity_id: switch.bedroom_ac
     to: 'on'
condition: 
   - condition: state
     entity_id: input_boolean.bedroomac_timer_on
     state: 'on'
action:
   - delay:
       minutes:  '{{ states(''input_number.bedroomac_timer_minutes'') | int }}'
   - service: switch.turn_off
     target:
       entity_id: switch.bedroom_ac
mode: single

That’s not what your automation is doing. Its State Trigger is clearly listening for switch.bedroom_ac to change to on.

After it changes to on, the condition checks if the input_boolean is also on.

Call it whatever you want but unless you post YAML code, no one can vouch for its validity.

So it was working before now on a fluke and a prayer?

I followed the linked post in my original question, it does that too unless there’s something I’m missing.

I’ll try changing things.

I can’t comment on what happened in the past but I can assure you that what you posted above is not designed to trigger on the input_boolean’s state-changes.

The linked post uses a State Trigger to listen to light.treelamp and not the input_boolean.

I assume the switch must have been in an on state then but not reflected as such on the UI which lead me down this rabbit hole of expecting something to happen that was the result of something that couldn’t / shouldn’t happen.

Turning on the switch.bedroom_ac then toggling the timer switch gives me the expected result I was looking for.

Next time I do this I’ll do it on more than a few hours sleep. Thanks for the assist.

If the goal is to automatically turn off the switch after a certain amount of time (but only if the input_boolean is on) then it can be done like this:

alias: Bedroom AC Timer
description: ' '
trigger:
  - platform: state
    entity_id: switch.bedroom_ac
    to: 'on'
    for:
      minutes: '{{ states(''input_number.bedroomac_timer_minutes'') | int }}'
condition: 
  - condition: state
    entity_id: input_boolean.bedroomac_timer_on
    state: 'on'
action:
  - service: switch.turn_off
    target:
      entity_id: switch.bedroom_ac
mode: single

Be advised that any automation that employs delay, wait_template, the for option, timers, etc doesn’t survive a restart. That means if you restart Home Assistant while a delay is underway, its countdown is lost on startup. In other words, your original automation, and the one I posted, will fail to turn off the switch.

There are ways to make robust automations whose countdowns survive a restart but they are more complex.

1 Like

Yeah thats what I have now albeit ordered differently (I did it with the UI).