TLDR Summary: I’d like to simplify my window cover automations based on Sun’s azimuth and elevation which currently span across 8 times 10 different automations (that is for 8 covers, 10 different azimuth value triggers per cover). I’d like to squeeze them into 1 automation per cover with some “If This Than That” coding magic inside the automation, if possible. Example of current automation below. If interested in the background, go on with reading my intro, otherwise skip to The Riddle section
Intro :
Dear Community,
I’m a huge fan of HA, and I’m done with a couple of integrations and automations, but what I’d like to achieve here is far beyond my programming capabilities
I’d like to automate my window covers based on how intense (meaning summer, don’t plan to use any LUX sensor, yet) and direct sunlight hits my windows, to maximize cooling effect during summer, and heating effect during winter (which seems to be easier since I just have to keep the covers open after sunrise )
I saw a couple of solutions, but they require far more knowledge than I’m in possession at the moment (node red blind automation, or appdaemon based python scripts), so for now I’d like to keep it simple and do it the old fashioned way, via automation.
The general idea is:
- based on the azimuth range where each cover gets hit by sunlight, and based on the elevation range from where I know I’m into the summer season and heating effect is intense, I’d like to partially shut the cover.
- Each 10 degree change in azimuth should correspond to a 10% movement of the cover.
- from the start of the azimuth range until the peak value the covers have to close 10% at each 10 degree change of azimuth until they are closed 100% at the peak azimuth value, and from then on they should open gradually again by 10% steps with each 10 degree change of azimuth
- there are a couple of condition on the automation whether it should fire or not:
- sun above horizon
- alarm system is disarmed (meaning we are not at sleep)
- sun’s elevation is greater then a certain value, meaning we are already in the hot season
- cover is not closed (which could mean my daughters are still sleeping even though the alarm system was disarmed by any other family member)
Here comes my problem: I can have (I mean: with my current programming capabilities ) 1 single automation to trigger a 10% percent movement action (either up or down, depending on the azimuth value) when the exact azimuth value kicks in. But since I have to cover around 100 degree change per each window, this would mean 10 different automation per cover, one for each 10 degree shift in azimuth!
(Eg:
- at azimuth=100 degree, if cover is open, close it to 90% open state, if cover is closed, skip automation;
- at azimuth=110 degree, if cover is open, close it to 80% open state, if cover is closed, skip automation;
- … and so on, I’m sure you got the point
The Riddle:
How can I convert this single automation which only kicks in at one single predefined value of azimuth to work with multiple predefined values of azimuth, and trigger different cover positioning action tied to a certain azimuth value? (azimuth=100, then open cover to 90%, azimuth=110 then open cover to 80%, and so on, I have a complete table of this matrix which I can provide if needed). Doing this while checking a couple of conditions at each step which could block running the automation: if alarm is in armed state, do nothing, if sun is below horizon, do nothing, if cover was closed before a closing step, do nothing)
Current version (code copied from automation editor’s YAML view):
alias: Windows cover automation based on Sun's azimuth and elevation (EAST side, azimuth=150)
trigger:
- platform: template
value_template: '{{ state_attr(''sun.sun'', ''azimuth'') |int == 150}}'
condition:
- condition: state
entity_id: sun.sun
state: above_horizon
- condition: state
entity_id: alarm_control_panel.area_1
state: disarmed
- condition: template
value_template: '{{ state_attr(''sun.sun'', ''elevation'') |int > 30 }}'
- condition: device
device_id: e4b4762c0041876dc3f25858ffd64a9d
domain: cover
entity_id: cover.EAST1
type: is_position
above: 1
- condition: device
device_id: 6805b32285feb03729995581b171643d
domain: cover
entity_id: cover.EAST2
type: is_position
above: 1
action:
- service: cover.set_cover_position
target:
device_id: cover.EAST1
data:
position: 80
- service: cover.set_cover_position
data:
position: 80
target:
device_id: cover.EAST2
mode: single
Sorry if this post was too long, I wanted to be as clear and specific as I could.
Any help – preferably in the form of exact code – is greatly appreciated!