Is there a cleaner way to do this repetitive if/then rule?

Basically when the weather is >80, I want certain blinds in the sunroom to close for a couple hours and then open up.

Thanks

From what I can see it is not repetitive, you want to do different things at different times. You could break it up into separate rules, removing the need to define the times in both the triggers and the conditions, i.e. you wouldn't need the conditions.

5 Likes

I'm trying to keep the separate rules clean so I don't have a huge list. I guess the main question was if it's possible to not have to define the times in both the trigger and the condition while keeping everything neatly wrapped up in one rule as above.

I did see a neat feature in HA in a video where you could nominate which trigger caused the automation to fire and perform actions based on that, but I don't believe there is anything similar in RM.

The only thing that is like what you are asking is if you needed to use the exact same condition within the Actions section. You would only need to define the condition once, but I don't believe that is the case for a trigger.

One thing that does spring to mind is the use of hub variables. I don't know the limitations of using them and so whether they may apply here, but they may be worth a look.

You can control subscriptions in webCoRE.

Or use modes ie late morn , early afternnon, late afternoon.

Change mode based on time and the trigger(s)

2 Likes

Have you considered setting this all up in the Room Lighting app (using Time Periods)?

I'm not quite sure how the Temperature requirement would be integrated, but I gotta think there's a way to do it...

1 Like

I do something similar with waits. So if it's going to be hot that day it starts off some event's. Then I have wait until X time and do something else then wait until Y and do something else.

Make the required expression "private boolean=true". Move the temp to being a trigger. Add first action to set private boolean to false. You need to change your conditionals to be time ranges instead of just the time.

Required expression:
Private boolean is true

Trigger:
Temp is >80

Actions:
Set private boolean to false.
If(time between 9:30 am and 12:30 PM
     Close shades
     Open shades delayed 2 hours
     Set private boolean to true.
End if
###Repeat the above for the rest of the time periods.

The gap here is that if the temp triggers above 80 again after the shades are shut, they will open right back up. If you only want them to open once per time block, then change the "if" blocks to:

If(time between 9:30 am and 12:30 PM
     Close shades
     Open shades delayed 2 hours
     Wait for time equals 12:29
     Set private boolean to true.
End if

There are some flaws in that logic, like if it triggers outside of the window it will lock the rule from working.
The PB false would need to be within the if. Or move the PB true out of it.

Good catch. Should add a final action of set private boolean to true to catch that.

Couldnā€™t the temperature requirement just be a custom attribute for means to activate or turn off? Thatā€™s how I would try using Room Lighting with time periods.

If the above didnā€™t work correctly, Iā€™d still set up in Room Lighting but create an activator device. Then Iā€™d use Rule Machine to turn on/off the activator device based on temperature.

1 Like

There is no speed penalty (to my knowledge) of breaking up a rule into several smaller rules. Personally I find individual rules easier to maintain/edit.

3 Likes

I tend to agree with this. Although, I must admit, I have some rules that read like books compared to this. Modifying them later is always no fun.

I've programmed for almost 50 years, which proves nothing except that I'm old.
Anyway, what you've got there is exactly what I'd do.

But splitting it into 3 rules is also completely legit and arguably less code since you'd no longer need the if statements. OTOH, you'd have the same required expression in three different rules so it's more complicated if, for example, you later decide you want the temp threshold to be 72 instead of 80.

Congrats on the clean code.
M.

1 Like