Light scenes: Best way to store default values

Hello,

I’m planning to write a few scripts to control different lighting scenarios:

I have different rooms
I have a couple of rgb Light bulbs in a room.
I like to adjust them interactive through the openhab app
I have some light scenarios i.e. Nighttime, TV, Movie, Daytime… as multiple selections
I have a “update” button to save the current setup for the currently selected scene.

In the end i have to store a lot of values in an array (?)

[room, scene, light, r/g/b/…] = value

before I mess around with hundrets of items I have the question:

What is the best way to store these “preset” values. The values should be restored after a restart.

I like to use reusable rules (lambdas) to use them in different rooms (I read there is a limitation using global variables)

Is there an elegant integrated way or do I have to use an persistent binding (and what is the best to store the data)

Thank you for any ideas, tips or examples.

Chris

There are two ways to do this.

If all the rules/lambdas that depend on these values are in the same .rules file you can store them in a global val/var and populate/restore them using a rule triggered by System started. There are ArrayLists and Hashtables available for you to store the values if single Items is not an option.

My prefered approach is to create Items to store the values, name the Items in such a way that I can find them by name in my rules and put the Items into Groups. In my rules I can programmatically construct the names and get a reference to the Item by name using MyGroup.members.filter[i | i.name == "name"].head. Again you would populate the Items using a System started rule but if you have persistence/restoreOnStartup you only need to use that rule the very first time to give the Item an initial value. After that persistence will restore it.

Persistence IS the elegant integrate way to restore values on startup.

If all you care about is restoreOnStartup I recommend MapDB. It only saves the most recent value so it never grows and it can store all data types. If you do care about historic data but not for data that is that old or you don’t care if the data gets monkeyed with over time rrd4j is good because the DB files stay a fixed size. If you want accurate historical data for analysis I’d recommend MySQL or InfluxDB.

You do not have to settle on only one persistence either. You can use MapDB to restore the values for all your items on startup, rrd4j just for those Items you may care about recent values, and MySQL for those Items that you really want to study.

Based on this comment I might recommend organizing your items and rules files by function instead of room. That way it is much easier to share lambdas and code with similarly functioned Items. Manage organization by rooms on your sitemap.

Thank you for your advice. I´m very busy at the moment, and will do a test soon (I hope). Will report an any progress or further trouble.

Chris