[SOLVED] Reading values from a data-source for further usage in rules

Hi there!
I’ve got a question regarding a way to retrieve values from a data-source in order to drive my rollershutters into a specific position.

First of all I’d like to mention that my rollershutter rule works fine. Basically I’ve defined 6 different “sun-states” like “morning”, “before noon”, “noon”, “afternoon”, “evening” and “night”. Each of these “sun-states” is defined by a combination of azimuth and elevation, provided by the astro-binding.

If the “sun-state” changes from one to another, hard-coded rollershutter-positions are sent to my KNX-bus. And this is the point where I’d like to ask for your ideas, because I’d love to have a seperate data-source where I can define the positions per state and item and OH just reads a specific datarow if needed.

That data-source doesn’t have to be a database, but it would be nice if it’s an “easy-to-read” thingy so if changes are needed I don’t have to touch the rule.

As always, many thanks in advance for your time & BR,

Use an array or a hash map. :slight_smile:

If you have a simple mapping you can use a .map file and the transform Action. It’s a special case of Design Pattern: Human Readable Names in Messages. That would probably be the easiest approach that doesn’t involve hard coding the values into a Rule.

If you use JSR223, you can utilize Item metadata for this, and keep the information in the Item itself. I use this for all of my lighting, including color, and have also included timer values for longer delays and to shutoff speakers, etc. Here is an early writeup that I did…

Hi guys,
many thanks to all of you - I decided to go with arrays and wanted to share my working (simplified) result.

// don't forget to import!
import java.util.List
// get current rollershutter state (from other rule)
// it's important to cast to INT here, because otherwise you can't {get} the value at the desired array-index
var int current_rollershutter_state = (your_global_variable as Number).intValue
// initialize an array to store your desired positions per state
var List<Number> your_rollershutterpositions = newArrayList(10,20,30,40,50,60)
// retrieve the rollershutterposition for a given state
var Number specific_rollershutter_targetposition = your_rollershutterpositions.get(current_rollershutter_state)
// send command to a specific rollershutter

Thanks & BR,