[Reactor] Variables not updating correctly in latest-25201-2aa18550
-
Post your script. Based on the instructions given, your local variables should be expressionless, so that seems wrong and I want to see what your script is trying to do.
I can tell you right now, if
ok_to_reset
is expressionless and you are resetting it in the Script Action script, and expectingpeak_power
to see the updated value, it won't work.@toggledbits that wasn’t what I was trying to convey here. Let’s forget script action for a moment as it has no relevance for my finding.
What I’m trying to say here is that by merely changing the order of variables (and to be clear, that setup has worked before), my rules are working again. Somehow new builds do not like if expressionless variables are in the middle of regular ones. If they are last in line, all is well. Sounds crazy, but please test.
-
I'll say again, local variables are not processed/evaluated in the same way as global variables. Local variables are only evaluated when the Rule to which they belong is being evaluated (i.e. its triggers are being checked). They are not evaluated when a dependent local variable is changed. When the Rule is evaluated, its local variables, if any, are evaluated before the triggers, and yes, they are evaluated in the order in which they are defined. That is known.
Combine this with using a Set Variable action... if you don't check the "Force re-evaluation" checkbox, any other local variables that use the variable being set will not be updated until the Rule is next evaluated. If you check the box, it forces a Rule evaluation, and it is the second evaluation that will update the dependent variables.
The Script Action is absolutely relevant in your case, at least from what you've posted, because you apparently still had local variables that are dependent on the local variable that the script was changing, and that was not consistent with my recommendation. The script will not cause the dependent variables to be updated, because there is no "Force re-evaluation" option for the script, and local variables are not dependency-scanned/triggered, as I said above. That means your script action will change the local variable
ok_to_reset
, but that won't makepeak_power
change immediately after. That is why I recommended that you make all local variables expressionless when using the Script Action, and do all of the work in the script, none of the work in the local variables' expressions.None of this is new. And again, no changes have been made to how variables (global or local) in any of these recent builds. The earlier changes you mentioned to make
isRuleSet()
andisRuleEnabled()
trigger with the rules they reference (build 25082 -- a long time ago) was a change to the implementation of those functions themselves , but was not in any way a change to the mechanism that handles changes in global expressions. -
I'll say again, local variables are not processed/evaluated in the same way as global variables. Local variables are only evaluated when the Rule to which they belong is being evaluated (i.e. its triggers are being checked). They are not evaluated when a dependent local variable is changed. When the Rule is evaluated, its local variables, if any, are evaluated before the triggers, and yes, they are evaluated in the order in which they are defined. That is known.
Combine this with using a Set Variable action... if you don't check the "Force re-evaluation" checkbox, any other local variables that use the variable being set will not be updated until the Rule is next evaluated. If you check the box, it forces a Rule evaluation, and it is the second evaluation that will update the dependent variables.
The Script Action is absolutely relevant in your case, at least from what you've posted, because you apparently still had local variables that are dependent on the local variable that the script was changing, and that was not consistent with my recommendation. The script will not cause the dependent variables to be updated, because there is no "Force re-evaluation" option for the script, and local variables are not dependency-scanned/triggered, as I said above. That means your script action will change the local variable
ok_to_reset
, but that won't makepeak_power
change immediately after. That is why I recommended that you make all local variables expressionless when using the Script Action, and do all of the work in the script, none of the work in the local variables' expressions.None of this is new. And again, no changes have been made to how variables (global or local) in any of these recent builds. The earlier changes you mentioned to make
isRuleSet()
andisRuleEnabled()
trigger with the rules they reference (build 25082 -- a long time ago) was a change to the implementation of those functions themselves , but was not in any way a change to the mechanism that handles changes in global expressions.@toggledbits I’m not using script action currently, and those screenshots were from a rule that uses set variable action.
But could you test my finding? Even rule triggers are not relevant when reproducing this finding. Just put a variable referencing an entity which frequently changes as a first one. Then make expressionless variable second, and as a third one make some kind of expression which uses first variable and does some calculation with it. Observe what happens and then swap second and third line and again watch what happens.
-
I'll say again, local variables are not processed/evaluated in the same way as global variables. Local variables are only evaluated when the Rule to which they belong is being evaluated (i.e. its triggers are being checked). They are not evaluated when a dependent local variable is changed. When the Rule is evaluated, its local variables, if any, are evaluated before the triggers, and yes, they are evaluated in the order in which they are defined. That is known.
Combine this with using a Set Variable action... if you don't check the "Force re-evaluation" checkbox, any other local variables that use the variable being set will not be updated until the Rule is next evaluated. If you check the box, it forces a Rule evaluation, and it is the second evaluation that will update the dependent variables.
The Script Action is absolutely relevant in your case, at least from what you've posted, because you apparently still had local variables that are dependent on the local variable that the script was changing, and that was not consistent with my recommendation. The script will not cause the dependent variables to be updated, because there is no "Force re-evaluation" option for the script, and local variables are not dependency-scanned/triggered, as I said above. That means your script action will change the local variable
ok_to_reset
, but that won't makepeak_power
change immediately after. That is why I recommended that you make all local variables expressionless when using the Script Action, and do all of the work in the script, none of the work in the local variables' expressions.None of this is new. And again, no changes have been made to how variables (global or local) in any of these recent builds. The earlier changes you mentioned to make
isRuleSet()
andisRuleEnabled()
trigger with the rules they reference (build 25082 -- a long time ago) was a change to the implementation of those functions themselves , but was not in any way a change to the mechanism that handles changes in global expressions.@toggledbits have you had time to look at this? I suspect there’s a bug in evaluating local variables when expressionless variables are not last items in the list
-
It works as I would predict.
-
Yep, I confirm I had to update a couple of rules where I had similar variables as @tunnus
I used script action because it’s multi line and definitely better in terms of readability.@therealdb could you test this if you could get your original rules (variables) to work just by rearranging local expressions? My hypothesis being that expressionless variables should be last in the list
-
@therealdb & @toggledbits, below you can find my simple test case for this case. At least in my setup I can consistently reproduce this behaviour. (Still) using build 25208.
- First, make sure you have some device/entity which updates often (not strictly necessary, but it's faster to see the results & differences).
- Then put "target" variable immediately after "source", and "expressionlessVariable" should be the last one
- Now "target" should follow/change as "source" changes
- Next, swap "target" & "expressionlessVariable" (as seen in the image). Save.
- Now "target" ceases to update
-
It's probably moot at this point... I've just spent the last two weeks completely revamping the evaluation of Rule-based variables, to make them perform more like global variables, respect dependencies between them better, etc. The last week has just been a deep dive through the logs watching the performance of my own house on the updated approach.
I'll shortly be releasing a blind build with these changes, just for you (@tunnus) and @therealdb to try. I expect this to be disruptive, because any approaches in the logic that rely on specific behaviors and side-effects of the old approach will now work differently, maybe fail, and adapting to the new approach will be necessary. But, I think the new approach will produce a result that is much more in keeping with how you would expect it to work. So, sit tight... I'll be ready to build later today or early tomorrow.
-
It's probably moot at this point... I've just spent the last two weeks completely revamping the evaluation of Rule-based variables, to make them perform more like global variables, respect dependencies between them better, etc. The last week has just been a deep dive through the logs watching the performance of my own house on the updated approach.
I'll shortly be releasing a blind build with these changes, just for you (@tunnus) and @therealdb to try. I expect this to be disruptive, because any approaches in the logic that rely on specific behaviors and side-effects of the old approach will now work differently, maybe fail, and adapting to the new approach will be necessary. But, I think the new approach will produce a result that is much more in keeping with how you would expect it to work. So, sit tight... I'll be ready to build later today or early tomorrow.
OK. Interim build latest-25248 for 64-bit docker systems only is up for testing/trials.
NOTE TO ALL USERS NOT CONTRIBUTING TO THIS THREAD — this is not an official build and you are advised not to upgrade to it just yet. This build is specifically for participants in this thread as we work to improve the behavior of Rule-based variables. Wait for a build advertised in the official announcement thread before upgrading your system.
Behavior of Rule-based variables now:
- Will still be re-evaluated when the Rule is started, and any time the Rule is subject to trigger condition check (i.e. behavior not changed);
- When the trigger condition check occurs, Rule-based variables are always evaluated/updated before trigger conditions (i.e. also same as before);
- Rule-based variables may be modified by Set Variable action and assignment statements in Script Actions in Rule Reactions (unreliable before);
- If a Rule-based variable references another Rule-based variable, and the latter changes, the former will be re-evaluated (now same as Global Variables).
- The order of Rule-based variables doesn't matter, it's just for your convenience. Dependencies between variables are established at startup, and evaluation takes place in dependency tree order, not the order shown in the UI (now same as Global Variables).
If you run into an issue you can't resolve, here's what I ask:
-
Make sure your expectations are aligned with the changes above; make sure you are not relying on any prior behavior or side-effect of the prior behavior.
-
Enable logging for the rule in question. Put a snippet like below in your
logging.yaml
file (replace the part after#
with your rule ID):"Rule#rule-l3hj06aa": level: 5 streams: - type: file # filename is derived from rule ID keep: 2 level: 999 recycle: true
-
Restart Reactor and get the rule in question to demonstrate whatever the issue is. Make sure to then capture the log file called
Logger#Rule#XXX.log
... I will be asking for it. -
Report the issue here on this thread, with all of the usual attention to posting requirements: good, detailed description; expectations of behavior; clear description of what's not meeting expectations; etc.
-
I will PM you a URL where you can upload the log file and your rule JSON file (from
storage/rules
) if necessary.
The locally-installed version of the documentation is also updated.
-
OK. Interim build latest-25248 for 64-bit docker systems only is up for testing/trials.
NOTE TO ALL USERS NOT CONTRIBUTING TO THIS THREAD — this is not an official build and you are advised not to upgrade to it just yet. This build is specifically for participants in this thread as we work to improve the behavior of Rule-based variables. Wait for a build advertised in the official announcement thread before upgrading your system.
Behavior of Rule-based variables now:
- Will still be re-evaluated when the Rule is started, and any time the Rule is subject to trigger condition check (i.e. behavior not changed);
- When the trigger condition check occurs, Rule-based variables are always evaluated/updated before trigger conditions (i.e. also same as before);
- Rule-based variables may be modified by Set Variable action and assignment statements in Script Actions in Rule Reactions (unreliable before);
- If a Rule-based variable references another Rule-based variable, and the latter changes, the former will be re-evaluated (now same as Global Variables).
- The order of Rule-based variables doesn't matter, it's just for your convenience. Dependencies between variables are established at startup, and evaluation takes place in dependency tree order, not the order shown in the UI (now same as Global Variables).
If you run into an issue you can't resolve, here's what I ask:
-
Make sure your expectations are aligned with the changes above; make sure you are not relying on any prior behavior or side-effect of the prior behavior.
-
Enable logging for the rule in question. Put a snippet like below in your
logging.yaml
file (replace the part after#
with your rule ID):"Rule#rule-l3hj06aa": level: 5 streams: - type: file # filename is derived from rule ID keep: 2 level: 999 recycle: true
-
Restart Reactor and get the rule in question to demonstrate whatever the issue is. Make sure to then capture the log file called
Logger#Rule#XXX.log
... I will be asking for it. -
Report the issue here on this thread, with all of the usual attention to posting requirements: good, detailed description; expectations of behavior; clear description of what's not meeting expectations; etc.
-
I will PM you a URL where you can upload the log file and your rule JSON file (from
storage/rules
) if necessary.
The locally-installed version of the documentation is also updated.
@toggledbits whoops... guess this is one time having the system auto-update containers with new images is bad....
So I'm on the test version. Found this:
This is a Dynamic Group I'd created forever ago:
I added the snippet as noted into my
logging.yaml
file:When it didn't work I checked my yaml and found a spacing issue. That's been corrected, I now have a proper
logger*
log. Will upload to our pre-x Dropbox in folder25248 logs
along with the rule JSON file. -
Is there a global variable called
dead
(it's not shown above)?Or are you looking for the word dead in
status_text
? Because if it's that, your expression is incorrectly formed. -
Is there a global variable called
dead
(it's not shown above)?Or are you looking for the word dead in
status_text
? Because if it's that, your expression is incorrectly formed.@toggledbits kicker is: this has been working for a long while. Dead iblind nodes (far too common, btw) get caught and pinged and I get the alerts on my phone.
I don't see a Global Expression called
dead
and, yes, I believe when I wrote this I was looking for either a status of3
orstatus_text
of dead. -
OK. Yes, the new build also has some new error reporting. That message was probably being logged, but since you weren't looking at the logs, you didn't see it.
You can also combine those into one status test, which will be a good bit more efficient:
- id: groups enabled: true implementation: DynamicGroupController name: Dynamic Group Controller config: groups: zwavejs_dead: select: - include_group: zwavejs filter_expression: < entity?.attributes?.zwave_device?.status === 3 || entity?.attributes?.zwave_device?.status_text === "dead"
Also, please... Please... PLEASE do not screen shot pure text. Use the fenced code block formatting here for text like expressions, configs, logs, etc. It may be expeditious for you to just paste the screen shot, but when I try to give you suggestions or corrections like the above, I have to retype the entire block (I can't copy-paste the text and update it). That not only takes a bunch of time, but also introduces the possibility that I will make a typo in the part we don't care about and leave you with a non-working example we then need to fix in yet another series of post replies.
Don't forget to remove the Rule logging when it isn't needed.
-
OK. Yes, the new build also has some new error reporting. That message was probably being logged, but since you weren't looking at the logs, you didn't see it.
You can also combine those into one status test, which will be a good bit more efficient:
- id: groups enabled: true implementation: DynamicGroupController name: Dynamic Group Controller config: groups: zwavejs_dead: select: - include_group: zwavejs filter_expression: < entity?.attributes?.zwave_device?.status === 3 || entity?.attributes?.zwave_device?.status_text === "dead"
Also, please... Please... PLEASE do not screen shot pure text. Use the fenced code block formatting here for text like expressions, configs, logs, etc. It may be expeditious for you to just paste the screen shot, but when I try to give you suggestions or corrections like the above, I have to retype the entire block (I can't copy-paste the text and update it). That not only takes a bunch of time, but also introduces the possibility that I will make a typo in the part we don't care about and leave you with a non-working example we then need to fix in yet another series of post replies.
Don't forget to remove the Rule logging when it isn't needed.
@toggledbits now I'm feeling hypocritical as I'm the guy at work chastising the Support folks for giving me screenshots for the exact reasons you noted.
Change deployed.
Got this upon restart of MSR:
at _ClientAPI._commandTimeout (http://192.168.1.100:8111/client/ClientAPI.js:594:125)
Cleared it and refreshed the tab and all seems fine. Removing logging snippet.
Thank you, sir!
-
@toggledbits I've updated my main system. I'll observe and report back. Thanks
-
Ok, I got a bunch of errors at restart because of failed references in almost all variables - now it seems to be OK and variables are updated. I'm observing a couple of rules I haven't migrate yet - and, at this point, I'll not migrate - where I used to old trick that @gwp1 surfaced (and that I used without making it a rule). always seems to be OK.
-
yep, it seems to be related (in general) to variables not being evaluated at startup. Here's a screenshot from a daily rule that it's setting a couple of things, including a virtual binary sensor for Christmas from a local variable:
After re-setting the rule, the expression got re-evaluated and the error went away. @toggledbits
EDIT. a similar one + logs
This one, instead, every time is evaluated gives the error.
[latest-25248]2025-09-11T07:19:37.602Z <Rule:ERR> Lights-Christmas-Off (rule-kwv6wdpw in Lights-Outdoor): error evaluating expression specialdays: [Error] Object does not exist [-] [latest-25248]2025-09-11T07:19:37.603Z <Rule:ERR> Full expression: t = time(), m = dateparts(t).month, d = dateparts(t).day, (m == 12 && d == 24) || (m == 12 && d == 25) || (m == 12 && d == 31) || (m == 1 && d == 1) || (m == 1 && d == 5) || (m == 1 && d == 6) [latest-25248]2025-09-11T07:19:37.604Z <Rule:CRIT> Error: Object does not exist [-] Error: Object does not exist at GlobalExpression.getInstance (/opt/reactor/server/lib/GlobalExpression.js:160:27) at _0x1ec9e7._func.<computed> [as _ref] (/opt/reactor/server/lib/Rule.js:848:69) at _resolve (/opt/reactor/common/lexp.js:1385:27) at _run (/opt/reactor/common/lexp.js:1429:31) at /opt/reactor/common/lexp.js:1697:33 at Array.forEach (<anonymous>) at _run (/opt/reactor/common/lexp.js:1696:28) at _run (/opt/reactor/common/lexp.js:1604:33) at _run (/opt/reactor/common/lexp.js:1438:34) at /opt/reactor/common/lexp.js:1425:29 [latest-25248]2025-09-11T07:19:37.627Z <Rule:INFO> Lights-Christmas-Off (rule-kwv6wdpw in Lights-Outdoor) evaluated; rule state transition from NULL to RESET! [latest-25248]2025-09-11T07:19:37.638Z <Rule:INFO> Lights-Christmas-Off (rule-kwv6wdpw in Lights-Outdoor) started
-
New build latest-25254 posted. This should address the local variable in rule-based expressions at startup issue. Docker 64-bit platforms only.
-
yep, it seems to be related (in general) to variables not being evaluated at startup. Here's a screenshot from a daily rule that it's setting a couple of things, including a virtual binary sensor for Christmas from a local variable:
After re-setting the rule, the expression got re-evaluated and the error went away. @toggledbits
EDIT. a similar one + logs
This one, instead, every time is evaluated gives the error.
[latest-25248]2025-09-11T07:19:37.602Z <Rule:ERR> Lights-Christmas-Off (rule-kwv6wdpw in Lights-Outdoor): error evaluating expression specialdays: [Error] Object does not exist [-] [latest-25248]2025-09-11T07:19:37.603Z <Rule:ERR> Full expression: t = time(), m = dateparts(t).month, d = dateparts(t).day, (m == 12 && d == 24) || (m == 12 && d == 25) || (m == 12 && d == 31) || (m == 1 && d == 1) || (m == 1 && d == 5) || (m == 1 && d == 6) [latest-25248]2025-09-11T07:19:37.604Z <Rule:CRIT> Error: Object does not exist [-] Error: Object does not exist at GlobalExpression.getInstance (/opt/reactor/server/lib/GlobalExpression.js:160:27) at _0x1ec9e7._func.<computed> [as _ref] (/opt/reactor/server/lib/Rule.js:848:69) at _resolve (/opt/reactor/common/lexp.js:1385:27) at _run (/opt/reactor/common/lexp.js:1429:31) at /opt/reactor/common/lexp.js:1697:33 at Array.forEach (<anonymous>) at _run (/opt/reactor/common/lexp.js:1696:28) at _run (/opt/reactor/common/lexp.js:1604:33) at _run (/opt/reactor/common/lexp.js:1438:34) at /opt/reactor/common/lexp.js:1425:29 [latest-25248]2025-09-11T07:19:37.627Z <Rule:INFO> Lights-Christmas-Off (rule-kwv6wdpw in Lights-Outdoor) evaluated; rule state transition from NULL to RESET! [latest-25248]2025-09-11T07:19:37.638Z <Rule:INFO> Lights-Christmas-Off (rule-kwv6wdpw in Lights-Outdoor) started
@therealdb said in [Reactor] Variables not updating correctly in latest-25201-2aa18550:
[latest-25248]2025-09-11T07:19:37.603Z Rule:ERR Full expression: t = time(), m = dateparts(t).month, d = dateparts(t).day,
(m == 12 && d == 24) ||
(m == 12 && d == 25) ||
(m == 12 && d == 31) ||
(m == 1 && d == 1) ||
(m == 1 && d == 5) ||
(m == 1 && d == 6)Just a tip, a more efficient way to write this:
parts = dateparts(), m=parts.month, d=parts.day, (m == 12 && d == 24) || (m == 12 && d == 25) || (m == 12 && d == 31) || (m == 1 && d == 1) || (m == 1 && d == 5) || (m == 1 && d == 6)
The default time for
dateparts()
is the current time, so you don't needd
, and by savingdateparts()
toparts
, the function is only invoked once. We old-timers love to save every cycle we squeeze out of the processor! -
@therealdb said in [Reactor] Variables not updating correctly in latest-25201-2aa18550:
[latest-25248]2025-09-11T07:19:37.603Z Rule:ERR Full expression: t = time(), m = dateparts(t).month, d = dateparts(t).day,
(m == 12 && d == 24) ||
(m == 12 && d == 25) ||
(m == 12 && d == 31) ||
(m == 1 && d == 1) ||
(m == 1 && d == 5) ||
(m == 1 && d == 6)Just a tip, a more efficient way to write this:
parts = dateparts(), m=parts.month, d=parts.day, (m == 12 && d == 24) || (m == 12 && d == 25) || (m == 12 && d == 31) || (m == 1 && d == 1) || (m == 1 && d == 5) || (m == 1 && d == 6)
The default time for
dateparts()
is the current time, so you don't needd
, and by savingdateparts()
toparts
, the function is only invoked once. We old-timers love to save every cycle we squeeze out of the processor!@toggledbits said in [Reactor] Variables not updating correctly in latest-25201-2aa18550:
Just a tip, a more efficient way to write this:
OMG, very old rules, isn't it? Thanks, I fixed it.