Check state of entity in a set timeframe and trigger automation

Hi,
I want to check if a device is unavailable every day during a certain timeframe, and if it’s true would like to trigger HA to restart.

Note that I DON’T want to check if a state CHANGES within that timeframe. For my use case that change to “unknown” can also happen before. I basically just want to trigger the restart of HA only during that timeframe, not every time when there is a state change.

Will that do the trick?

trigger:
  - platform: state
    entity_id:
      - switch.eve_energy_fdb7
    to: unavailable
condition:
  - condition: time
    after: "23:30:00"
    before: "23:45:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - service: homeassistant.restart
    data: {}
mode: single
trigger:
- platform: time_pattern
  minutes: "/1"
condition:
  - condition: state
    entity_id: switch.eve_energy_fdb7
    state: unavailable
  - condition: time
    after: "23:30:00"
    before: "23:45:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - service: homeassistant.restart
    data: {}
mode: single
1 Like

Thank you petro. What does minutes: "/1" do? is it like for 1 minute?

it runs the automation every minute on the minute

1 Like