The range of times is because I want it to trigger when it’s around sunset, during times that may be getting dark but not always - without interfering with other automation I have that control the same lights at/after sunset nor during the day. That part has been working fine.
I’m sure it could use some refining, but at this point I’m still not 100% certain exactly what I want to specify all the requirements. More or less, if it’s late day or nearing sunset, I want to turn on lights if it’s cloudy, or if it becomes cloudy during that time. Then I decided I also want it to turn on lights at a specific earlier time if it’s cloudy, even if sunset is much later.
I only got started with this back in Jan/Feb and my rules worked great…until I noticed with a summer storm even though sunset was much later I wanted it on at an earlier “evening” time like a traditional lamp timer I’m replacing (which would dumbly waste power turning on even if it’s sunny). Adding the “at 16:00” handles the case I hadn’t considered of “it’s stormy all day and sunset is late in summer”.
The biggest problem I’m having is figuring out how to translate what (in my head as a programmer) I am thinking about “less-than / less-than equal-to / just equal-to” type conditions I’d do in C++/Java to the words-ing that YAML uses to play with the options I think I want. In a “normal” program I’d just have an event loop trigger at 16:00 and add an “or” to my if-checks to “now == 16:00” but with YAML that’s an at
in one place and apparently you can’t at
it in another place as an “equal” condition so ??? and then I want to keep things reasonably maintainable so I am trying to avoid having several automation that do the same thing on minimally different conditions (in a program I’d use “functions” to encapsulate but that’s not a thing apparently with YAML).
- alias: "Kitchen Lamp Timers On Cloudy Evening"
trigger:
# If it's near sunset, or stops being sunny, or hits 16:00, try and do it
- platform: sun
event: sunset
offset: "-01:30:00"
- platform: template
value_template: "{{ states('weather.home') != sunny }}"
- platform: time
at: '16:00:00'
condition:
# If it's getting near (but still early) sunset, or at 16:00, let it go thru
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: "-01:30:00"
before_offset: "-00:45:00"
- condition: time
after: '15:59:59'
before: '16:00:01'
# but only if it's not sunny (cloudy, rainy, foggy, whatever)
- condition: template
value_template: "{{ states('weather.home') != sunny }}"
action:
service: input_boolean.turn_on
data:
entity_id: input_boolean.kitchen_lamp_timers_on
I’m open to other ideas, but I have “daytime” automations I don’t want to overlap with and “approaching sunset” automations I don’t want to overlap with. I believe that has been working correctly though.
Some of this is also finding what DO I want it to do. I’m still not used to the flexibility of more than a dumb lamp timer…which I would just manually push in some extra pins if it was stormy for some days to make it on longer, or pull them out as the days were shorter. This can do it automatically but I haven’t thought of WHY I want it on, used to just be like “oh it should be on earlier” and move a pin, not considering the specifications for that decision.
So I want to implement what I think I want, and then if I don’t like it I’ll change it again.