Merge pull request #9423 from home-assistant/emontnemery-patch-1

Update documentation related to sun triggers and sun conditions.
This commit is contained in:
Klaas Schoute 2019-05-30 00:17:41 +02:00 committed by GitHub
commit 63135477d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 9 deletions

View File

@ -130,9 +130,17 @@ automation:
### {% linkable_title Sun trigger %}
Triggers when the sun is setting or rising. An optional time offset can be given to have it trigger a set time before or after the sun event (i.e. 45 minutes before sunset, when dusk is setting in).
#### {% linkable_title Sunset / Sunrise trigger %}
Sunrise as a trigger may need special attention as explained in time triggers below. This is due to the date changing at midnight and sunrise is at an earlier time on the following day.
Triggers when the sun is setting or rising, i.e. when the sun elevation reaches 0°.
An optional time offset can be given to have it trigger a set time before or after the sun event (e.g. 45 minutes before sunset).
<p class='note'>
Since the duration of twilight is different throughout the year, it is recommended to use [sun elevation triggers][sun_elevation_trigger] instead of `sunset` or `sunrise` with a time offset to trigger automations during dusk or dawn.
</p>
[sun_elevation_trigger]: /docs/automation/trigger/#sun-elevation-trigger
```yaml
automation:
@ -140,11 +148,13 @@ automation:
platform: sun
# Possible values: sunset, sunrise
event: sunset
# Optional time offset. This example is 45 minutes.
# Optional time offset. This example will trigger 45 minutes before sunrise.
offset: '-00:45:00'
```
Sometimes you may want more granular control over an automation based on the elevation of the sun. This can be used to layer automations to occur as the sun lowers on the horizon or even after it is below the horizon. This is also useful when the "sunset" event is not dark enough outside and you would like the automation to run later at a precise solar angle instead of the time offset such as turning on exterior lighting. For most things, a general number like -4 degrees is suitable and is used in this example:
#### {% linkable_title Sun elevation trigger %}
Sometimes you may want more granular control over an automation than simply sunset or sunrise and specify an exact elevation of the sun. This can be used to layer automations to occur as the sun lowers on the horizon or even after it is below the horizon. This is also useful when the "sunset" event is not dark enough outside and you would like the automation to run later at a precise solar angle instead of the time offset such as turning on exterior lighting. For most things intended to trigger during dusk or dawn, a number between 0° and -6° is suitable; -4° is used in this example:
{% raw %}
```yaml
@ -162,11 +172,15 @@ automation:
```
{% endraw %}
If you want to get more precise, start with the US Naval Observatory [tool](http://aa.usno.navy.mil/data/docs/AltAz.php) that will help you estimate what the solar angle will be at any specific time. Then from this, you can select from the defined twilight numbers. Although the actual amount of light depends on weather, topography and land cover, they are defined as:
If you want to get more precise, start with the US Naval Observatory [tool](http://aa.usno.navy.mil/data/docs/AltAz.php) which will help you estimate what the solar elevation will be at any specific time. Then from this, you can select from the defined twilight numbers.
- Civil twilight: Solar angle > -6°
- Nautical twilight: Solar angle > -12°
- Astronomical twilight: Solar angle > -18°
Although the actual amount of light depends on weather, topography and land cover, they are defined as:
- Civil twilight: 0° > Solar angle > -6°
This is what is meant by twilight for the average person: Under clear weather conditions, civil twilight approximates the limit at which solar illumination suffices for the human eye to clearly distinguish terrestrial objects. Enough illumination renders artificial sources unnecessary for most outdoor activities.
- Nautical twilight: 6° > Solar angle > -12°
- Astronomical twilight: 12° > Solar angle > -18°
A very thorough explanation of this is available in the Wikipedia article about the [Twilight](https://en.wikipedia.org/wiki/Twilight).

View File

@ -120,10 +120,59 @@ condition:
### {% linkable_title Sun condition %}
The sun condition can test if the sun has already set or risen when a trigger occurs. The `before` and `after` keys can only be set to `sunset` or `sunrise`. They have a corresponding optional offset value (`before_offset`, `after_offset`) that can be added, similar to the [sun trigger][sun_trigger].
#### {% linkable_title Sun state condition %}
The sun state can be used to test if the sun has set or risen.
```yaml
condition:
condition: state # 'day' condition: from sunrise until sunset
entity_id: sun.sun
state: 'above_horizon'
```
```yaml
condition:
condition: state # from sunset until sunrise
entity_id: sun.sun
state: 'below_horizon'
```
#### {% linkable_title Sun elevation condition %}
The sun elevation can be used to test if the sun has set or risen, it is dusk, it is night etc. when a trigger occurs.
For an in depth explanation of sun elevation see [sun elevation trigger][sun_elevation_trigger].
[sun_elevation_trigger]: /docs/automation/trigger/#sun-elevation-trigger
```yaml
condition:
condition: and # 'twilight' condition: dusk and dawn, in typical locations
conditions:
- condition: template
value_template: {% raw %}'{{ states.sun.sun.attributes.elevation < 0 }}'{% endraw %}
- condition: template
value_template: {% raw %}'{{ states.sun.sun.attributes.elevation > -6 }}'{% endraw %}
```
```yaml
condition:
condition: template # 'night' condition: from dusk to dawn, in typical locations
value_template: {% raw %}'{{ states.sun.sun.attributes.elevation < -6 }}'{% endraw %}
```
#### {% linkable_title Sunset/sunrise condition %}
The sun condition can also test if the sun has already set or risen when a trigger occurs. The `before` and `after` keys can only be set to `sunset` or `sunrise`. They have a corresponding optional offset value (`before_offset`, `after_offset`) that can be added, similar to the [sun trigger][sun_trigger].
[sun_trigger]: /docs/automation/trigger/#sun-trigger
<p class='note warning'>
The sunset/sunrise conditions do not work in locations inside the polar circles, and also not in locations with highly skewed local time zone.
It is advised to use conditions evaluating the solar elevation instead of the before/after sunset/sunrise conditions.
</p>
```yaml
condition:
condition: sun