Comments in RM

Ok, I will bite back :wink:
I just use rule machine for complex logic BECAUSE simpler apps don't do it. As programmer, I like the power of rule machine. A while loop like this one (just some lines of a complex rule) is for me confusing:

In some weeks I don't remember that this is in fact a "while" loop, and I don't remember how I have done it. Second the need for a loop is a workaround for a device not always reacting on the first command.

The ability to add comments here like:

// This is the Rule Machine way to create a while loop
// Conditional actions -> Simple Conditional actions -> Repeat as action
// This loop is required to work around a problem with the Spirit device not always reacting on a command. Has to be reevaluated later (if fixed)

may be very useful once the rule takes 40 lines or more.

Just another note: Isn't something that starts with a condition (IF) and ends with a END-REP, instead of an END-IF confusing ?
The logic is to start with a loop, then install a looping condition and then to end the loop:

while (NOT Thermostat mode of Act_Heating_Living_Back heat)
..Thermostats: Act_Heating_Living_Back --> Mode: heat
..Delay: 10s
end while

1 Like

Where in my post do you see an assumption of the motive ? I only say that a company that is hearing on users, and I'm not alone to request this, (apparently they are in most cases) should not say NO with no valuable explication, and "rules are not programming" is no valuable reason.

I don't know how RM is coded but I code since more than 30 years and I coded many software, freeware, shareware, on demand coding for large companies and I know how code works. The rule engine is "probably" interpreting rules and a line beginning with "//" should simply not be treated after that. In the best case the conditions are evaluated before they are translated for the core service and ignoring comments at this level is really easy. If that is difficult to do, then it might really be badly coded. But maybe a coder of RM can convince me from the opposite...

I'm not going to argue with you.. I quoted the exact text where you ASSUMED that they weren't listening to users.

Have a good day.

3 Likes

As someone who still frequents the GOTO side of town, I'll just note that both of those examples are actually GOSUBs. :wink:

As someone who also heavily comments his code, I certainly wouldn't mind that ability here, if it can be done without significant performance penalty. Until then, I've been making do with "Notes" and, when necessary, off-device text files.

3 Likes

Sorry, no. GOSUB statements are still used in a long list of code and not between different methods. They are GOTO statements that do not refer to a line of code but a named block of code.
Like this:

PRINT "CHOOSE A MENU (1 OR 2)" :
...
ON MENU GOSUB MENU1, MENU2
...
MENU1: * CONTROL TRANSFERS HERE IF MENU 1 IS CHOSEN
..
RETURN
MENU2: * CONTROL TRANSFERS HERE IF MENU 2 IS CHOSEN
....
RETURN

I called it a modern GOTO as pendant to what it is today. In a real object oriented language it is a message. One method sends a message with arguments if needed to another method and this method decides what to do with the message. One objects method can't directly do changes or calls in another object (even if some so called languages do allow it).

It doesn't, really: the repeat starts with a "Repeat" and ends with an "END-REP," just like regular repeat syntax in Rule Machine. The "IF" is just part of a "Simple conditional action." What you're seeing is just a result of the fact that simple conditions appear on the same line as the action they are "attached" to. (It is a little odd that a simple conditional on a "Repeat" action acts as a check for the entire thing...but it makes things easy and is just something you have to learn, I suppose.)

Instead of this:

IF (Condition X) Repeat every Y
  Do Z
END-REP

you could write this:

IF (Condition X) THEN
  Repeat every Y (stoppable)
    Do Z
  END-REP
ELSE
  Stop repeating actions
END-IF

...and they are exactly equivalent.

It's not "interpreting" things in the sense of looking at the pseudo-code you see on the screen. All Hubitat apps (of this kind, so ignoring things like service managers) work by asking the user to fill out inputs that get saved to an internal settings map (as in the data structure) for that app. In the case of RM, the inputs are things like devices and what type of action you want to run. Both what RM does and what it displays are the result of an undoubtedly complex set of app code that looks at the settings and devices what to do--but one of the reasons you'll see people say that RM rules aren't "code" is because they're not really. I will concede that what it displays looks a bit like that, and that you might consider it "programming" because it requires you to think like one--can't escape the fact that you need to know how things work, no matter how you do it. :slight_smile:

Given your comments, I don't think that the entry barrier to Groovy will be that high for you. I know it's not for everyone, but I think you might like it better in the long run given those same comments. Maybe come back to that possibility some day if you don't want to right now. I know lots of people would be willing to help you get started!

2 Likes

If that works, then it is even more confusing for me. My interpretation is that this will hang forever in the:

Repeat every Y (stoppable)
Do Z
END-REP

This is nice loop with no with condition in it to exit it and it should loop forever. If the surrounding condition makes this work it seems to be completely illogic.

Your explication of how RM is internally working is in line with my estimate (not knowing it) when I talk of "In the best case the conditions are evaluated before they are translated for the core service". So it should not be as complex to implement it, but I agree that it may take time and resources that are actually better invested in other implementations.

You're right; this really depends on what your trigger is. I was assuming a trigger like "X *changed*", which would often be the case with a rule written like this. The first (simple condition) variant is not as picky about the trigger since it does the check before starting (or re-starting) the repeat. But what I wrote above will work if the rule is written correctly--it should (re)trigger, run the ELSE actions, and stop the repeat.

And both go to show why I always ask people to share the entire rule, including triggers... :rofl:

Well, be careful on terminology... It won't "hang" forever. It isn't a single thread, single execution issue, as that isn't how rep works in this context.

But to Bert's point, depending on the trigger you may keep ending up in the rep portion of the if statement.

Yaeh, I agree with you :wink:

My code or rules are more complex. Just to be as exhaustive as possible I show a short sequence of my codes here. You can easily see that there are more ramifications possible, but I will not show all of them to non overload the post (maybe already the case).

Here is a date and time trigger that sets two SetPoints for Heating:


(The last action line is a work around as variable triggering does not work correctly with day conditions - another post)

This rule is triggered by the change of one of the variables set by the rule above:

This is the rule run by the above script if a window is open:

Opening or closing a window triggers this rule that triggers again the above rule:

To avoid that the called rule 1100(A) is triggered multiple times when a window is opened and closed in a short period (to call someone for example or a door) I have a delay of 1 minute and to avoid the rule to run on multiple instances I use the private boolean. If the state after a minute is the same as the old one (set on the valves) all instructions in rule 1100(b) will be skipped

Ok, I agree. This instance of the rule will hang forever in the loop, until restarted, power failure and so on :wink:

Again, it still depends on what the trigger is and whether condition X would always evaluate as true or not. But now I'm just arguing because I'm bored, so I'll stop. :slight_smile:

1 Like

:popcorn:

@pascal.nohl i appreciate your thoughtful comments.

In case anyone missed it, I did implement comments last night. I don't like them, wouldn't use them, suggest that you not either, but they are there.

Your comments about how RM works reveal that you don't understand how it works. There is no "core service", there is no translation, there is no "interpreting" rules or lines beginning with characters, "//" or otherwise. @bertabcd1234 explained pretty clearly above what is going on. Selected actions are executed against selected devices and settings, conditions are evaluated with then current values of devices, variables and settings, not "before" anything. They are also evaluated as the rule is built in order to display their current values at that time, and then evaluated when encountered as the rule runs, where those values could be visible in logs (of which you are in control of there being too many or not).

RM is not a programming language, by any "modern" definition.

A programming language is a formal language comprising a set of strings that produce various kinds of machine code output. Programming languages are used in computer programming to implement algorithms. Most programming languages consist of instructions for computers.

There are no strings involved, it produces no machine code. There is no "interpretation", no "translation", as there is no script or source code to interpret or translate, no object code to execute. RM provides a means to implement an algorithm, so in that sense it has a certain similarity to a programming language. It is an interactive app that creates data structures that determine actions to be performed in response to events, as are all of the built-in apps that run on the hub.

The newly implemented Comment feature is not ignored as a comment in programming language "source code" is; it's an action like any other RM action, where the method that implements it does nothing. Like all actions, it resides in the data structures of a rule, with, unfortunately but unavoidably, two copies of the comment string (tldr explanation as to why there is a copy as well as the original having to do with speed of page rendering during rule creation).

6 Likes

That may be true, I don't know the logic, didn't see the code and I have to estimate as long as I have no concrete information.

BUT, you say there is no interpretation and that's simply not possible. Regardless of the way it works, you have some user readable rules, scripts or whatever you call what we see when rules are defined and this has to be interpreted to your logic and back (or return the stored original value) if a rule is edited again. So there is an interpretation at some levels. It doesn't even matter if I understand it or not.

Anyway, that's not my job and as you created comments over night, it might not have been so impossible or hard as announced...

Obviously in retrospect that was true. But that doesn't mean that the original statement wasn't believed to be true at the time.

Another possibility is that like many engineering oriented minds, over time he looked at/thought of it a different way and came up with an idea that was much easier to implement than what he believed to be required/the original idea.

New thoughts and new ideas equal new outcomes after all. :slight_smile:

Just a thought/suspicion. I could be completely off base.

1 Like

As I said above, I don't like this idea at all, and didn't want to do it. It's all just SMOP ultimately.

2 Likes

I fully understand that. I always start my software (not valid for on demand developments) with something I need for myself. Later users request one or the other feature that I don't need, do not want, do not like and that from my logical point of view is not a good idea to implement. But if the user demand is important enough, I simply do it.

What do you mean with SMOP ?

  • Simple Matter Of Programming
  • Standard Method of Procedure
  • Small Matter of Programming :wink:

Will it be in the next release ?

No worries. Your baby, your decision. :slight_smile:

I actually think I will use the feature on occasion. :man_shrugging: I wasn't losing any sleep about it not being there, though either - so I'm not complaining either way.

You can put an entire book in a comment if you want:

And like all actions, they can be delayed (whatever that means).

2 Likes