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.
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
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).
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:
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.
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.