Exec Binding 2.1: String Calculations

Hi

Today I tried to update from the old the the new Exec-Binding. Unfortunately Items are only working as String and not as Number.

Items:
String PV_Tag “Tagesertrag [%s kWh]” {channel=“exec:command:pv_tag:output”}
String D0_Abgabe_Tag “Tagesabgabe [%s kWh]” {channel=“exec:command:abgabe_tag:output”}

Results (that means exec commands are working):
PV_Tag = 39.9
D0_Abgabe_Tag= 30.6

Now I need to calculate this within a rule:
PV_Tag - D0_Abgabe_Tag

Before it was working with:
var ev = PV_Tag.state as DecimalType - D0_Abgabe_Tag.state as DecimalType

How can I do this with String-Items?

Thanks
Michael

There are some suggestions here

I have solved the problem with a rule, see here

https://community.openhab.org/t/convert-string-item-to-number-item-in-oh2/25424

:+1::clap:

var ev = Double::parseDouble(PV_Tag.state.toString) - Double::parseDouble(D0_Abgabe_Tag.state.toString)
postUpdate(P_EV, ev)

To be honest I don’t know really what’s exactly happening with Double::parseDouble but it’s working now :slight_smile:

Thanks
Michael