Please help with timers

I’ve been banging my head on this one for hours, please help.

I have a Z-Wave sensor on my pantry door and a controlled Z-Wave outlet to control the lights. I also want to alert if the door is left open, we don’t want the dogs to self-feed.

An alert is easy, and that works just fine. I was impressed when I stumbled upon that component. However, I have Aeotec Doorbell Gen 5’s that I want to play a sound after two minutes of the door being open and every two minutes afterwards. As there doesn’t seem to be an easy way to plug that into the notification system to use an alert I need to implement an automation.

Here’s the alert, which works well:

alert:
  kitchen_pantry_open:
    name: "Pantry door left open"
    entity_id: binary_sensor.pantry_door
    state: 'on'
    repeat: 2
    skip_first: true
    notifiers:
      - house

Now here is the automation, complete with debugging:

automation:
  - id: Kitchen Pantry Open
    trigger:
      - platform: state
        entity_id: binary_sensor.pantry_door
        to: 'on'
        from: 'off'
    action:
      - service: notify.jeff_mobile
        data:
          message: "Timer Start"
      - service: timer.start
        entity_id: timer.kitchen_pantry_alert
  - id: Kitchen Pantry Timeout
    trigger:
      - platform: event
        event_type: timer.finished
        event_data:
          entity_id: timer.kitchen_pantry_alert
    condition:
      condition: state
      entity_id: alert.kitchen_pantry_open
      state: 'on'
    action:
      - service: notify.jeff_mobile
        data:
          message: "Timer Repeat"
      - service: timer.start
        entity_id: timer.kitchen_pantry_alert

timer:
  kitchen_pantry_alert:
    duration: '00:02:00'

What works:

  • I get the “Timer Start” alert
  • If I manually start the timer, I get the “Timer Repeat” alert and it repeats if the door is open

What doesn’t work:

  • The timer is never started by “Kitchen Pantry Open” automation.

I assume that I’m missing something obvious.

I’m running the Home Assistant container which is currently at 0.90.1. All that code is in a package. I’ve tried separating the automations out into a separate file, that did not change the behavior.

Thanks.

Jeff

try putting "initial_state: ‘on’ " in the automations and then reload automations.

example:

automation:
  - id: Kitchen Pantry Open
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: binary_sensor.pantry_door
        to: 'on'
        from: 'off'
. 
.
.

Ah, that explains a lot. I assume that any time an automation fails it is marked as ‘off’?

By default the state of the automation (on or off) should always retain the same state it was in before you restart HA or reload automations. But there is one situation that the state will default to off and that is if you don’t allow HA to fully start up before you restart HA again the automation will lose its retained state and will be in the ‘off’ state.

And I think that now by default the automations are created in the off state so if you don’t turn them on they will never be on and hence they will never run.

if you put in the “initial_state: ‘on’” then no matter what the prior state was then the automation will always be initialized to the state being ‘on’.

I’m not sure what you mean by an automation “failing”.

I was wondering if the initial state being off was caused by errors in my actions. I’ve only been using HA for a few months so I’ve been tweaking my automations and trying to get things right, which results in a lot of action failures. I was wondering if that was what was causing the initial_state to be ‘off’.

no.

I have to write more than that since there is a minimum character count in a post…:wink: