I'm getting an error while trying to save switches last state

  • Platform information:
    • Hardware: Raspberry Pi
    • OS: OH2


rule "Controls Initializing"
    System started
    logInfo("ControlsInitializing", "Controls Initializing ------>")
    Thread::sleep(5000) // need to experiment to find the right value to ensure all the Items have been restored

    // logInfo("InitializingControl", "GPIO_Light_state.state: " + GPIO_Light_state.state.toString)
   if( (GPIO_Light != null) && (GPIO_Light_state.state != null) ){
        logInfo("GPIO_Light", GPIO_Light_state.state.toString())
        // GPIO_Cooler.sendCommand(GPIO_Cooler_state.state.toString())
        // GPIO_FanCeiling.sendCommand(GPIO_FanCeiling_state.state.toString())
        // GPIO_Fan.sendCommand(GPIO_Fan_state.state.toString())


rule "Controls Update"
    Member of Control received command
    // logInfo("UpdateControl", "Controls Update >>>>>>>>>")
    // logInfo("Update Control", "---------------> Member " + triggeringItem.name + " to " + receivedCommand)

    switch triggeringItem.name {
        case "GPIO_Light"           : GPIO_Light_state.postUpdate(receivedCommand.toString())
        case "GPIO_Cooler"          : GPIO_Cooler_state.postUpdate(receivedCommand.toString())
        case "GPIO_FanCeiling"      : GPIO_FanCeiling_state.postUpdate(receivedCommand.toString())
        case "GPIO_Fan"             : GPIO_Fan_state.postUpdate(receivedCommand.toString())
        // default                     : logInfo("Update Control", "Error in switch! item:" + triggeringItem.name)


2019-11-19 05:51:52.857 [INFO ] [me.model.script.ControlsInitializing] - Controls Initializing ------>

2019-11-19 05:51:58.387 [INFO ] [se.smarthome.model.script.GPIO_Light] - OFF

2019-11-19 05:51:58.396 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Controls Initializing': Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null

What exactly are you trying to achieve here?
I think this could be a case of the XY Problem

i’m trying to save switches last state and restore the switch state after system started .

For such task you could use mapdb ( stores only the last state) to persist all(?) items with the strategy restotreOnStartup. That should fo your complete desired task.

1 Like

As opus said, use mapdb and restore on startup. This is what is was made for:



My mapdb.persist file:

// mapdb persistence

Strategies {
	default = everyChange
Items {
    * : strategy = everyChange, restoreOnStartup

thanks , I’m using rrd4j persistence

You are not listening
Use mapdb for restoreonstartup
You can use several persistence service at the same time. (I use 3)

1 Like

thanks a lot

For the curious,

was probably intended to be
if( (GPIO_Light !== null) && (GPIO_Light_state.state != NULL) ){

NULL is the valid state all Items take up at creation.