ERROR in Rule with Group based Trigger and Data forwarding

Hello

I am trying to create a rule that triggers when a number item changed.
The rule is transforming W to kW and forwarding the result to new items.

Unfortunately I get an error.

Is it because all the items are getting pulled at the same time and so the rule cannot figure out what the triggering item is? I am getting 5 errors in the logs so i guess the rule is getting fired for each item individually.

I am Using OH 4 in a docker container on a synology nas.

Here’s the items that work as the trigger:

Number                    EVCC_Leistung_Netz_W                             "Grid Power [%.1f W]"                            <energy>          (gLadesaeule, gLadesaeule_Faktor)    {channel="evcc:device:home:general#gridPower"}
Number                    EVCC_Leistung_Haus_W                             "Home Power [%.1f W]"                            <energy>          (gLadesaeule, gLadesaeule_Faktor)    {channel="evcc:device:home:general#homePower"}
Number                    EVCC_Leistung_PV_W                               "PV Power [%.1f W]"                              <energy>          (gLadesaeule, gLadesaeule_Faktor)    {channel="evcc:device:home:general#pvPower"}

Here are the items that should be 1/1000 of the trigger items after the calculatioN.



Number                    EVCC_Leistung_Netz_kW                            "Leistung Netz [%.1f kW]"                         <energy>          (gLadesaeule)                        {channel="knx:device:bridge:Diverses:Haus_Leistung_Netz"}
Number                    EVCC_Leistung_Haus_kW                            "Leistung Haus [%.1f kW]"                         <energy>          (gLadesaeule)                        {channel="knx:device:bridge:Diverses:Haus_Leistung_Haus"}
Number                    EVCC_Leistung_PV_kW                              "Leistung PV [%.1f kW]"                           <energy>          (gLadesaeule)                        {channel="knx:device:bridge:Diverses:Haus_Leistung_PV"}
Number                    EVCC_Leistung_Batterie_kW                        "Leistung Batterie [%.1f kW]"                     <energy>          (gLadesaeule)                        {channel="knx:device:bridge:Diverses:Haus_Leistung_Powerwall"}
Number                    EVCC_Leistung_Ladesaeule_kW                      "Leistung Ladesäule [%.1f kW]"                    <energy>          (gLadesaeule)                        {channel="knx:device:bridge:Diverses:Haus_Leistung_Ladesaeule"}

Here’s my rule:

rule "Elektroauto: Leistungen umrechnen"
when
    Member of gLadesaeule_Faktor changed
then
    val Number leistungNetzW = triggeringItem.state as Number
    val Number leistungNetzkW = leistungNetzW / 1000

    sendCommand(triggeringItem.name.replace('_W', '_kW'), leistungNetzkW)
end

I am getting this error:

[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'EVCC-1' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null in EVCCnces:

I need the Power in kW because of a Display i am using.

Thank you

Have you looked at transforming the data instead?

An example being, my wife’s Mini provides the remain fuel in Metres, which I convert to Miles.

Number:Length Car_Mini_Range "Range [JS(Metres2Miles.js):%s]" { channel="mybmw:conv:XXXXXX:ZZZZZZ:range#fuel" }

I created this and places it into the Transfom folder and named it Metres2Miles.js

(function(x) {
    return (parseInt(x)/1609).toFixed(1) + " Miles";
})(input)
1 Like

That’s what Units of Measurement is for. You almost certainly don’t need a rule for this.

Which release? A lot has changed even in the last week, let alone between M1 and M2.

Note, the whole way units are handled and managed changed in the past week or so which could be relevant. Now the unit of the state carried by the Item is defined by a unit metadata and the State Description Patter metadata and Item label are now used only by the UIs for display.

So assuming a recent OH 4 snapshot, add unit="W" to the Item’s metadata and keep the label as %.1f kW and the Item will continue to carry Watts but in the UI (I think even in charts) it will show kW.

That’s it. That’s all you need to do. You don’t need separate Items.

I believe it will even work if you set the unit metadata on your triggering Items to kW. The binding will send W and OH core will convert the state to kW before it gets to the Item. Again, no need for a rule and even better, no need for proxy Items.

The error in the rule is likely caused by the fact that sendCommand() requires two Strings but leistungNetzkW is a Number.
The error you are seeing is almost certainly because triggeringItem’s

1 Like

Well, that you!
That makes actually a lot of sense and is a great new feature!

I get the power in Watt from the binding but i want to handle the item as kW.
I process the item in rules and the item is also linked to a knx thing (that displays the kW values on a touch display).

Now my item looks like this:

Number:Power              EVCC_Leistung_PV                                 "PV Power [%.1f kW]"                              <energy>          (gLadesaeule)    {unit="kW", channel="evcc:device:home:general#pvPower", channel="knx:device:bridge:Diverses:Haus_Leistung_PV"}

I will check the display once i get home today but i guess it should work.

Unfortunately my rule does not fire now.

When i hover in VS Code the item EVCC_Leistung_Netz delivers -4.5 kW.
But the condition EVCC_Leistung_Netz.state < -3 does not get True back. Is it due to the unit?

what would be the right thing to set as a condition in that case?
Here’s the complete rule:

rule "Wärmepumpe PV Überschuss"
        when 
                Item EVCC_Leistung_Netz changed
        then         

                if(EVCC_Leistung_Netz.state < -3 && WP_Warmwasser_Isttemperatur.state < 44 && Haus_Energie_Sparen_II.state != ON && Powerwall_SOC.state > 75 && WP_PV_Ueberschuss_Merker.state == OFF)
                        {
                        logInfo("Waermepumpe", "PV Überschuss erkannt: Wartezeit gestartet, Grid Power (old) = "+ EVCC_Leistung_Netz.state)
                        sendNotification("","PV Überschuss erkannt: Wartezeit gestartet")
                        WP_PV_Ueberschuss_Merker.sendCommand(ON)
                        createTimer(now.plusMinutes(3),
                                        [ |                       
                                        logInfo("Waermepumpe", "Grid Power (new) = " + EVCC_Leistung_Netz.state)
                                        if(EVCC_Leistung_Netz.state <= -3)
                                                {
                                                        sendNotification("jonas.boetsch@me.com","PV Überschuss ausreichend - WW-Programm gestartet")
                                                        logInfo("Waermepumpe", "PV Überschuss ausreichend - WW-Programm gestartet")
                                                        WP_PV_Ueberschuss.sendCommand(ON)
                                                        createTimer(now.plusMinutes(60),
                                                                [ |   
                                                                sendNotification("","PV Überschuss WW-Programm beendet - WW-Temperatur: " + WP_Warmwasser_Isttemperatur.state + " °C")
                                                                logInfo("Waermepumpe", "PV Überschuss WW-Programm beendet - WW-Temperatur: " + WP_Warmwasser_Isttemperatur.state + " °C")
                                                                WP_PV_Ueberschuss.sendCommand(OFF)
                                                                ])
                                                }
                                        else    
                                                {
                                                        sendNotification("com","PV Überschuss für WW-Programm nicht ausreichend")
                                                        logInfo("Waermepumpe", "PV Überschuss für WW-Programm nicht ausreichend")
                                                        WP_PV_Ueberschuss_Merker.sendCommand(OFF)                                                
                                                }
                                        ])
                        }
end

Yes, you either need to strip the unit or use units. To use units in Rules DSL

EVCC_Leistung_Netz.state < -3 | kW

As long as the units are compatible it doesn’t matter whether they are the same. If you really mean < -3 | W and the Item stores the state as kW the comparison will still work.

1 Like

Thank yo. It is working properly now. (Item.state as Number) worked as well.

I’m of the opinion that either you should use the units or your should not. If you don’t want to use units you can now link a plain Number Item to any Number channel and the units will be thrown away. But with the improvements to units handling, they finally have become consistent and useful.

So i could also use < -3000 | W ?

Yes, as long as the operand to the left of the < is compatible with W.