How to create automation trigger if state doesn't 'change'

I have an automation to turn on my home alarm if no motion is seen downstairs for a certain time, certain switches are off etc all wrapped up into group.good_night_group.

The problem I had last night was the alarm set correctly when we all went to bed, but my weekly backup triggered at 2am and then when HA came back on group.good_night_group had the initial value ‘off’ but I think because it never went to ‘off for 14 minutes’, the alarm didn’t turn back on.

What’s the best way to fix this, so that when HA restarts all automations still behave as I want them i.e. for this one my alarm should have re-armed.

Thanks in advance

- alias: 'Alarm - arm alarm pending home'
  trigger:
      - platform: state
        entity_id: group.good_night_group
        to: 'off'
        for:
            minutes: 14
  condition:
        condition: and
        conditions:
        - condition: time
          after: '23:30:00'
          before: '05:25:00'
        - condition: state
          entity_id: person.home_occupied
          state: 'home'
  action:
      - service: notify.notify
        data:
            title: "Alarm arming (home) in 1 mins"
            message: "{{ as_timestamp(now()) | timestamp_custom('%I:%M%p', true) }} Alarm will arm (home) in 1 min"

Can you please also show the automation that turns off the alarm?
I don’t see a reason why the alarm should have been disarmed during the weekly backup or do you have the alarm set to be disabled on startup?
I also don’t see any action that actually arms the alarm in your automation, only a notification that it will get armed in a min.

Sounds like the server is stopping for the backup?

One way is to check using the following trigger:

  trigger:
    platform: homeassistant
    event: start

Thanks - that makes sense. So add another trigger:

      - platform: homeassistant
        event: start
        for:
            minutes: 14

Edit: can’t do ‘for’ - need to rethink

Do you not have the possibility to do a “live” backup? My server doesn’t restart during backups.

No, write another automation. Trigger on restart but check all your states/time in the conditions.

Burningstone has suggested the best option though.

I run HA in a docker in unRAID and my dockers are stopped and backed up weekly at 2am

Thanks. I’ve come up with a way to fix the alarm the same way I do my lights. I use timers which are restarted at HA startup, and the automations start if the timer finishes i.e. I’ll create a new timer timer.alarm_home

- alias: Startup - Alarm
  trigger:
      - platform: homeassistant
        event: start
  action:
      - service: timer.start
        entity_id: timer.alarm_home

- alias: 'Alarm - arm alarm pending home'
  trigger:
      - platform: state
        entity_id: group.good_night_group
        to: 'off'
        for:
            minutes: 14
      - platform: event
        event_type: timer.finished
        event_data:
            entity_id: timer.alarm_home
  condition:
        condition: and
        conditions:
		  - condition: time
			after: '23:30:00'
			before: '05:25:00'
		  - condition: state
			entity_id: person.home_occupied
			state: 'home'
		  - condition: state
			entity_id: group.good_night_group
			state: 'off'
			for:
				minutes: 14
  action:
      - service: notify.notify
        data:
            title: "Alarm arming (home) in 1 mins"
            message: "{{ as_timestamp(now()) | timestamp_custom('%I:%M%p', true) }} Alarm will arm (home) in 1 min"

I don’t think you can use “for” in a condition, only in a trigger. Does your automation work?

I haven’t tested it but I’ve done similar in other automations, so yes

Ah yes you can, just saw it in the documentation, sorry for the confusion.