Variable cannot be initialized

  • Platform information:
    Raspberry pi 3 with latest Openhabian 3

In one of my rules I have this code:

// This rule is manually generated !

// Imports
import org.openhab.core.library.types
import org.openhab.core.persistence
import org.openhab.model.script.actions
import org.openhab.core.model.script

// Global Variables and values
var Number Thermostats = 0
var Number OldThermostat = 0
var StartLowTempTimeHours = 0
var StartLowTempTimeMins = 0
var StopLowTempTimeHours = 5
var StopLowTempTimeMins = 30
var StartLowTempTime = getZonedDateTime.now().with(LocalTime.MIDNIGHT).plusHours(StartLowTempTimeHours).plusMinutes(StartLowTempTimeMins)
var StopLowTemptTime = getZonedDateTime.now().with(LocalTime.MIDNIGHT).plusHours(StopLowTempTimeHours).plusMinutes(StopLowTempTimeMins)


rule "Nattemp"
when
    Time cron "0 0 * * * ?"
then
        logInfo("heating","StartLowTempTime: {}", StartLowTempTime)

        OldThermostat = Thermostats

        if (now.isAfter(StartLowTempTime) && now.isBefore(StopLowTempTime)) {
                Thermostats = 19
        }
        else
        {
                if(HolidayMode.state == OFF)
                {
                        Thermostats = 22
                }
        }
        var triggertDevices = gThermostats.members
        if (OldThermostat != Thermostats){
                triggertDevices.forEach [ i |
                       sendCommand(i, Thermostats)
                ]
        }
end

After saving the rule I get this warning in the logs:


2022-01-10 12:54:38.185 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'nattemp.rules'
2022-01-10 12:54:39.131 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'nattemp.rules', using it anyway:
The field Tmp_nattempRules.StartLowTempTime refers to the missing type Object
The field Tmp_nattempRules.StartLowTempTime refers to the missing type Object
2022-01-10 12:54:40.000 [WARN ] [e.runtime.internal.RuleContextHelper] - Variable 'StartLowTempTime' on rule file 'nattemp.rules' cannot be initialized with value '<XMemberFeatureCallImplCustom>.plusMinutes(<XFeatureCallImplCustom>)': The name 'getZonedDateTime' cannot be resolved to an item or type; line 16, column 24, length 16
2022-01-10 12:54:40.004 [WARN ] [e.runtime.internal.RuleContextHelper] - Variable 'StopLowTemptTime' on rule file 'nattemp.rules' cannot be initialized with value '<XMemberFeatureCallImplCustom>.plusMinutes(<XFeatureCallImplCustom>)': The name 'getZonedDateTime' cannot be resolved to an item or type; line 17, column 24, length 16
2022-01-10 12:54:41.009 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'nattemp.rules'

Any idea what is wrong with the StartLowTempTime variable ?

I don’t think you need those in OH3

As a ‘global’ variable, this is a bit weird. If it worked, it would evaluate related to ‘now’ being the load time of the rules file.

But it doesn’t work because it references another ‘global’

Yep - I found out - thank you.