I have a question. I have a Number Item called “zaehler”. When my light changed from OFF to ON, the rule “count” will be start. How can I update the Number Item + 1 … ?
So always the Lamp goes on, the Item “count” will do count = count + 1 …
this does not work (this will give me “2” instead of 1… ):
zaehler.postUpdate((zaehler.state as DecimalType) + 1)
the “zaehler” item is 0 at the beginning. any ideas how to count a Item type “number” in a rule ?
2018-08-09 15:09:09.443 [vent.ItemStateChangedEvent] - zwave_device_1650b6401a7_node20_meter_watts1 changed from 0 to 18.8
2018-08-09 15:09:14.177 [vent.ItemStateChangedEvent] - zwave_device_1650b6401a7_node20_meter_watts1 changed from 18.8 to 18.4
2018-08-09 15:09:17.542 [vent.ItemStateChangedEvent] - GARTENLICHTZAEHLER changed from 0 to 1
2018-08-09 15:09:22.245 [vent.ItemStateChangedEvent] - GARTENLICHTZAEHLER changed from 1 to 2
2018-08-09 15:09:22.521 [vent.ItemStateChangedEvent] - GARTENLICHTZAEHLER changed from 2 to 3
Rule starts when the Item State Changed … and this is the power (W) … this goes from 0.5 (standby) to 16…than 18…than 18.5 so the rule see more change events and run more than once. how can I do something:
power (W) change
if over 12W …and variable “ison” = 0, than: count counter + 1
set variable “ison” to 1 (so the rule could not run again)
if power (W) under 2, set variable “ison” to 0 (so when the lamp goes on again, the rule can run again
This is my code at this time but it will not work:
var Number ison = 0
rule "Bewegungen Garten zählen"
when
Item zwave_device_1650b6401a7_node20_meter_watts1 received update
then
if (zwave_device_1650b6401a7_node20_meter_watts1.state > 12)
{
if (ison == 0)
{
GARTENLICHTZAEHLER.postUpdate((GARTENLICHTZAEHLER.state as DecimalType) + 1)
ison = 1
}
}
if (zwave_device_1650b6401a7_node20_meter_watts1.state < 2)
{
ison = 0
}
end