Automation to check state

I have a toggle ‘helper’ that I want to check via an automation has been left ‘on’ between 10pm and 8am.

In the automation visual editor how do I get this working, if I add it as a state under trigger it’s looking for a change not it just being on as I hit the time.

If I remove the trigger part and add it as a condition “name of helper is on” set a time after and before it does nothing.

Automations must have a trigger. Think about how you’d do it manually. Do you mean you want to check if the helper was 'on' for the entire timespan? Would you want to check that at 8am?

If so, time trigger for 8am, state condition that the helper has been on for 10 hours.

If not, explain more clearly what you’re trying to achieve.

I want to know if a ‘entitiy helper toggle’ has been left ‘on’ or is turned on between 10pm and 8am immediately.

The change state of ‘on’ I can already achieve as state ‘on’ of an for entity you can select under triggers, I use this but only after 2 hours of having a state of on.

The problem is getting an automation to trigger when it’s already on as there is no state change.
For example entity on at 21:55… time elapses to 22:00 but automation doesn’t trigger as the state didn’t change it’s already at that state of on.

So check if it’s on at 10pm, and check if it gets turned on between those times. I’d write it like this in YAML:

alias: Check the thing
trigger:
  - platform: time
    at: "22:00:00"
  - platform: state
    entity_id: input_boolean.your_helper
    to: "on"
condition:
  - condition: state
    entity_id: input_boolean.your_helper
    state: "on"
  - condition: time
    after: "21:59:59"
    before: "08:00:00"
action:
...

Sounds like you need 2 triggers. One for the time being 10pm and one for the helper being turned on. Also 2 conditions for both the helper being on and the time being between 10pm and 8am.

Thanks this seems to work but just trying to get my head around it so I can learn and understand.

For the trigger either a time or the state change to on can launch the automation?
Under conditions both criteria have to be met so the entity is on and it’s between the time?

Does that mean once triggered at 10pm the automation continues to ‘run’ and check until the condition of the extended time finishes then that automation ends and won’t trigger again till 10pm?

There’s no “continues to run” about automations: it’s much simpler than you’re imagining.

The system is continually looking to see if any of the triggers should fire. In this case, it will trigger at 10pm; and it will also trigger whenever your helper goes 'on'.

Once a trigger has fired, it will check the condition block. By default, conditions are AND — all must be true for it to pass (although you can configure OR conditions). In your case, it must be both between 10pm and 8am, AND the helper must be 'on'.

If the condition block is passed, the action block is run, and that’s it done for this iteration.

So:

  • ooh! the helper’s gone on!
  • the helper is (obviously) on but it’s only 5pm, bail out.

Then:

  • ooh! It’s 10pm!
  • it’s in the valid time range, but the helper is now off, bail out.

Later:

  • ooh! the helper’s gone on!
  • it’s 11pm, and the helper is (obviously) on! Good to go!
  • run the action block.
1 Like