I suppose your post is just the perfect answer. It helped me a lot and ofc it fixed my problem.
I decided for your pimped state machine approach which looks smart and most important: I understand what it does (your comments helped there). Even if I suppose it is very basic, I wouldn’t have figured out lines like if(nLevel == 100) nLevel = 99
by myself.
After some minor adjustments, this is the final result:
var int iStep = 0
var Timer tSlats = null
var Number nLevel = 0
rule "Control slat positions"
when
Item Lamellen changed // better use "received command" or "changed" than "received update"
then
if(tSlats !== null) return; // timer already scheduled, so stop rule
if(!(Lamellen.state instanceof Number)) return; // illegal state, so stop rule
nLevel = Lamellen.state as Number // save position
if(nLevel == 100) nLevel = 99
iStep = 0
tSlats = createTimer(now.plusMillis(10)) [ // parameter is integer!
iStep ++ // short for "iStep = iStep + 1"
switch iStep {
case 1: {
Wintergarten_Jalousie_Tuer_Level2.sendCommand(nLevel)
Wintergarten_Jalousie_Tuer_Stop.sendCommand(ON)
tSlats.reschedule(now.plusMillis(3500)) // reschedule next step
}
case 2: {
Wintergarten_Jalousie_links_Level2.sendCommand(nLevel)
Wintergarten_Jalousie_links_Stop.sendCommand(ON)
tSlats.reschedule(now.plusMillis(3500)) // reschedule next step
}
default: {
Wintergarten_Jalousie_rechts_Level2.sendCommand(nLevel)
Wintergarten_Jalousie_rechts_Stop.sendCommand(ON)
tSlats = null // delete pointer to timer
}
}
]
end
For the second part of your post I now found an even better suiting astro channel in the docs to trigger my rule, which is NauticDusk_Start
. Means no need for an additional timer (or setting an offset) anymore.
The zeit_rolladen
control is currently “under construction” which is why I skipped this part for the moment. Will surely later come back to your advises and extend my current rule, which is quite handy:
rule "Close all living area shutters at NauticDusk_Start"
when
Channel "astro:sun:local:nauticDusk#event" triggered START // can be tested with a cron trigger á la Time cron "0 45 14 ? * * *"
then
gRolladen_Gesamt.members.filter[ r | r.state < 100 ].forEach[ r, i | createTimer(now.plusMillis(100*i), [ | r.sendCommand(0) ])]
logInfo("shutter", "Rule 'Close all living area shutters at NauticDusk_Start' successfully executed.")
sendTelegram("linus" , "Beginn der nautischen Abenddämmerung, alle Rollläden wurden geschlossen.")
end
Thank you again for your time and suggestions!
Marked your post as solution.