How to see returned values in rules

In other languages I can use console.write or console.log to show variable and property values in the console. In some IDEs I can add break points to see the value in the IDE. How do I do the same with OpenHab with rules? I’m using VS code with the plugin. Is there a better IDE to use?

Use the logInfo action:

For example:

var myNumber = 1
logInfo("My number: ", myNumber.toString)
var myString = "Hello world"
logInfo("My string: ", myString)
logInfo("My Item state: ", MyItem.state.toString)

The logInfo statements will be published in the openhab.log file

I tried this one in a rule, but I can´t seemto get it to write the state of the items to the log.

This is what I have done:

var Number previousVentilation = 1

rule "Auto ventilate bathrooms"
    Member of gHumidityBathRoom changed
    // Exit the rule when there is nothing to do
    if(gHumidityBathRoom.state < 49) return;

        logInfo("info", "Humidity is:", gHumidityBathRoom.state.toString) 

The result I get in the log:

2018-10-12 00:29:25.873 [INFO ] [] - Humidity is:

How did you define gHumidityBathRoom?

Hello Kim,

you need to set a space holder where to put the value in…
Just have a look here:

The second or third example will help you…

logInfo("info", "Humidity is:" + gHumidityBathRoom.state.toString)


logInfo("info", "Humidity is: %0.1f", gHumidityBathRoom.state)

Your logInfo will only take place if humidity is below 49…


It´s two thermostats in a group. Where I use the MAX definition.

Ahh, ofocuse… Thanks Andreas… Will try later today.

Hmm, it should take place, if the humidity is above 49. When humidity is below 49, it should just return doing nothing.

It looks like the state is empty
Can you publish the group definitions and the items in the group, please?

I will later today, cause I´m not at home, and cant get access to my items.
But I do believe it isn´t empty, cause the rule is triggering fine.

I wanted the rule to start logging if one of the two humidity sensors is above 49. Thats why I use MAX for item defintion. I have a problem with my automatic ventilation rule, not returning ventilation to previous state, (step 1) in this thread:

(it´s probably better to discuss my specific problem regarding “returning to previous state” in the other thread).

But it is empty because:

That’s why I am asking for the definitions, to understand where your values come from, how you constructed the group and possibly add more logging in the rule to understand what happens.

I know it showed empty in the log, which is what I dont understand :slight_smile: But my rule is firering just fine, so it cant be empty… (I think :slight_smile:)…

This is exactly why I wanted to log this :slight_smile: And probably add some more logging as well, due to the problems with my rule returning to previous state. But this is part of the other thread I guess.
I´ll post my items later…

Please see my advice about logging…

At the second look I saw, that there is the return directly after the if…
For looking after the group value of gHumidityBathroom I would suggest to put this logInfo statement directly after entering the rule. Then you have always the state in your log-file. I don’t think it is empty, but there is no place holder for your value…


This one is working

logInfo("info", "Humidity is:" + gHumidityBathRoom.state.toString)