Hi all
Trying to wrap my head around this for a quite a while, and thought of reaching out to the community for a clue.
Problem in a nutshell:
Persistence not returning proper previous state.
I’m working on a user configurable home automation solution with dynamic items, sitemaps and rules creations. One of the problems I have is when an unexpected power cycle happens (which is bit common in this part of the world), my end-points (ESP8266 driven relays) comes back on-line with all relays at on position. To resolve this issue, Im programming my endpoints to send a message (MQTT) every-time they boot-up and have an item in my items file to receive it.
String mqtt_init "MQTT Initiation message" {mqtt="<[halmqtt:HAL_COM/MQTT/init:state:default]"}
Then I created a rule to reply back with previous state of the items so the end point can restore the original states. I understand restoreOnStartup does this, but there’s no openhab startup here, just the end-points, and hence the workaround. I have following logInfo line in the rule just to check if it works
rule "Persistance"
when
Item mqtt_init received update
then
logInfo("Persistance","Rules kicked")
logInfo("Persistance",my_item.previousState())
end
This is where things go south. I get following lines in the openhab.log
2018-07-09 16:14:16.415 [INFO ] [e.smarthome.model.script.Persistance] - Rules kicked
2018-07-09 16:14:16.427 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Persistance': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null
First I though my persistence setting were wrong, but I observed them properly recorded in the MariaDB table:
±------------------------±------+
| time | value |
±------------------------±------+
| 2018-07-09 14:55:51.683 | ON |
| 2018-07-09 15:05:11.226 | OFF |
| 2018-07-09 15:05:31.963 | ON |
| 2018-07-09 15:09:10.782 | OFF |
| 2018-07-09 15:09:11.937 | ON |
| 2018-07-09 15:11:53.551 | OFF |
| 2018-07-09 15:11:55.450 | ON |
| 2018-07-09 16:17:11.086 | OFF |
| 2018-07-09 16:17:12.154 | ON |
±------------------------±------+
Any idea why Im not getting proper previousState in this situation?