I have this autonation. I want it to run every morning at 06:30 and if the sun has not risen yet at this time, lights should be turned on. Today the sun rose at. 06:20 and the automation still ran.
alias: Turn on Lights in the morning
description: ""
trigger:
- platform: time
at: "06:30:00"
condition:
- condition: time
weekday:
- tue
- thu
- mon
- wed
- fri
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
below: -2
action:
- type: turn_on
device_id: c86bba1
entity_id: light.ikea_e27_1
domain: light
What sun elevation value should I use here?
Likewise, I would like the lights to be turned off right before sunrise again.
alias: Turn off lights In the morning
description: ""
trigger:
- platform: numeric_state
entity_id: sun.sun
above: -1
condition: []
action:
- type: turn_off
device_id: 0aaaedc5
entity_id: light.ikea_e14_3
domain: light
I get really confused. How is above/below actually working? Positive and negative numbers?
In your second example you are missing the attribute. The state of sun.sun is not numeric… you need to specify that the trigger or condition should be listening to the elevation attribute.
Elevation at sunrise and sunset is 0, but you can use whatever value you want.
When you use above, the value of the state (or attribute in this case) changes must be greater than the specified value in order for the condition to pass.
No. Both positive and negative numbers can be used in both above and below. The value you use defines the threshold, while above and below define the direction of comparison. For example…
Still confufsed I’m afraid. Today, sunrise occured at 06:31
The turn on lights automation ran at 06:30 and the sun elevation condition was true. The condition checks if the sun is above -4.
The turn off lights automation ran at 06:22. I currently have it set to run at Above -2. Which is fine I guess, it did run before the sun rose
With this logic, I think there will be issues as long as the off job runs before the on job.
Maybe I should also add a condition to make sure these two only runs during like October-april or similar. During summer it is bright outside anyway so then it is not needed. Something like this condition:
So am I… you keep only providing snippets and making statements that are confusing, or of indiscernible purpose. For example, what is the purposes of the following?
To summarize the quote above,
You have stated that the solar elevation is 0 at 6:31.
The automation ran at 6:30 (when the solar elevation would be barely less than 0, but let’s call it -0.1).
The automation has a condition to run only when the solar elevation is above -4
Mathematically -0.1 is greater than -4, so the condition passes. That is the expected behavior.
If this is not what you wanted to happen, what behavior did you expect?