So I want to have several different rules, which will be triggered by different items, but all rules will somehow turn on a Wifi LED controller. I want to set different color, brightness, etc in the rules. However I don’t want to lose the previously set (colors and brightness). So in general I want to achieve that when the rule ends, it should turn off the leds and send the previous setting to the LEDS. So when I turn it on again, manually, not by rule, it will turn on as I set it before.
I have read that there is a previousState command, but how does it work? Does it work on all kind of items? It will always return the last (previous) state?
Little bit off, but I have a MagicHome LED Controller and for now, it seems that it only accepts commands after the LED turns on. I mean it receives the command, sets the colors for example, but when I turn it on, it will turn on with previous setting, not which I set up. Any ideas, someone has the same problem or a solution?
See the storeStates and restoreStates Actions here: https://www.openhab.org/docs/configuration/actions.html#event-bus-actions
previousState(true) could work but you need to have persistence set up on these Items using a DB that is not MapDB or rrd4j. With the actions above you just need vars.
Thanks! Vars are global in rules? So can you acces a locally created var from another rule? I thought that it is destroyed everytime the rule returns…
It depends on where you define them. If you define the var in the Rule then it only exists in that Rule and gets destroyed when the Rule exits. If you define them at the top of your .rules file they persist and multiple Rules can use them.
The Variable Declarations section can be used to declare variables that should be accessible to all rules in this file. You can declare variables with or without initial values and modifiable or read-only.
Oh, thank you very much!
Good to see that most programming conventions is used here, however I don’t know everything regarding openHab so I don’t know what can be used and not…