Global number items (counter) do not work


I would like to achieve the following:
OH should send a message (telegram) once per day for multiple tasks (e.g. warning if CO2 is too high in the living room).

So I have set global counter items like:
Number counterCO2
and use it in the rules like:

rule "CO2@Home"
    Item Netatmo_Indoor_CO2 changed
    if(counterCO2 == 0) {
        if(Netatmo_Indoor_CO2.state > 1000) {
            sendTelegram("OH_TeleBot", "CO2 Konzentration zu hoch!\nIhr solltet lüften!")
                counterCO2 = counterCO2 + 1

This counter should be reset every morning:

rule "Set Daytime"
    Item Weather_Sunrise_Event changed to ON
// reset all "once per day" local counter
    counterCO2 = 0
    logInfo("weather.rules: ", "Daily counters have been reset")

Unfortunately I get an error in OH.log:

2016-10-14 07:51:01 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Set Daytime': org.eclipse.xtext.util.PolymorphicDispatcher$NoSuchMethodException: Couldn't find method ''_assignValue'' for objects [org.eclipse.xtext.common.types.impl.JvmGenericTypeImplCustom@16878be (visibility: PUBLIC, simpleName: NumberItem, identifier: org.openhab.core.library.items.NumberItem) (abstract: false, static: false, final: false, packageName: org.openhab.core.library.items) (interface: false), <null> counterCO2 <XNumberLiteralImpl>, 0, org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext@ce7d90, org.eclipse.xtext.util.CancelIndicator$1@13806b6]

Previously I had this structure in one rule (all rules within one single file and used the counters locally. This was working like a charm.

What might be wrong here?
Any idea?

Just as you look at the .state of Netatmo_Indoor_CO2 item, so you would look at the .state of counterCO2 when doing comparisons.

When you want to update (increment or zero) an item, use postUpdate

You’re damn right - thanks for seeing this.

however - I still get:
2016-10-14 11:51:52.142 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘CO2@Home’: An error occured during the script execution: The name ‘.state’ cannot be resolved to an item or type.

And Eclipse Designer says:
The method or field state is undefined for the type Number…

got it - just changed to switches instead of counters :slight_smile: