Need help creating very basic Rule Machine sunset to sunrise rule

I currently have a rule in Basic Rule that turns outside lights on at sunset and off at sunrise. I have another rule that turns inside lights on at sunset until a certain time then off until a certain time and off at sunrise.

I am trying to convert both to Rule Machine but I keep getting lost in the terminology. Am I correct in understanding that RM only checks triggers at the indicated trigger time, for example at sunset? And so if the lights stay on during the day for some reason they won't get corrected until the next rule off (trigger) time? So running the rule will not correct accidental on or off other than at trigger times?

Can someone show me an example of a RM rule that would accomplish the above situations? I know this is very basic but until I see things that actually work I'm struggling to understand the concepts of trigger, conditions, actions.

For example, do I need to list every trigger I use in condition specifically, sunset, sunrise, specific time? And then do I connect those triggers to actions in statements in the conditions section. For example, when time is sunset, when time is sunrise, when time is certain time?

Presumably I can then create conditional actions that reference these conditions and triggers to cause things to happen?

I know that you are not using webcore, but you might look at the webcore documentation for triggers and conditions for a brief description. Webcore basics - triggers and condtions and triggers and conditions: what is the difference?

I.have similiar situations . You may want to look at muliple rules like i have instead of trying all in one overly complex rule.




Did you know you can import a rule from Basic Rules directly to Rule Machine? That might help you see how it would produce that same rule.

That said, here is how I would re-create both of those rules in RM:

For the first one, turning the light on at sunset, off at sunrise, and you want to be able to rune the rule at any point manually, then use a « Wait for expression ».

For the second rule, do I understand that you want it to turn on at sunset, then off at a certain time, say midnight, then also turn it off at sunrise (in case someone manually turned it on, as an example)? If so, this would be one way to do this in RM:

1 Like

I think it's important to understand the difference between events and states. A simple example is a door. The door has two states. It's either opened or closed. The event of opening a closed door will change the state from closed to opened. To relate this back to RM, triggers are events so the door opened would be the trigger. Conditions are states and would be evaluated as either True or False in the actions of the rule. For example, IF the door is open THEN turn on a light.

For time, certain time, sunrise, and sunset are all events. Between two times is a state so Between Sunset and Sunrise would be evaluated as true at 3:00 AM and false at 3:00 PM. A special case is using Time Is as a condition. Say sunset in your area today is 6:00 PM. RM would evaluate IF Time is Sunset as true between 6:00:00.000 and 6:00:59.999.

Here an example of how to do this in RM

Triggers:
When Time is Sunset
OR
When Time is Sunrise

Actions:
IF (Time is Sunset) THEN
    ON Light
ELSE-IF (Time is Sunrise) THEN
    Off Light
END-IF

This can be simplified by using ELSE instead of ELSE-IF since there are only two triggers but this shows the general idea. Events can also be included in the actions so here's another example that yields the same result.

Triggers:
When Time is Sunset

Actions:
ON Light
Wait for Event: When time is Sunrise
Off Light

You are correct that if the OFF action is missed for some reason in either rule the light will stay on all day. If that is a concern you could add logic (or a second rule) to check the light later and turn it off.

2 Likes

You use a trigger to get the rule to run the actions. So you need a trigger listed for anything that would make it necessary to take an action. So for the lights on and off at sunrise or sunset you would need sunrise and sunset for triggers. Then in the actions you would have an IF statement for it being sunrise to turn them on and an else statement to turn them off.

You could then have another rule that has a trigger of those lights being turned on to then have actions that say if it's after sunrise but before sunset to turn them back off.

Hope that helped and didn't get more confusing.

(@pseudonym gave great examples while I was typing that for the sunrise and sunset part.)

1 Like

Thank you everyone for your responses. They are very helpful, especially pointing out the ability to create a rule machine rule from a basic rule. I'm off to try the things you recommended.

I very much appreciate the support!

1 Like