Rule to set night mode

Hi all

Trying to get my head around Rule Machine 4.0

I am trying to get it to set mode to night and turn loads of things off, when there is no motion on 3 PIRs and 3 room switches are all off for 10 minutes, during which can cancel if any motion is then detected or a switch turned on, indicating someone is still up.

Further conditions are mode must be home and time between 23:00 and 00:30.

Is the following the correct way to do it?

Select Trigger Events

Kitchen, Diner, Lounge, PIRS: any changed
Kitchen, Diner, Lounge, Switches: any changed

Select actions to run:

IF(Kitchen, Lounge, Diner PIR all inactive) AND (Kitchen, Lounge, Diner Switches all off) AND (Mode is Home) AND (Time is between 23:00 and 00:30)

THEN IF (Private Boolean is TRUE)

Set Private Boolean False

Delay 10:00 (cancel)

Set mode: Night
Off( loads of stuff)

ELSE

Set Private Boolean TRUE

Cancel Delayed Actions

ENDIF

If you write it exactly like that, you have a syntax error (but not one RM will complain about--a missing END-IF, which it will try to fill in for you at the end of your rule, which is not where you want it). I'd try something like this instead for the actions:

IF (Kitchen, Lounge, Diner PIR all inactive AND
    Kitchen, Lounge, Diner Switches all off AND
    Mode is Home AND Time is Between 23:00 and 00:30) THEN
  Delay 0:10:00 (cancelable)
  Set Mode: Night
  Off: [whatever devices]
ELSE
  Cancel Delayed Actions
END-IF

I also got rid of the Private Boolean since I don't think it's doing anything for you and simplified the resulting structure a bit (no more nested IFs, which also eliminates the possibility of creating the syntax problem I mentioned above). If either of these was doing something for you that I'm not seeing, you should be able to add them back in--what you have looks fine except for the missing END-IF before your ELSE. The rule looks good to me otherwise.

Good luck!

1 Like

Thanks.
I am trying to make it as simple as possible, so yours probably wins on that front.
Will tweak it later.
So in your example, do I still need another END-IF, before the ELSE?

No; the way I wrote it is as it should be. Each IF needs one matching END-IF, which should enclose the chunk of actions that you would like conditinally exectued (optionally with an ELSE in the middle). I'm not sure if it was just a typo/omission in your original rule, but you have two IFs and likely meant to end your second before your ELSE, otherwise you'd have a lot of code under there you probably didn't meant o have. This would likely become more apparent if you actually built this rule, as RM helpfully indents actions to show you what IFs (and similar enclosures like Repeats, etc.) they fall under.

Doesnt appear to be working as planned. Any ideas

This is how it is currently setup:

Is it because I have left the triggers in, when actually I donā€™t need them for this rule

That shouldn't be a problem, but what do you mean that you don't need the triggers? If you don't need them, take them out, but since you said that I'm less sure what you're actually trying to do. Perhaps you mean that you don't need the switch states as triggers; you likely don't since if you turn off a switch, you'd probably be there to generate motion that the other trigger would already handle, but I don't know your desired use case and outcomes in all circumstances.

Also, when you say that it's not working "as planned," what do you see that is different than expected? I might be missing something, but it looks good to me. The only thing I could see is that if motion goes inactive at, say, 12:55 AM and then you come back in at 1:04 AM (generating motion--or with your current triggers, even just turning on a switch without motion or turning off a switch that was on when one or more others remain on), it won't turn off all the switches and go into night mode since that would be enough to cancel that, then if inactivity again stops at 1:04 AM it won't schedule this again since it's outside your timeframe in the IF. Anything before that edge case looks like it would be OK, though.

Turning on logging for the rule may help you verify what it thinks is happening if you haven't tried that already when it isn't working as expected.

Hi
I have turned on logging. Where do I find them?

It didnā€™t work as intended as it didnā€™t put night mode on, as far as I can tell.

I was thinking of taking the triggers out as it then becomes a conditions only rule. Eg if this AND this are off then fire the rule, ELSE cancel within the delay period.

For me I need motion inactive on all PIR and the lights off to indicate Iā€™ve gone to bed etc. Although thinking about it, if my Wife accidentally leaves a light on the rule wonā€™t work.

I might just move to a time base rule to activate night mode at X time, which arms HSM as well, then do a separate rule to turn everything off when there is no activity for X minutes.
John

You'll find live logs in the "Logs" item on the left-hand list of the admin UI. If you missed something, the "Past Logs" button on that screen will let you see farther back, but I usually find that harder when I'm looking for something in particular. Enabling logging for your rules should put something in there each time a trigger event happens or it runs your actions, and it will let you see what it's doing (or skipping).

Just a guess: are you sure your hub is in Home mode? And is your time and location (check it in Settings) correct? Either of those would prevent your rule from engaging Night mode. You could also check the event history on all your sensors and switches to make sure they were inactive and off. Just one remaining on/active would also prevent this from happening. Logging may help, but you may also be able to do some digging yourself and see.

Your Actions section will never run unless you have Triggers (or call the rule from another rule). Triggers are what cause your actions to run; you can control what actually happens there based on conditionals like you have, but they alone will not cause anything to happen.

That is more or less how I have mine set up, but if something isn't working above (like time, motion, etc.), you're likely to run into the same problem.

Mmmmm, still trying to figure this Rule 4 out. Previously in Rule 3 you could just specify conditions and once met, the rule fired and carried out the actions.

Likely explains why my security lights rule also didnt work as I didnt put any triggers, just the conditions and actions.

What would you use as a trigger if you wanted some security lights to come on when mode was away and time between sunset and sunrise. To me that shouldn't need a trigger - merely if the conditions are met, carry out the action!

I will have a play again tonight and see what happens.

Rule actions can be quite powerful, and not everything that you want to test as a condition needs to be a trigger. Rule 4.0 makes you explicitly specify your triggers. Since you're apparently familiar with earlier versions of Rule Machine, I suggest reading the 4.0 docs to see what's changed and how you can convert previous thinking to the new paradigm ("classic" conditions no longer exist in that sense, for example): [Released] Rule 4.0

For your rule, you could try something like this:

Triggers: Time is sunset OR Time is sunrise OR Mode *changes*

Actions:

IF (Time is between sunset and sunrise AND Mode is Away) THEN
  On: Security Lights
ELSE
  Off: Security Lights
END-IF

You can customize this exact logic to do what you want. If you're mode is Away and it changes to something else, the lights will turn off, even if it's between sunset and sunrise. If mode isn't Away at sunset, the lights won't turn on but will if it becomes away any time before sunrise. I'm not sure if that's exactly what you're looking for, so again, you can tweak it for your exact desired logic. (Simple Lighting actually might be able to handle this without RM at all, but I haven't checked these exact restrictions.)

I did read the Rule 4 post, but missed read the bit around triggers, or in place of triggers using another rule to fire it.

Thats pretty much what I am after, but will cap it to stop working at 00:00, rather than sunrise

Eg, turn on outside light, wait for event 00:00 then turn off.

John