I’m seeing trouble with my modbus queried solar inverter and its generation value. I want to act on the current generated power, hence I tried as a ECMA script:
var Prod = items["Strom_Erzeugung"];
However, the item Strom_Erzeugung contains f.e, “8.6E+2 W” which, when used in a simple “if (Prod > 300)” does not work. Other items don’t exhibit this behavior so I’m thinking about the modbus binding as a source of the quest. What do you think on this?
It would be useful to confirm the type of your Item, Number or Number:Power?
Generic Modbus binding does not give units by default, but this can be configured.
More likely you are using one of the extensions, which do offer quantity type channels with units?
I’m trying to compare the number of the item’s state to a constant, say 300.
My problem is that the item’s state is not “0” (zero) but “0E+1 W” and this can’t be used in a ecma script like this:
if (items["Strom_Erzeugung"] > 300) {
events.sendCommand("Light", "ON");
}
It’s trite, but “you can’t do that”. That’s to say, you can’t compare 30W with 300 … 300 what? kW? horsepower? mW?
Your Group state, as you point out, has a unit.
Your constant needs to have units as well, or comparison is meaningless.
if (items["Strom_Erzeugung"] > new QuantityType("300 W"))
This works if your Item is in kW, mW,or indeed horsepower.
This is a more future proof approach than extracting the numeric value for a numeric only comparison (which is possible).