Items, Sitemap saves change switch states

Hi Guys

Pretty sure this is an easy one but I haven’t found the answer, so thanks in advance.
I have been hitting the keyboard hard lately modifying my sitemap and items (was in dire need of a clean up) and every time I make a change and save the files the switch states reset eg.
I have a presence switch which is updated by a http post and every save changes the state, this obviously throws the switch state out of whack!

How can I have the item/switch go to the previous state?

This is also affected when OH is restarted- What code should be added to rules/items for system restarts? Some examples would be fine.


The states of items should only be affected in saving .items (and maybe .rules) files. To make openHAB to restore items at startup / when rereading .items, you have to setup persistence for these items. For only restoring to the last known state, mapdb is sufficient (this one won’t grow because mapdb only saves the last state)
For this copy org.openhab.persistence.mapdb....jar to addons folder and setup a file mapdb.persist in folder persistence:

// persistence strategies have a name and a definition and are referred to in the "Items" section
Strategies {
    // if no strategy is specified for an item entry below, the default list will be used
    default = everyChange

 * Each line in this section defines for which item(s) which strategy(ies) should be applied.
 * You can list single items, use "*" for all items or "groupitem*" for all members of a group
 * item (excl. the group item itself).
Items {
    // persist all items on every change and restore them from the db at startup
    * : strategy = everyChange, restoreOnStartup

Changes in rules can affect the items because a system started rule will be triggered immediately.

thanks for the quick response Udo.
I will try this when I get home.

thats done the trick.
Thanks again :slight_smile: