#Advanced motion / light automations

1 messages · Page 1 of 1 (latest)

eternal locust
#

Hi there,

brand new member here, quite newb in all things Home Automation (software, hardware, ...)
but in IT / tech / dev for my work and hobbies, so rather "tech savvy".

For now I'm just fiddling around with a few smart relays for my existing lights, and "basic" motion sensors (meaning: PIR w/o luminosity sensor).
I got everything set up and working.

Here is what I wish to achieve, and I was wondering what the best approach would be. I could for sure come up with some working automations by myself, but since I already read that some "obvious" ways to do this (e.g. with timers etc.) were not best practice (like long timers...), I'd be curious to know how experienced users would tackle it.

I don't really need "the code" here (like yaml/jinja...), this I can figure out, but more the logic* to organize this in differetn automations and such.
(* : I wanted to say "the blueprint" but this has of course its own meaning in HA)

I hope this will be clear enough, but if not let me know.
Any advice/help/input will be much appreciated.

#

These are my needs, as an example with my hallway ceiling light :

  1. turn on light when motion is detected, then turn off after a couple of minutes (based on time of the day)
    this one is easy and already done, don't need help here.

  2. but when light is turned on using the smart switch (whether 1. already triggered by PIR or not), keep it on until switched off.
    For this I already set up a boolean helper, set to true or false when the switch is used to control the light.
    So it's easy to add a condition in 1. to not turn off.

    Then I also need these additional behaviours :

    2.a. in any case, still turn it off after say 1h (yeah, we tend to forget the lights...)
    But here I'm not sure how to trigger the turning off after 1h, since I guess this is the kind of "long timer" that should be avoided.
    What's more, this turning off the light after 1h should of course not happen if at that very moment, there is motion detected.

    2.b. we should also be able to override this switching off after 1h (whatever the way: turning on another helper in the app, or a scene... that's not the point, but feel free to advise)
    because when we go out (to dinner f.i.) and leave the dog at home, we want to keep a couple of lights on.
    Then, when we get home (I know how to detect one of us is "at home"), disable the override to get back to the general "1h light time out")
    But maybe do this (disable the override) only after 1h of us being away, just so it doesn't get disabled if we just immedialtely re-enter to grab something we forgot (you get it, the "forgetting" factor happens a lot).

eternal locust
#

Actually now that I've written it down, I guess 2.b. is probably just a matter of using a specific "go out without the dog" scene that would turn on a couple of lights, set a boolean helper to true to override any auto-extinction rule, then when we get back home, either completely stop the scene or just unset the override helper.
But I'd still need some advice as to how detect us back home only after 1h of being away.

I guess it all basically boils down to : what's the best way to trigger an automation a certain amount of time after another one was run...
But maybe I'm missing something.

leaden raptor
#

you could use a timer helper entity. start the timer when you turn the light on, and then use the timer finished event to trigger an automation which performs any extra checks desired before turning the light off (or potentially even restarting the timer). Then you can cancel the timer to stop the second automation from running, or have certain events add more time to the already-running timer.

#

(timer helper entities are pretty handy for many types of "i want to do something later" automation; they can even be configured to survive a home assistant restart, which a long-running automation cannot do)

eternal locust
#

ok thanks, I'll look into those timer helpers.

but right now, I'm having a hard time discriminating whether the light was turned on by flicking the switch, or by the motion sensor...

Whatever I'm trying, if I set an automation to do something upon "switch changing to on" (I tried with my above mentioned boolean helper, but it would be the same with the timer helper), it is triggered both when I physically flick the switch AND when the motion sensor triggers its automation...

So I really don't get how I can make the physical flicking trigger any dedicated automation (even just setting a helper) that the motion triggered automation would NOT ALSO cascade-trigger when turning the light on...

any idea ?

eternal locust
dusk grove
#

Timers are fine. But for 2a you can just add a state trigger with a for. Like:

triggers:
  - trigger: state
    entity_id:
      - light.study_bulb
    to: "on"
    for:
      hours: 1
      minutes: 0
      seconds: 0

For 2b you can indeed you another helper. Or you could merge both helpers into a single input_select for example. But depends on how you want to interact with it.

eternal locust
#

thanks
yup, I just thought myself about using a single helper.

about your solution for 2a, where should this trigger go ? into a new automation that would turn off the light ?

or if I add as a secondary it to my "main" motion sensor automation, the whole would take care of all cases ?

dusk grove
#

Both are possible. I like to group everything that's related into a single automation and do whatś needed with choosers and trigger id's