#Automation using When and And If

1 messages · Page 1 of 1 (latest)

fervent prism
#

I am confused as I'm trying to understand the difference between When and And If when it is time based automation.

Trying it both seems to behave differently but I am having a hard time understanding on how it work. So I am trying to tie into my alarm system. My wife and I love going out and most of time we are gone for 2 hours or more. I do not want to keep remembering to turn on lights so it looks like someone is home. So Currently when I use When time and alarm.

When Alarm changed to Armed and If time is after 6pm turn on lights = it works

but!

When time is 6pm and if Alarm = armed it doesn't work.

What is the difference?

jolly fox
#

"When" is a trigger. When the trigger occurs, it kicks off the automation to be processed.
"And if" is a condition. It is checked at the time the automation is triggered.

#

What does "it doesn't work" mean?

#

Note your first example will trigger anytime the alarm becomes armed during the night, and could happen multiple times.

Your second example will only turn on the lights, exactly once, at exactly 6pm if the alarm is armed. If you arm/unarm it later in the night, nothing will happen, because it is not triggered

fervent prism
#

That does make more sense. It was bit a struggle. My plan is that I want to lights to turn on automatically any time after sunset or dusk only if alarm state is armed. That's what I'm trying to achieve.

jolly fox
#

Sounds like maybe you want a mix of both:

Triggers:

  • When sunset
  • When alarm state becomes armed
    Conditions:
  • After Sunset
  • Alarm state is armed
#

That means at sunset, your alarm state will be checked, and if it is armed, the lights will turn on.
Additionally, anytime the alarm state becomes armed, if it is after sunset, the lights will turn on.

fervent prism
#

For trigger is it like an automatic "and' condition? or is it "or" condition? like When Sunset AND When arlarm state becomes armed? is that how Trigger works?

jolly fox
#

Triggers are always just a list of things that trigger. You can think of them like an OR

#

it would be impossible to "and" two triggers, because two things can never happen at the same instantaneous moment in time

fervent prism
#

That REALLY clears up my confusion. Thank you so much!!!

fervent prism
#

Actually small problem. It looks like I don't see sunset in And If option. Does Sun Next Dusk count as sunset? I know sunset means when sun start going down while dusk mean the list bit of sun fading.

#

This is what it looks like currently

north socket
fathom smelt
fervent prism
jolly fox
#

Next dusk is an attribute of sun.sun

fervent prism
#

That's the problem @jolly fox as what @fathom smelt said use "Sun" condition and I only get this

#

but if I use time.....I can get this

#

That's what perplexing me

jolly fox
#

If you want something other than strict sunrise or sunset, then the sun trigger is not for you.

fervent prism
#

Right. I Really want the Sun Dusk strictly.

jolly fox
#

I think easiest will be sun angle with numeric state

#

there's 3 dusks 😂

fervent prism
#

😅 ermmmm Let me just grab the one from weather.com dusk time hahahaha

jolly fox
#

probably civil dusk I think

#
trigger: numeric_state
entity_id:
  - sun.sun
attribute: elevation
below: -6
fervent prism
#

I think I got it. I'm gonna wait and see what happens.

fervent prism
#

I made 3 copies to see which works the best lol