I think there is still an issue with the rrd4j on the latest build (#2005).
So, cfr all the discussions before, the Item here below is definitely a Number without a QuantityType. So, why is the value returned by rrd4j through HistoricState containing a UoM, whereas the data returned through the REST interface does not contain a UoM, and this UoM is only defined in the label of the Item? Changing DecimalType to Number eliminates the error, but the result it totally wrong
.Items:
Number TechnicalFacilitiesElectricityActiveEnergy “Technical Facilities - Electricity - Active Energy [%.2f kWh]”
rrd4j :
{“name”:“TechnicalFacilitiesElectricityActiveEnergy”,“datapoints”:“1406”,“data”:[{“time”:1604563080000,“state”:“123945.0”},{“time”:1604563140000,“state”:“123945.0”},{“time”:1604563200000,“state”:“123945.0”},{“time”:1604563260000,“state”:“123945.0”},{“time”:1604563320000,“state”:“123945.0”},{“time”:1604563380000,“state”:“123945.0”},{“time”:1604563440000,“state”:“123945.0”},{“time”:1604563500000,“state”:“123945.0”},{“time”:1604563560000,“state”:“123945.0”},{“time”:1604563620000,“state”:“123945.0”},{“time”:1604563680000,“state”:“123945.0”},{“time”:1604563740000,“state”:“123945.0”},{“time”:1604563800000,“state”:“123945.0”},{“time”:1604563860000,“state”:“123945.0”},{“time”:1604563920000,“state”:“123945.0”},{“time”:1604563980000,“state”:“123945.0”},{“time”:1604564040000,“state”:“123945.0”},{“time”:1604564100000,“state”:“123945.0”},{“time”:1604564160000,“state”:“123945.0”},{“time”:1604564220000,“state”:“123946.0”},{“time”:1604564280000,“state”:“123946.0”},{“time”:1604564340000,“state”:“123946.0”},{“time”:1604564400000,“state”:“123946.0”},{“time”:1604564460000,“state”:“123946.0”},{“time”:1604564520000,“state”:“123946.0”},{“time”:1604564580000,“state”:“123946.0”},{“time”:1604564640000,“state”:“123946.0”},
.rules:
logInfo("org.openhab", "Calculate daily electric energy consumption : Current : " + TechnicalFacilitiesElectricityActiveEnergy.state)
logInfo("org.openhab", "Calculate daily electric energy consumption : Midnight : " + TechnicalFacilitiesElectricityActiveEnergy.historicState(now.minusHours(now.getHour()).minusMinutes(now.getMinute())).state)
var gToday = TechnicalFacilitiesElectricityActiveEnergy.state as DecimalType - TechnicalFacilitiesElectricityActiveEnergy.historicState(now.minusHours(now.getHour()).minusMinutes(now.getMinute())).state as DecimalType
logInfo("org.openhab", "Calculate daily electric energy consumption : Today : " + gToday)
bundles:
184 │ Active │ 80 │ 3.0.0.202011032318 │ org.openhab.core.persistence
248 │ Active │ 80 │ 3.0.0.202011020022 │ org.openhab.persistence.rrd4j
Output:
2020-11-06 08:41:44.567 [INFO ] [org.openhab.core.model.script.org.openhab ] - Calculate daily electric energy consumption : Current : 124008.0
2020-11-06 08:41:44.569 [INFO ] [org.openhab.core.model.script.org.openhab ] - Calculate daily electric energy consumption : Midnight : 123998.0 kWh
2020-11-06 08:41:44.571 [ERROR] [utomation.module.script.internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘consumption-3’ failed: Could not cast 123998.0 kWh to org.openhab.core.library.types.DecimalType; line 30, column 84, length 108 in consumption
If I now change the one line to
var gToday = TechnicalFacilitiesElectricityActiveEnergy.state as Number - TechnicalFacilitiesElectricityActiveEnergy.historicState(now.minusHours(now.getHour()).minusMinutes(now.getMinute())).state as Number
then the output is
Calculate daily electric energy consumption : Today : -446389075992.0