rule "Controls Initializing"
when
System started
then
Thread::sleep(30000)
Control.members.forEach[ i | i.sendCommand(i.previousState().state as OnOffType) ]
end
error:
2020-09-20 14:29:05.845 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Controls Initializing': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
That suggests that one or more of your Items does not have a persisted state.
Have you a persistence service installed, are your Items configured to persist, is that part working, is the system default service the one you expect?
Thanks @rossko57 for respond
I’ve a mapdb and rrd4j running
mapdb.persist
Strategies {
// for rrd charts, we need a cron strategy
everyMinute : "0 * * * * ?"
everyHour : "0 0 * ? * *"
everyDay : "0 0 0 * * ?" // Every day at midnight - 12am
default = everyChange
}
Items {
// persist all items on every change
* : strategy = everyUpdate, restoreOnStartup
}
rrd4j.persist
Strategies {
// for rrd charts, we need a cron strategy
everyMinute : "0 * * * * ?"
everyHour : "0 0 * ? * *"
everyDay : "0 0 0 * * ?" // Every day at midnight - 12am
default = everyChange
}
Items {
// persist all items on every change
* : strategy = everyUpdate, restoreOnStartup
}
but I did not set a default service
runtime.cfg
################ PERSISTENCE ####################
# The persistence service to use if no other is specified.
#
#org.eclipse.smarthome.persistence:default=
Then it won’t work. previousState() pretty obviously asks the default service for data.
You can set the default, or tell previousState() which service to use.
off topic - why would you want both db to store everything and restore everything?
I don’t know what I’m doing :))
I’m using charts for temperature and humidity and weather
which one do you suggest to use for charts, switches, settings ?
Thanks a lot
Strategies {
// for rrd charts, we need a cron strategy
everyMinute : "0 * * * * ?"
everyHour : "0 0 * ? * *"
everyDay : "0 0 0 * * ?" // Every day at midnight - 12am
default = everyChange
}
Items {
// persist all items on every change
Sensors* : strategy = everyChange, everyUpdate, restoreOnStartup
}
mapdb.persist
Strategies {
default = everyChange
}
Items {
// persist Control items on every change
Control*, ControlPeriod : strategy = everyUpdate, restoreOnStartup
}
rules
rule "Controls Initializing 2"
when
Member of Control changed
then
logInfo("sps.ControlsInitializing2", "triggeringItem:" + triggeringItem.name + ".previousState(): " + triggeringItem.previousState().state.toString + " state: " + triggeringItem.state.toString)
end
I’m still getting errors
2020-09-20 15:37:30.752 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Controls Initializing 2': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
Changes that you make to persistence settings do not take effect until the packages involved have been restarted.
I’ve never understood the habit of stuffing many operations into one line and then struggling to find out which bit is broken. Break it open, go step by small step.
logInfo("sps.ControlsInitializing2", "triggeringItem:" + triggeringItem.name)
logInfo("sps.ControlsInitializing2", "current state " + triggeringItem.state.toString)
var results = triggeringItem.previousState()
if (results == null {
logInfo("sps.ControlsInitializing2", "Item has no default stored data")
} else {
logInfo("sps.ControlsInitializing2", "historic state " + results.state.toString)
}
As you are relying on your chosen persistence service having somestored data to return, it’d be smart to find out if there actually is any stored data for that Item and that service. The REST API is a useful tool for this.