I’m new to Openhab and already ran into a problem.
I have several items in my configuration, mostly switches. I want to assign special ids to these switches with whom I can get direct access to them in the rules. In my case a get an input via serial binding, parse it and its containing information in the rules and then do special actions later on.
My goal is to “find” the Switch with f.e. pin=8 (which can change, depending on the serial bindings input) within the code.
I’m accessing all these items/switches with this code:
myMansion?.members.forEach(theitem|…)
Is there something like
theitem.getattr(“pin”)
available to get access to its attributes? Haven’t found anything yet. If not, which would be the correct way to do something like this?
You wouldn’t really want to peer inside the binding config strings in your rules, as you are trying to be at a level of abstraction higher than the bindings. But there is a lot of power in setting up maps as data you can access within your rule files.
val itemsPins = newHashMap(
"myMansionSwitch1" -> 8,
"myMansionSwitch2" -> 9
)
rule x
when something
then
var pin = itemsPins.get("myMansionSwitch2") as Integer // sets pin to 9
// ...
end