"Script did not return a boolean value, but 'null'" - but which one?

  • Platform information:
    • Hardware: RasPi 4 + RaspBee II
    • OS: latest Raspbian with all current updates
    • Java Runtime Environment: OpenJDK Client VM Zulu11.52+13-CA
    • openHAB version:OH 3.3.0M2
  • Issue of the topic:

After upgrading my hardware (Pi 3 → Pi 4) i got some issues with my exec binding, which was running a script remotely over ssh on another Pi, which one again did NOT run because of some ssh key issues … nevermind, it’s fixed now…
While looking for reasons i saw in openhb-cli console - log:tail following error:

[ERROR] [ternal.handler.ScriptConditionHandler] - Script did not return a boolean value, but 'null'

It comes up like every few seconds 3x in a row.
So i’m stuck here, as it seems like some kind of script does not run well, but as far as i see all my items and rules seem to work.
I re-checked all my rules once (like 30) and can’t see any items not working (there i got like 240 :confused: )
Is there a way to find out which script is throwing the error, as there is no more detailed info in the log?

You have a rule defined in MainUI that has a Script Condition defined (i.e. the “but only if” section). The Script Condition is malformed. The last line of a Script Condition must evaluate to a boolean (when true the rule’s action(s) will run).

Hopefully that should narrow your search down. You likely don’t have too many rules that have a Script Condition defined. And now you know what to look for in those few rules.

Unfortunately I know of no other way to identify which rule is generating the error.


Thank you for the very quick reply. You’re my legend here :grin:
I re-re-checked everything and got a few (kinda 10) rules with “but only if” conditions, which all still seems to work…
When i was coding in java (once … long time ago) and wanted to check, where my code interrupts, i was just inserting “sysout” lines so i could see in the console, how far it came before it breaks.
Is there a way to do something like this with the rules? Like inserting a simple log-mark or line into the rule, so when the error pops out or even just the rule in triggered i get a clear message where it came from in the log?

You don’t say what language you are using but all the scripting languages, from Rules DSL to jRuby, have log statements.

But pay special attention to some nuance here. It’s not just a rule that has any old “but only if” condition. It has to be one that has a Script Condition as a “but only if” condition.

There should be no return statement in that code. And the last line executed must evaluate to a boolean. For example, the following is wrong and will generate that error (this is ECMAScript).

if(something == somethingElse) 
    return true;
   return false;

There are no return statements allowed in a Script Condition.

This too would generate that error

something == somethingElse
console.log('Exiting the script condition');

The last line executed needs to evaluate to a boolean.

Instead it needs to be

something == somethingElse

What that evaluates to will determine whether the Actions in the rule are run or not.

If you have an Item Condition, Time Condition, or Ephemeris Schedule as the condition you would not see this error.

In the Script Conditions pay special attention to any if statements or loops you may have in there. It’s not the last line of the Script Condition that needs to evaluate to a boolean, it’s the last line executed. The following would generate an error sometimes too:

if(something) {
    console.log('something is true, I don't know what to do!');
else {
  something == somethingElse;

Any time something is true will generate that error in your log but when something is false it will work without complaint.

1 Like

I just thought of something that might help identify the rule that’s generating the error.

Edit $OH_USERDATA/etc/log4j2.xml and change the level; of openhab.event.RuleStatusInfoEvent to INFO. That will add a log statement to events.log when ever a rule runs (complete with the rule ID). You can then correlate the timestamp with the error to the rule that ran at that same time.

1 Like

So long i’m only using DSL rules.
Indeed this helped me a lot. I identified my rules, which meet the metioned tokens:

  • got “but only if” statment
  • script in “but only if” statement
  • evaluate in a boolean, but not in the last line
  • got a “return” statement

For example such one:

var solltemp = (p_EZ_Heizung_Solltemperatur.state as Number)
var temp = (p_EZ_Heizung_Temperature.state as Number)
if (solltemp > (temp+1)){
    return true;

This is comparing the room temperature with the heating temperature and shall turn on some fans.
But what is confusing me: this rule works pretty fine.
So is this error just some kind of “you got a typo”-warning, which i could ignore, or is it suggestive to fix this?

It appears to work because it only generates the error when soltemp <= (temp+1) in which case you wouldn’t want the rule to run anyway.

Change from that if statement to just

var solltemp = (p_EZ_Heizung_Solltemperatur.state as Number)
var temp = (p_EZ_Heizung_Temperature.state as Number)
soltemp > (temp+1)

That should eliminate the error for that one.

To log in Rules DSL use logInfo('logger name', 'log statement'). There’s an action for each of the logging levels if you want to differentiate the logging levels.

1 Like

Awesome! :hugs:
This is it!
I’ve changed one rule and it still works, but i get 1 less error in the log.
So going to change every one like this now.

Thank you very much!

PS: guess it’s more usefull to others, when i mark your “way to find the error” as solution than to mark the actual solution for my specific problem. Correct me, when i’m wrong and i change it