Issue with Rule and math operations

Hi folks,

I’ve two number items, Charge and Capacity.

I would like to have BatteryLevel (%) = Charge / Capacity

The following rule:

Rule "Roomba Battery Level (%)"
when
    Item RooWifi_Roomba871_Charge received update or
    Item RooWifi_Roomba871_Capacity received update
then
    val DecimalType batterylevel = new DecimalType(((RooWifi_Roomba871_Charge as DecimalType) / (RooWifi_Roomba871_Capacity as DecimalType)) * 100)
    RooWifi_Roomba871_BatteryLevel.postUpdate(batterylevel)
end

is generating this ERROR:

2018-06-20 14:11:34.876 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Roomba Battery Level (%)': Could not cast RooWifi_Roomba871_Charge (Type=NumberItem, State=2657, Label=Roomba 871 Charge, Category=null, Groups=[gHouse, gBatteries]) to org.eclipse.smarthome.core.library.types.DecimalType; line 28, column 54, length 39

What I’m missing?

thanks
Andrea

RooWifi_Roomba871_Charge.state
1 Like

ahahaha uops :slight_smile:

thanks @Josar

Noticed your rule question regarding roowifi, I have a roomba, it’s it a modern roomba with WiFi or a module added to the roomba?

Hi, this is a 871 model with roowifi module. It works, but bear in mind you need to use roomba as access point, then connect to it via wifi interface (and play with routing in your debian vm).

Andrea