@rlkoshak
Okay… I just started with GPIO because for me that was the first “small step” that I could do without bringing too much complexity into learning OpenHAB. I thought: Do one small step, understand it, do next step.
Here some results of further testing:
I used this rule:
rule "Restore GPIO states"
when
System started
then
logInfo("startup.rules", "Executing »Restore GPIO states« rules")
Thread::sleep(1000)
DesktopLight_Switch.sendCommand(DesktopLight_Switch.previousState.state)
end
Logging after startup of OpenHAB says:
2018-02-07 21:04:13.104 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://192.168.0.1:8080
2018-02-07 21:04:20.186 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'gpio.items'
2018-02-07 21:04:20.891 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'influxdb.persist'
2018-02-07 21:04:26.258 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'startup.rules'
2018-02-07 21:04:31.652 [INFO ] [smarthome.model.script.startup.rules] - Executing »Restore GPIO states« rules
2018-02-07 21:04:32.673 [WARN ] [nce.extensions.PersistenceExtensions] - There is no queryable persistence service registered with the id 'influxdb'
2018-02-07 21:04:32.680 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Restore GPIO states': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
2018-02-07 21:04:34.443 [vent.ItemStateChangedEvent] - DesktopLight_Switch changed from NULL to OFF
// manual save of startup.rules to trigger refresh
2018-02-07 21:05:58.076 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'startup.rules'
2018-02-07 21:05:58.307 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'startup.rules'
2018-02-07 21:06:03.530 [INFO ] [smarthome.model.script.startup.rules] - Executing »Restore GPIO states« rules
2018-02-07 21:06:04.696 [ome.event.ItemCommandEvent] - Item 'DesktopLight_Switch' received command ON
2018-02-07 21:06:04.702 [vent.ItemStateChangedEvent] - DesktopLight_Switch changed from OFF to ON
So seems as InfluxDB persistence is very slow until finally started up?
So I solved the problem of restoring the state after bootup, but there still is something wrong about the GPIO binding, because refreshing the gpio.items still turns off my desktop light (and loggs an OFF to InfluxDB). System Startup rule isn’t triggered during refresh.