Openhab3 Rule Struggles!

Good Evening everyone
currently just upgraded my whole system including a new raspberry pi 4 from openhab 2.4 to 3.0.

Release = Debian GNU/Linux 10 (buster)
Kernel = Linux 5.10.11-v8+
Platform = Raspberry Pi 4 Model B Rev 1.4
openhabian 3.0.1

I let openhab try and adopt my rules for me from openhab2 but some havent worked very well and currently dont fire.

how could i remake this rule to work with openhab3?

rule "Battery Status Check"
when
    Item gALLBatteryPercentage changed
then
    var String msg = ""
    var triggertDevices = gALLBatteryPercentage.members.filter[s|s.state <= 15]

    triggertDevices.forEach [ i |
        msg = msg + (transform("MAP", "batteries.map", i.name) + ': ' + i.state.toString) + '%\n'
        logInfo("Battery Check","Low battery at " + i.name + ": " + i.state.toString + "%")
    ]

    if (msg != "") {
sendBroadcastNotification(msg + " of your battery remaining")
    }
end

Thank you in advance.

Not without explaining:

  • what is this rule supposed to do?
  • what specifically is not working?
  • what do you see in the logs?

I do apologise i should of stated that in my orignal post. The Rule is triggered when anyone member of my gALLBatteryPercentage group goes below 15%. It the sends me a notification of which exact sensors battery is below 15% by grabbing the text from the batteries.map file.

The item is obviously receiving the data from the device but the rule ust isnt firing.

I dont actually know how to view more detailed logs. I only know how to acces fronttail via :9001

Frontail is showing the logs as they are.

  1. What is the configuration for gALLBatteryPercentage?
  2. Are all the Items that need to be members of that Group?
  3. Do you see events in events.log of gALLBatteryPercentage changing?

Group Config

Group:Number gALLBatteryPercentage (gALLSensors)

Item Config

Number Living_Room_Battery      "Living Room Battery [%.1f %%]"      <battery> (gALLBatteryPercentage)     { channel="mqtt:topic:Living_Room_Sensor:battery" }
Number Kids_Bedroom_Battery      "Kids Bedroom Battery [%.1f %%]"      <battery> (gALLBatteryPercentage)     { channel="mqtt:topic:Kids_Bedroom_Sensor:battery" }

No there is no change to gALLBatteryPercentage in the log. Just the item itself changing whilst im sending it mqqt data to try and trigger rule.

2021-02-15 19:48:06.689 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Living_Room_Battery' changed from 76.5 to 10

You don’t have an aggregation function defined so there is nothing to change the state of gALLBatteryPercentage. Items | openHAB

You are triggering the rule when gALLBatteryPercentage changes and it’s never changing without an aggregation function. Maybe you want it to trigger when one of its member’s change?

Member of gALLBatteryPercentage changes

ok updated rule as stated and now the rule isnt even appearing in the rule section like it was before, i have rebooted aswell.

rule "Battery Status Check"
when
    Member of gALLBatteryPercentage changes
then
    var String msg = ""
    var triggertDevices = gALLBatteryPercentage.members.filter[s|s.state <= 15]

    triggertDevices.forEach [ i |
        msg = msg + (transform("MAP", "batteries.map", i.name) + ': ' + i.state.toString) + '%\n'
        logInfo("Battery Check","Low battery at " + i.name + ": " + i.state.toString + "%")
    ]

    if (msg != "") {
sendBroadcastNotification(msg + " of your battery remaining")
    }
end

Logs?


2021-02-15 20:31:06.632 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Zigbee.rules' has errors, therefore ignoring it: [3,5]: no viable alternative at input 'changes'

Cargo cult programming is so tedious.

It’s changed not changes. I haven’t used Rules DSL for nearly a year now so I typed it wrong. But it’s also helpful if you took some initiative and looked around at some examples or the docs in the mean time. It’s not even clear you looked at the logs before I asked. You have to meet us half way.

Altered changes to changed and the rule file has now loaded with no error logs.

Yes I totally agree with you. I need to work on my information giving skills and initiative. I did however look at the document you are referring to and got the information you stated whilst I was awaiting a response. I do apologise for wasting your time. Thank you all the same.

1 Like

It’s worth reviewing why this rule, that worked in OH2.4, did not work in OH3. Ultimately, you missed something in copying your Group Item configuration - you might want to check on others.

When I swapped to openhab3 it was a fresh install and i added the files from my openhab2 conf folders. Will keep an eye on all rules and items over the next few days for errors :+1: