Use an expression in a conditional statement

Here's the scenario. I travel a lot for work, some times a month at a time. There is a hand full of tasks I'd like to be reminded to do for every x days I am home. For example:

  • Descale the coffee machine every 60 days.
  • Run the cleaning cycle on the coffee machine every 45 days.
  • Change the water filter every 90 days.
  • Disinfect keyboard and mouse every 7 days.
  • etc...

In SmartThings of WebCore, I used to have a piston called Home tasks reminder. There's a global variable called At home counter, where the number goes up for every night I am home. Then I divide this At home counter variable with x days(days required for tasks). If the remainder is zero, then execute a task.

Here is an example code for descaling the coffee machine:

If At home counter%60 == 0
{ Create a task on Todoist, "Descale the coffee machine."}

How do I do the same thing on RuleMachine?

1 Like

OMGosh! I'd never thought of something like that! Just reading your post, I'm thinking "turn smartthings back on and hubconnect them so that you don't have to rewrite that piston"! Ha!
Seriously, .. definitely a very ingenious way to utilize smart technology. I'll be following the answers on your post.

2 Likes

Found this, but noticed it is deprecated since RM provides similar functionality?

I sold my SmartThings hub already haha

1 Like

Thanks.. but doesn't sound like that app can do what I need.
I don't need to be reminded every 60 consecutive days, it's every 60 days I am home. Because certain things at home doesn't have to be maintained if they are not used.
For an extreme example, It is possible that I descale my coffee machine, then I am gone for work for 2 months. I don't want to be reminded to descale my coffee machine when I'm back from work... Because I simply have not been using it.

I would just use RM for that. Set up a counter (most likely a global variable but you can also use a local one if only 1 rule needs to access it) . Every day you are at home (based on mode or whatever virtual switch you use to indicate presence) add one to the counter. Then send a notification when the number of days is reached (this would be a simple test to check the value of the variable at a certain time each day). Or count down instead if that logic suits better. You can show and set a global variable in a dashboard too using a connector so that would provide a reasonably nice UI for this.

Alternatively you could use the number of times the power is on if you used a smart plug for the device. I do something similar for my nebulizer to send me a notification to check the oil level after it's been used 25 times (you can search for that recent post under my name).

That's all clear, I had already done this once on WebCore, so the programming is clear. My challenge is writing "If At home counter%60 == 0" on RuleMachine/HE, i want it to be an expression so i don't have to write If At home counter == 60 or If At home counter == 120 or If At home counter == 180 or If At home counter == 240 ... For each task in rule machine...
By checking the remainder, I can use the same counter for all tasks.

If At home counter%60 == 0
{ Create a task on Todoist, "Descale the coffee machine."}
else If At home counter%45 == 0
{ Create a task on Todoist, "Run the clean cycle on the coffee machine."}
else If At home counter%90 == 0
{ Create a task on Todoist, "Change the water filter."}
else If At home counter%7 == 0
{ Create a task on Todoist, "Disinfect keyboard and mouse."}
else
{ nothing }

If you're a programmer, it might be pretty simple to write a custom Groovy App to handle this. This way you'd have access to more math functions versus what Rule Machine exposes.

I see. I guess in HE you will need a separate counter variable for each event you are trying to count down/up to. At least that's how I'd do it. I don't feel it's any more complex than the code you show above.

For me, I'd use individual counters down, because the continuous up-counting without any reset will eventually lead to a large number with no obvious value. If you look in at down counters, you have an instant idea of the future, whereas looking at "2743" really doesn't tell you that your next coffee machine clean cycle is in 2 days. At the very least, if you're counting up, find the LCM of your cycles (in this case, 630), and do a reset to zero when you increment to that number.

I'd also use variables (either global or in the rule) instead of the constants, so that (eventual) cycle length changes would be easier.

2 Likes

I'm not a programmer, but i have taught myself few languages.
That's not a bad idea actually, to write my own app. I might just try that.
I guess the conclusion is that RuleMachine doesn't have the same level of capability compare to WebCore, at least not yet.

1 Like

And likely never will. Rule Machine runs locally on the hub, with limited resources. webCoRE runs in the cloud with virtually unlimited resources at it's disposal.
Many folks have had issues running webCoRE on their hubs but there are many of us that still run webCoRE with a limited number of Pistons. Myself I run only one piston presently just because I haven't had the time to move it over to a custom Groovy app yet. But I see no system degredation because of it and my hub runs snappy and consistently without issue. So, if you want to try installing webcore and importing your piston over, there is a set of converted apps that have been optimized for Hubitat.

Thanks for the recommendation, that might be the ideal approach for RuleMachine.

note webcore is local on habitat, and now it is very efficient (very comparable to rule machine in performance)

2 Likes

I'm using 5 webCoRE pistons that, as @Ryan780 and @nh.schottfam has eluded to, do not impact my hub performance.
I suppose that best way is to import it and give it a go.
Maybe also install @bptworld's Hub Watchdog before you do, copy in the piston and see if there is any impact on your hub. You might be pleasantly surprised. :wink:

1 Like

Focused and slim is the name of the game with webCoRE in Hubitat. Cut down on your global variables and don't have a lot of cross piston triggering. If you stick to those rules, it can still work extremely well.

1 Like

Download the Hubitat app