[SOLVED] Count on/off´s

Hi there, I have a motion sensor lamp in my garden. This lamp is switched completely on/off with a Fibaro Single switch 2:

Fibaro switch on: motion detected --> Light on
Fibaro switch off: no motion detection because of no current on the whole lamp.

When the light is on, after detected motion, then the Fibaro switch tell me the actual current and power comsumption.

How can I count, how often the lamp was on ? The easiest way is to count how many times the power comsumption was over 2W. because: Lamp off: 0.1W Lamp on: 15W.
I want to have a simple Number in HABpanel which say for example: Lamp on: 3x.

Is that easy ? :slight_smile: thanks for hints

Buld a rule triggered by comsumption changed and check in the then part, if comsumption is greater 2W and last comsumption was less 2W.

okay. can you show me an example how to set a variable to count, in the rule ?
I know it in C and C++ but I have zero experience in rules syntax :thinking:

I did a rule for that, and a Item “GARTENLICHTZAEHLER” type Number… but I get this error:

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Bewegungen Garten zählen': Unknown variable or command '>'; line 6, column 13, length 41
rule "Bewegungen Garten zählen"
when
        Item zwave_device_512_node20_meter_watts1 received update
then
        if (zwave_device_512_node20_meter_watts1 > 10)
        GARTENLICHTZAEHLER.postUpdate((GARTENLICHTZAEHLER.state as Number) + 1)
end
        if (zwave_device_512_node20_meter_watts1.state > 10) {
                if (GARTENLICHTZAEHLER.state == NULL) {GARTENLICHTZAEHLER.postUpdate(0)}
                GARTENLICHTZAEHLER.postUpdate((GARTENLICHTZAEHLER.state as DecimalType) + 1)}
1 Like

Hi, big thanks for that. It works perfect. Now I have a good example for other rules like this !