Problem with state_changed for a timer update


I have a timer that is triggered by an automation that is fed the timer duration via an input_number slider. I would like to be able to update the duration via the slider and not have to wait for the timer to count down to zero before it takes effect. I made an automation that should be triggered by a state_change in that slider that is supposed to cancel the running timer, update to the new duration and restart the timer - but I am getting the following errors on HA restart:

Invalid config for [automation]: expected dict for dictionary value @ data['trigger'][0]['event_data']. Got None
extra keys not allowed @ data['trigger'][0]['entity_id']. Got None. (See /config/configuration.yaml, line 23). Please check the docs at
Invalid config for [automation]: [event_type] is an invalid option for [automation]. Check: automation->trigger->0->event_type.

I have been playing with whitespace variations for well over 4 hours and am about to lose my shit. Can anyone point me in the right direction?

Here’s the automation:

- id: 'au_airex_timer_update'
  alias: airEx (update timer)
    platform: state
    entity_id: input_number.airex_duration
    event_type: state_changed 
    - condition: state
      entity_id: timer.air_ex_timer
      state_not: "idle"
    # Cancel already Running Timer
    - service: timer.cancel
      entity_id: timer.air_ex_timer
    # Start modified Timer
    - service: timer.start
        entity_id: timer.air_ex_timer
        duration: "{{ states.input_number.airex_cyclefreq_hours.state | int }}:{{ states.input_number.airex_cyclefreq_mins.state | int }}:00"
    - delay: '00:{{ states("input_number.airex_duration") | int }}:00'
    - service: switch.turn_off
      entity_id: switch.air

Take out this line. It will trigger when the state changes without it.

event_type: state_changed

Hello Jeremy;

I commented out that line and it still won’t restart. Getting this error now:

Invalid config for [automation]: extra keys not allowed @ data['condition'][0]['state_not']. Got None
not a valid value for dictionary value @ data['condition'][0]['condition'].

Sorry I didn’t look at the entire Automation. Use a template condition instead like this:

    - condition: template
      value_template: '{% if states.timer.air_ex_timer.state == "idle" %}false{% else %}true{% endif %}'

Check out the documentation for more here…

I’m sending from my phone so i hope I didn’t make a typo. Try it and see

I just managed to get it to restart. I took out the “state_not: idle”, opting for “state: active” - i guess that probably does the same thing as that template. I’ll see what happens once I test it. I have no doubt your template will work though.


1 Like

So that worked great! Timer runs fine and I can change it on the fly. Thanks for your help Jeremy!

Great! Glad to hear it’s all working now