[Released] Rule 4.0

Got this error from this rule, any thoughts on why @bravenel ?

*Anything you can help me with @bravenel ?

Hi people,
Is this a bug or with intention: I think there should be an option to choose a light for the stop color temperature change function... am I wrong?

@bravenel

FYI. I read your comment about state machines back when you made it, and it intrigued me. So for the last week, I've been working on an app for defining state machines in HE.

I'm a software engineer by trade, and I love state machines for certain applications. (Also the old saying about any class eventually becoming a state machine. The distinction is if you know that it's a state machine and plan it out, or you just allow states and transitions at random. The quote at the top of this article is excellent: How I Learned to Stop Worrying and ❤️ the State Machine)

So when I see people posting screenshots of their RM rules with multiple IF - ELSEIF - ELSE blocks with different conditions in each and they wonder why it doesn't catch an edge case, my engineer brain says "That's a place for a state machine!"

However, I'm torn over whether to release it or not. Even RM4 is edging into the point of being powerful enough for non-programmers to get themselves into a lot of trouble, as evidenced by those posts. It has the power to do recursive, iterative conditional logic. For users who aren't used to that kind of power, they don't realize the pitfalls. For professional engineers, we see certain patterns in code and think "code smell!" and then refactor and clean it up.

So for a professional, you see "smelly" code that can be simplified and more reliable by using a state machine. But the tradeoff is an additional level of abstraction. And for typical users, the abstraction of a well-defined state machine is not something they're used to seeing.

However, the most likely result is I release the app and no one uses it because it's too confusing. So I probably will release it when I feel it's ready.

One thing that would help me: what use cases would you want to use a state machine for? This is the first thing I've built for Hubitat that didn't come from one of my own needs. I've tried to keep my automations simple, and haven't needed a state machine yet. I'm just building it because it's cool.

To give an idea of the "spec" of my app:

  • ability to define "states"
    • a state is a child device that implements the "switch" capability, so you can use RM to perform actions either when you enter or leave a state.
  • ability to define "events"
    • an event is a child device that implements the "button" capability, so you can use any arbitrary RM rule or other app to trigger the event
  • ability to define "transitions"
    • a transition means that if you are in the "from" state, and the chosen event fires, the state machine should transition to the "to" state. (the from state turns off, and the to state turns on.)
  • don't re-implement RM. Rely on RM to perform actions from the state transitions. Rely on RM to trigger the events. Just be the core of the state machine that manages the state and transitions.
1 Like

Hi, wow!! i am pretty excited that I caught your attention. Right now i am up to my eyeballs with trying to upgrade from Sonoff-basics to the Tasmota-hubitat on 18 Teckin SP10 plugs so i can't divert right now (WAF #s woudl go way down!!)

But this was the original situation i got into when thinking that i should have recoded my RM with a state variable. Originally when i purchased my leak sensors i gave the HSM a go. I really didn't spend enough time with it but it did alert me to a leak sensor & then never again. Since leak sensors are pretty important to me, i didn't want to chance it to code that was hidden & i could not debug. long story short is this is my RM. I use contact switches that trigger alexa warning and those contacts get reopened by another rule.

I did have Alexa TTS installed, but the cookie thing makes it unreliable for something like this. My next project will be the Echo Speaks, but so far I have only been reading & not implementing.

You are absolutely right, with out limiting the inputs being looked at at each state, you can inadvertently have your code follow the wrong path at unintended time. With states, you can say - ok, this is what i am considering inputs/events/whatever at this time and all other conditions are ignored. it's all about the KISS principle !!

Maybe you would like to take discussion right now off the main thread, and i would hope that by early next week i will have time to devote to this.

This is just awesome!!

Steve

32 posts were split to a new topic: Help with my rules

Followup: My state machine code is ready for beta!

2 Likes

Feature request: Could something be added to make it easy to replace devices used in rules?

I have had to change some sensors around recently, and am finding that Rule Machine does not allow me to easily change the sensor used in a conditional expression. I instead have to re-do all conditions using the new sensor and delete the old one. This change would make a great addition, if it is something that can be done...

I did a quick search (research / finding these things is NOT one of my strengths :frowning: )but didn't find this as a request or an available work around other than re-creating the condition.

Thanks!

1 Like

This isn't necessary. On the Actions page at the bottom is the section to Manage Conditions. Edit the Condition that you want to change the device in, and it will allow you to deselect the sensor that is there, and select a different one.

6 Likes

Ah! This is great! I never realized I could do that... Only a couple months in using Hubitat and still a lot to learn! Thank you so much for this info!

1 Like

@bravenel - I was editing a pretty complex rule today and at some point it seems to have broken I see this whenever I try and edit the rule:

This is the rule in question:



It broke when I was trying to add a statement before the first on1(). I accidentally pressed END-REP, however I hadn't pressed the "done" yet so I pressed "cancel action" but then it broke the whole thing. Anyway to fix without redoing the whole thing?

No, unfortunately it is broken.

I would suggest that rather than one ginormous rule, you put some of its pieces in other rules, called by the main rule.

2 Likes

Ok.. I guess I'll just rebuild it. Whilst we are on this I think there are some issues with repeating actions. In the last day I have made a few rules with repeats and I have seen some odd errors:

  1. java.util.NoSuchElementException: Cannot pop() an empty List on line 6320 (doRepeatR) - gets thrown in the logs with one of my rules during the time that it is repeating.. although as far as I can tell at the moment.. the rule is working as intended
  2. In 2 cases the statement "Stop repeating actions" does not do what it is supposed to.. as in, the rule just keeps repeating anyway - I've checked that nothing else is re-triggering these rules. To get around this problem I added "exit rule" after the stop repeating statement and that appears to work at the moment.

Just a heads up

The "cannot pop()" error is due to simultaneous instances of the app running. This usually is a sign of it being over triggered. You need to turn on logging, and demonstrate a failure in the logs. Without logs, there is no way to know what is going on.

Ironically those 2 cases do not have the pop issue - and I have checked with logging on and they are not being over triggered.. the stop repeating actions just doesn't seem to stop it repeating, but exit rule seems to work

The pop issue is separate and affects only one rule

logs needed to see what is going on.

This is my 1st attempt at RM and wanted to know if this looks right?
image

Just not sure if i have the cancel delayed actions correct and delayed timer part correct?

Cheers

id put it at the beginning and once, (before the 1st IF)
also the delay need to be cancelable (toggle in the action)
only other thing (might need to test) i didnt think (mode asleep) you would need the on command, the set color and level might turn it on by default

1 Like

The ELSE-IF will run when the Ensuite sensor is either active or inactive and the other two conditions are met.

Thanks.
Will make the changes

After ELSE-IF i need to add ensuite sensor active aswell?
Thanks