Hi,
I have 8 Shades, which I want to open in the morning. Depending if we have “winter” or Summer, they have different opening values. I have two scripts, that “do their job”; but IMHO look “clumsy”. So I try to change it, but with not luck.
So here is how the scripts look like: (I only show 4 shades as an example). They are named ‘cover.l1, cover.l2’ … ‘cover.l4’, ‘cover.r1’ … ‘cover.r4’
alias: WZ Rolläden 100% auf
sequence:
- target:
entity_id: cover.l1
data:
position: 100
action: espsomfy_rts.set_shade_position
alias: L1 100%
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
## 6 deleted
- target:
entity_id: cover.r4
data:
position: 100
action: espsomfy_rts.set_shade_position
enabled: true
alias: R4 100%
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
icon: mdi:roller-shade
mode: single
description: ""
The other script is basically the same, but with individual cover positions for each cover (33, 35, 47, … depending on where they are located.)
Between each cover call, there is a delay, which is needed in my environment.
I am really old, and know languages like C, perl, paascal (assembler on the C64, …), … In those languages I would have used a three dimensional array like
covers[winter][l1][100]
covers[winter][l2][100]
covers[winter][l3][100]
covers[winter][l4][100]
covers[winter][r1][100]
covers[winter][r2][100]
covers[winter][r3][100]
covers[winter][r4][100]
covers[summer][l1][0]
covers[summer][l2][0]
covers[summer][l3][34]
covers[summer][l4][35]
covers[summer][r1][38]
covers[summer][r2][37]
covers[summer][r3][38]
covers[summer][r4][38]
Than “program” something like
if $summertime than
$coveropening="summer"
else
$coveropening="winter"
fi
foreach $cover in $covers[$coveropening] do
- target:
entity_id: cover.$cover
data:
position: $covers[$coveropening][$cover]
action: espsomfy_rts.set_shade_position
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
Is there something similar, or is there a better way to do it? Reason: In the long run, I want to compute the openiung position depending on the solar azimut, but before I want to understand to handle such structured data in something like “foreach, while_do, …”. I learn best by exampley, so if yomeone has a script and would like to share it, I really would appreciate it.
thank you all for reading
Juergen