Basic rule is not working. What am I getting wrong

  • Platform information:
    • Hardware: Raspberry pi 3B+
    • OS: Raspbian 10
    • Java Runtime Environment: openjdk 11.0.6
    • openHAB version: 2.5.9 Release
  • Issue of the topic:
    I’m just trying to put some item value into the log file.
    My Item is the instant power consumption of an electrical outlet
    The item is showing ok in the sitemap
  • Please post configurations (if applicable):
    • Items configuration related to the issue

Number LeFeu_Power “Consommation instantanée du feu [%i kWh]” (testGroup) {channel=“tplinksmarthome:hs110:F4A130:power” }

  • Sitemap configuration related to the issue
    THIS IS WORKING OK, I can see the consumption in basic UI :

sitemap Charneux label=“Maison Charneux” {
Frame {
Text label=“Pellets” icon=“fire” {
Switch item=LeFeu_Alimentation label=“Le feu” icon=“light”
Text item=LeFeu_Power label=“Consommation actuelle [%.1f W]” icon=“energy”
}
}
}

  • Rules code related to the issue
    THIS RULE IS NOT WORKING :

var boolean isHighConso
// init variables
rule “pellets_autoOff_startup”
when
System started
then
logWarn(“pellets”, “TEST STARTUP LOG DEBUG”)
isHighConso = false
end
rule “pellets_autoOff_cron”
when
Time cron “0 * * * * ?”
then
logWarn(“pellets”, “TEST LOG DEBUG BEGIN - 1”)
logWarn(“pellets”, LeFeu_Power)
logWarn(“pellets”, “TEST LOG DEBUG END”)
end

  • Services configuration related to the issue
    ??
  • If logs where generated please post these here using code fences:

2020-10-11 12:35:35.199 [WARN ] [lipse.smarthome.model.script.pellets] - TEST STARTUP LOG DEBUG
2020-10-11 12:36:00.009 [WARN ] [lipse.smarthome.model.script.pellets] - TEST LOG DEBUG BEGIN - 1
2020-10-11 12:36:00.016 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘pellets_autoOff_cron’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logWarn(java.lang.String,java.lang.String,java.lang.Object) on instance: null

logWarn() wants a string to log out.
LeFeu_Power is a complex object, an Item, not a string.
The Item has many properties - name, label, etc.
Perhaps it is the state you are interested in?

logWarn(“pellets”, "my Item state: " + LeFeu_Power.state.toString)

Ho my god.
Thank you.
I had tried that but the problem was that Visual Studio Code autocompleted my code to LeFeu_Power.Item.state.toString
instead of LeFeu_Power.state.toString
Thank you for pointing me in the right direction.
:slight_smile:

It is more efficient and often easier to use parameterized logging rather than using the + operator to concatenate strings. There are examples in the documentation.

Thanks for the logging tip.

1 Like