I have the following automation where I need to shut down the covers if the elevation of the sun has become the higher point of the day (approx 73.8) and start falling. I have test the following code but didn’t work yesterday. Any ideas what I should do?
- id: Covers Close in SummerTime
alias: Covers Close in SummerTime
trigger:
- platform: numeric_state
entity_id: sun.sun
value_template: "{{ state.attributes.elevation }}"
below: 73
above: 72
condition:
- condition: template # Only between these dates
value_template: >
{% set fromts = '06-01' %} ##### apo 01 Iouniou mexri 30 Augoust
{% set tots = '08-30' %}
{{ fromts <= now()|as_timestamp|timestamp_custom('%m-%d', False) <= tots }}
May I ask, if I can use the sun rising attribute in a template?
I see now that is still rising = true maybe later (after 73) will give false and then I could have 2 conditions like rising=false and below 68?
I have added the binary sensor from the trend example which right now is on (so in my case a condition to be off) but if I can do the job with the sun integration (above) I would prefer it (to keep the minimum of sensors)
I am trying it right now. However I have this trigger in another automation and it is working.
What it seems wrong is in the second condition the " - " sign
it is black in my configurator instead of red as all other conditions. is that meaning something?
I just read through this topic. How about using this for a trigger:
trigger
- platform: template
value_template: "{{ not state_attr('sun.sun', 'rising') }}"
This will become True, and hence trigger the automation, when the rising attribute of sun.sunchanges to False (i.e., the sun begins going down.) It will not trigger again until the attribute changes to True (starts to rise) and then back to False (starts to go down.) I.e., it will trigger once a day when the sun starts to go down. I believe that is what you’re looking for.
Also, the condition in your OP works because of the way the strings are formatted. Normally doing string comparison of numbers, dates, etc. can be unpredictable. But, I have to ask – why do you use False in the timestamp_custom() function? That means you want UTC, not the local time zone. You’re probably “getting away” with this because the condition is only evaluated at midday, when the UTC date and local time zone date are more than likely the same. I’d suggest, however, you really should use True (i.e., use local time zone.)
condition:
- condition: template # Only between these dates
value_template: >
{% set cur = now().date() %}
{% set from = strptime(cur.year ~ "-06-01", "%Y-%m-%d").date() %}
{% set to = strptime(cur.year ~ "-08-30", "%Y-%m-%d").date() %}
{{ from <= cur <= to }}