I just created another really cool automation, most certainly my favorite of all time so far. I’m beginning a top-down re-do of my entire HA to optimize it and make it actually smarter. In that I created a new system for controlling all my curtains and shades (aka covers).
What I had been doing up to now is setting each shade to some percentage based on what was happening. For example, when waking up then my scripts and automations had long sequences of “cover.open_cover” for a dozen covers. The same with many other things like going to bed or ramping down for the evening while watching TV, so on. I have a LOT of things that control my covers.
The problem with this is it is a huge pain to maintain as I come up with new “events” for which my covers are impacted I have all sorts of places to fix this up. Also as I add more and more covers to my house, again I have to touch dozens of automations and scripts. This was also slow, it often took several minutes to control multiple shades as each event fired and completed before the next event.
The new system is really cool. It starts with a sensor template, in which I have attributes for each cover in the house, each attribute is a DICT of settings of how to control each shade under certain “events” (wake up, go to bed) and then exceptions for each “condition” (climate changes, vacation mode, etc). Each attribute looks like this:
#############################################
# SIDE CURTAINS
#############################################
curtains_side: >-
{{
{
'adaptive_cover_entity': 'vertical_toggle_control_side_sliding_glass_door',
'adaptive_cover_insun_entity': 'horizontal_sun_infront_side_shade',
'events': {
'awake': {
'value': 100
},
'evening': {
'value': 50,
},
'sleeping': {
'value': 0,
'conditions': {
'swamp': 30,
},
},
'shower': {
'value': 0,
'conditions': {
'swamp': 30,
},
},
'shower_done': {
'value': 100,
},
'end_mitigation_parity': {
'value': 100,
},
}
}
}}
Then I have a script to control each shade based on these parameters. It first looks to see if the entity name is in the attributes of the sensor, if so then it looks to see if there is an event configured for the one being processed (i.e., awake), then sets the percentage to set the cover to the “value”. If it finds “conditions” within the event, it evaluates those conditions to see if there is an exception (i.e., if my swamp cooler is on and I need to leave the shade open slightly for venting). The result is the percentage that the cover should be at by the end of this run. You’ll see this in my side curtains posted above, the curtain set to 0 (close) when we shower, but if the swamp cooler is on it instead only closes to 30%. This script is set to run in parallel so that when fired on a house-wide scale it opens almost all covers simultaneously (rather than one-by-one).
This script also knows when to end mitigation (when I button the house up on really warm days), when to enable/disable adaptive covers to automatically adjust the cover to the point of letting too much direct sunlight into the room and more.
Finally a second script serves as a master script, it simply takes an event as a field (i.e., Waking Up that translates to “awake”), then runs through every single cover and sets it to the matching event value (with conditions) - it then takes the entity ID of a found cover and sends it to the first script to set the percentage of the cover.
Now the only thing I ever have to do is edit the sensor template to set all the ways I want a cover to be set based on events and conditions, no more editing dozens of automations or scripts, that one single sensor enables all automation to just always work.
Truly this is not only significantly smarter than dozens of automations, it also allowed me to remove a lot of automation and script sequences and the cherry on top is that controlling every cover in the house went from several minutes to about 45 seconds.