Motion turn on / off

I have a motion sensor in my Living Room. I'm trying to figure out how I can create a rule.

If motion is active and between Sunrise and 9am or Sunset and 11pm, turn on Living Room lamp. Turn off after 15 mins unless motion is active and reset timer.

TRIGGER
Motion Sensor 'changes'.

(Use a conditional action. IF - THEN)
RULE
IF
Motion Sensor is active
AND
(Time of day between Sunrise and 9am
OR
Time of day between Sunset and 11pm)
THEN
Turn On Lamp.
Cancel Delayed actions.
ELSE
Turn off lamp. Delay 15 mins (Cancel).
END - IF.

Do you mean "rule" literally, or just any automation that will do what you want? This would be pretty simple to do with Rule Machine, but Rule Machine itself is not simple if you're totally new to it. For this, I would use one of the purpose-built native apps like Hubitat Simple Lighting or Motion Lighting, both of which can do what you want (the former is easier to set up, but the latter has more options; maybe start with the first and move to the second as you get more comfortable or want more).

In the event you really did want RM, I'd be happy to show you one way it can be done, but reading the Rule 4.0 docs should go a long way for that--there's a basic motion lighting example in there, and all you'd need to add are conditionals for time wherever you see fit (but there's more to think about: do you want it to still turn off if it was turned on inside this timeframe but is outside of it when motion stops, for example).

So maybe something like this?

IF (Time between Sunrise+45 minutes and 11:59 AM EDT(F) OR
Time between Sunset+45 minutes and 11:00 PM EDT(F) [FALSE]) THEN
On: Living Lamp 2, Living Lamp 1
Delay 0:15:00
IF (Living Room inactive(T) [TRUE]) THEN
Off: Living Lamp 2, Living Lamp 1

You are not turning the lights on with motion.
Have a look at what I have put above.
This uses RM4.
If you need more help, let me know and I can PM you if you wish.

I want my lights to turn on with motion and off when motion stops after a certain amount of time. I think I'm going to try the Motion Lighting app again.

So I setup the Motion Lighting app. Looks like I'm going to have to do 2 of these. One for Morning and one for Night.

Morning:
If Living Room Motion is active, turn on Living Room Lamp 1, Living Room Lamp 2 only between Sunrise and 9am. Wait 15 mins, turn off.

Night:
If living Room Motion is active, turn on Living Room Lamp 1, Living Room Lamp 2 only between Sunset and 11pm. Wait 15 mins, turn off.

I'm I correct in having 2?

Personally I do not use Motion or Simple lighting. I have everything on RM.
Looks good to me though.

Have you seen this BTW.
https://docs.hubitat.com/index.php?title=Hubitat_Elevation_Documentation#App_Documentation

I like RM also but I just can't seem to get it to do what I want.

Should you try RM4, this is how I would try it.
image

1 Like

You need to put sub-expression brackets round the 2 time statements as in my example above.
Plus you have missed the 'Cancel Delayed Actions' statement.
Also, and it doesn't matter with this rule, its good practice to finish with an END-IF.
It's a learning curve I know but once you get the hang of it I'm sure you will be defining more and more complex rules. :smile:
image

image

1 Like

I hope so since I linked to two specific app documentations in my first post, though as of now neither has been clicked. :slight_smile:

Creating the rule as above is a good place to start if you do want to learn RM, but keep in mind that Hubitat has lots of native apps built for specific purposes, including two that could handle your situation above with a lot less effort. If you're totally new to Hubitat, I might suggest starting there first, then moving to RM if you want to as you find things you're unable to do with stock apps or want more control than they provide--no need to make your life more complicated than it needs to be right off the bat. :slight_smile: (And yes, you would need two child apps to handle this split time as is, but you may also wish to consider using modes--maybe two like "Morning" and "Evening"--and restricting lights on to these modes only.

1 Like

That wasn't actually meant as a comment to you but to the OP. :slight_smile:

I understand--just pointing out that they do not appear to have read it. :slight_smile:

Not quite--you have:
IF (Living Room active AND Time between Sunrise-45 and 9 AM OR Time between Sunset-45 and 11 PM)
but you want:
IF (Living Room active AND (Time between Sunrise-45 and 9 AM OR Time between sunset-45 and 11 PM))

The difference is because AND and OR both evaluate left to right with equal priority, which affects the result of the Boolean algebra. Imagine a situation where the sensor just became inactive (triggering the rule) but it happens to be inside one of the time conditions:
False AND False OR True = True
False AND (False OR True) = False
The first would cause the light to turn on even though motion just became inactive.

You're also missing the entire ELSE block, so nothing will happen (if the conditional is written correctly) when the sensor becomes inactive. What you have now would more or less work without this addition, but it will just blindly turn the lights off 15 minutes after motion starts even if it's still active. You probably want to do what was suggested by the other poster there.

Have I mentioned Motion Lighting? :slight_smile: That or even Hubitat Simple Lighting could handle this situation with a lot less effort. You'll need two child apps, as you discovered, but there's nothing wrong with that. If you only want one app for some reason or you plan to use these same time restrictions somewhere else (say, in other automations), you could even use mode instead of explicit time restrictions--say, a "Morning" mode active from 45 minutes before sunrise until 9 AM, and an "Evening" mode for sunset-45 until 11 PM. Mode Manager can handle automating that for you, and I'd suggest something like a "Day" and "Night" (or "Sleep") mode in between.

If you're not familiar, modes are basically a global state you can use to restrict any automation (every app is supposed to have the ability to at least simply run or not run based on mode; some incorporate ability to choose different specificities based on mode). You could create something in Motion Lighting and make it only turn on lights when in Evening or Morning mode--and if it's a particularly dark (or bright) day, you can even manually change mode at will and your automations will follow. Pretty neat, I think--which is why I use mode in nearly all my lighting automations.

Please, please, please read my posts.
I've shown you an example of what you are trying to achieve. I've also shown you where the sub expressions are in the menu. :slight_smile:
Good luck.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.