Conversion of groupitem to Decimaltype

Dear all,

I want to implement a rule to check that my wallbox is not using to much power out of my house batteries. It uses a GroupItem which is defined as the sum of all battery currents. If the sum is below -10.0 (equal to ~500W) it shall switch off both wallboxes.

rule "Max Batteriestrom Wallbox"
when
    Item gSum_Bat_current changed
then
    if ((gSum_Bat_current as DecimalType + 10.0) < 0.0) {
        WallBox_Fenster_S.sendCommand(OFF)
        WallBox_Wand_S.sendCommand(OFF)
    }
end

When the rule is triggered I get the following error messeage:

Script execution of rule with UID 'PV_control-12' failed: Could not cast gSum_Bat_current (Type=GroupItem, BaseType=NumberItem, Members=6, State=29.4, Label=Gesamtstromstärke, Category=battery, Groups=[gPV]) to org.openhab.core.library.types.DecimalType; line 254, column 10, length 31 in PV_control

Thanks for your help!

gSum_Bat_current is an Item, not a State. DecimalType is a State. You can’t cast something into something it’s not.

You need to cast the gSum_Bat_current.state.

1 Like

I changed it so often to cope with the decimal figure that I forgot the basics! Thank you!