Rules uninitialized after restart (PaperUI)

When restarting the openhab2 service or my raspberry pi3, rules show as uninitialized when paperui comes back up. I have MQTT binding installed, and have succesfully configured mysql persistence and jdbc yesterday. The rules issue was also there before I configured all this. I understand they were dependent on SQL/persistence, so I had hoped this issue would be resolved once I configured that.

I’ve already adjusted the configuration refresh settings in configurations/openhab.cfg as follows:

folder:items=10,items
foldersitemaps=20,sitemap
folder:rules=50,rules
folder:scripts=35:script
folder:persistence=40,persist

unfortunately the issue persists (haha), and there’s no clear solution.

1 Like

I guess you mean items, not rules?

openhab.cfg is no longer used in openHAB2.

Persistence is the correct way to solve that problem, but you have to configure it like:

// persist all items once a day and on every change and restore them from the db at startup
* : strategy = everyChange, everyDay, restoreOnStartup

So the “magic” is done through restoreOnStartup

Thanks for your reply,

I’m not a fan of semantics, but openhab calls these rules, so I do as well :wink:

[quote=“sihui, post:2, topic:27629”]
Persistence is the correct way to solve that problem, but you have to configure it like:
[/quote]
This is my persistence strategy:

Strategies {
everyMinute : "0 * * * * ?"
everyHour : "0 0 * * * ?"
everyDay  : "0 0 0 * * ?"

default = everyChange
}

                Items {
    * : strategy = everyChange, everyDay, restoreOnStartup
}

so where do I specify the mentioned setting then? Every google result that seems related to my problem still references it >_< If you could point me in the right direction, that would be helpful :smiley:

Thanks!

Okay, you are using the experimental new rules engine … sorry, I have not the slightest idea how that works, never used it.

http://docs.openhab.org/configuration/rules-ng.html

I think I still need to make sure the rules load/init AFTER persistence is loaded, since I did find multiple google results mentioning rules become/stay uninitialized because the item used in them has no current value. So when it restores the stored value before it tries to init the rules, then it might just work instantly.

Most google results reference openhab1 though, so getting this to work in openhab2 is confusing.

so, is the folder used by openhab still

/etc/openhab2/configurations

, or is it

/etc/openhab2/conf

?

I’ve deleted openhab.cfg in my configurations folder, it doesn’t make a difference. So you were right in that is isn’t being used by openhab2.

It depends on your installation method … repository or manually:

http://docs.openhab.org/installation/linux.html#file-locations

so it is either
/etc/openhab2 (repo) or
/opt/openhab2/conf (manual install)

As you have already found out, that is done through persistence and restoreOnStartup

To find out if the item value is persisted, you may use the REST Api:

http://<ip_adress_oh_server>:8080/doc/index.html

Go to Persistence -> GET /persistence/items/{itemname}, fill in your persistence service at “serviceID”, fill in your itemname at “itemname” and hit “Try it out”.

You should then see the persisted value (if your persistence service is working)

If you don’t have the REST Api available, install the “Rest Documentation” at MISC tab under Add-Ons.

I’ve confirmed both mysql and jdbc both make entries in the database (using phpmyadmin).

Nevertheless I took your advice for the REST API, which is neat! Using your instructions I got this

Request URL
http://jarvis.local:8080/rest/persistence/items/Tanganyika?serviceId=mysql&boundary=true
Response Body
{
  "name": "Tanganyika",
  "datapoints": "8",
  "data": [
    {
      "time": 1493573633000,
      "state": "21"
    },
    {
      "time": 1493573646000,
      "state": "13"
    },
    {
      "time": 1493573648000,
      "state": "0"
    },
    {
      "time": 1493575996000,
      "state": "80"
    },
    {
      "time": 1493576430000,
      "state": "52"
    },
    {
      "time": 1493576432000,
      "state": "21"
    },
    {
      "time": 1493576722000,
      "state": "73"
    },
    {
      "time": 1493576737000,
      "state": "30"
    }
  ]
}
Response Code
200
Response Headers
{
  "date": "Mon, 01 May 2017 10:35:43 GMT",
  "server": "Jetty(9.2.19.v20160908)",
  "content-length": "558",
  "content-type": "application/json"
}

If I interpret this correctly it seems to be working using MySQL :slight_smile:

when I used jdbc i got 0 data points, this makes sense because I use MySQL as the default protocol.

Yes, looks good :slight_smile: So no need to investigate further in items having no state at startup.
Unfortunately I’m not of any help regarding the experimental rule engine.

It’s still a topic about the rules being uninitialized :stuck_out_tongue: so my question is now, where can I control when these rules initialize? In my first post I post the config I used in openhab.cfg, but since that’s obsolete I should be able to control those settings in another file, no?

Thanks for the help so far though.

This is all I could find, does not help too much, was fixed end of 2016, but I guess you are using a newer build?

found the eclipse config at

/var/lib/openhab2/config/org/eclipse/smarthome

but no idea what to add or remove. I can see it nicely follows openhab in choosing MySQL as the standard interface, but that’s about it. Can’t seem to find the bundles folder in which the file I need to edit resides :frowning:

Hi there. Did you ever find a solution to this problem? I have an identical one and I too am using the experimental rules engine off which there is still naturally very little info available…

1 Like

I found today a reason why some of my rules stopped working.

I had several rules that were rather similar (all for rollershutters)
so I first created one rule that worked well.

and then I created copies for other and I replaced the active parts (aka the buttons and the rollershutters)
That worked well for all of them, and still they always stopped working and when I reloaded them with an extra space or so, they worked again.

My problem was I all gave them the same rule name

“rule rollershutter changes"
and not
"rule rollershutter bedroom Parents changes”
“rule rollershutter bedroom Child 1 changes”

What I think happened was everytime I ran one, it replaced in memory the other rule (with the same name)

yes of course functions can’t have the same name, yet when I load multiple rule files with rules with the same name, openhab does not complain (or I don’t see it)

Yves

I have added a workaround based on the solution provided at this Thread which fixes the startup rule to initialize the rules.