Move sunrise/sunset status to a macro #196
This commit is contained in:
@ -168,4 +168,36 @@ It is {{ now().strftime("%I:%M %p") }}.
|
||||
"Collin, your bedroom lights are now on."
|
||||
] | random }} Goodnight!
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro sun_status() %}
|
||||
{% if is_state('sun.sun','below_horizon') %}
|
||||
You have
|
||||
{% set seconds = as_timestamp(states.sun.sun.attributes.next_rising)-now().timestamp() %}
|
||||
{% set hours = seconds / 60 %}
|
||||
{% if seconds / ( 60 * 60 ) > 1 %}
|
||||
{{ (seconds // ( 60 * 60 )) | int }} hours
|
||||
{% else %}
|
||||
{{ (seconds // 60) | int }} minutes
|
||||
{% endif %}
|
||||
{{ [
|
||||
'until the sun rises.',
|
||||
'until the sun is up',
|
||||
'before the sun officially rises.'
|
||||
] | random }}
|
||||
{% else %}
|
||||
You have
|
||||
{% set seconds = as_timestamp(states.sun.sun.attributes.next_setting)-now().timestamp() %}
|
||||
{% set hours = seconds / 60 %}
|
||||
{% if seconds / ( 60 * 60 ) > 1 %}
|
||||
{{ (seconds // ( 60 * 60 )) | int }} hours
|
||||
{% else %}
|
||||
{{ (seconds // 60) | int }} minutes
|
||||
{% endif %}
|
||||
{{ [
|
||||
'until the sun sets for the day.',
|
||||
'until the sun slips below the horizon.',
|
||||
'before the sun officially sets. '
|
||||
]|random }}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
Reference in New Issue
Block a user