Last active
March 14, 2025 21:27
-
-
Save erkr/be04a09c4b826d1ff31d29c71152c322 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint for 'persistent' Sunset elevation triggered actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author Eric Kreuwels, Copyright 2022, publiced under the free MIT license conditions | |
blueprint: | |
name: Actions at Sunset elevation | |
description: Persistant elevation based actions around sunset. These actions can be any sequence including checking additional conditions if you like | |
domain: automation | |
input: | |
elevation_shift: | |
name: Elevation Shift | |
description: Using an elevation angle of the sun relative to the horizon; a positive angle is above the horizon. Angles between 0 and -3 degrees are in the twilight zone | |
default: 0.0 | |
selector: | |
number: | |
min: -6.0 | |
max: 6.0 | |
mode: slider | |
step: 0.5 | |
unit_of_measurement : degrees | |
trigger_at_startup: | |
name: Trigger at Home Assistant startup | |
description: Trigger the target state check and enforcement at Home Assistant. This check is only effective between Solar Noon and Solar Midnight. | |
default: true | |
selector: | |
boolean: {} | |
sunset_actions: | |
name: Sunset Actions | |
description: Action to run at the defined elevations around sunset | |
default: [] | |
selector: | |
action: {} | |
# Prevent the automation from running concurrently | |
mode: single | |
# Define the variables used in the action section | |
variables: | |
trigger_at_startup: !input 'trigger_at_startup' | |
elevation_shift: !input 'elevation_shift' | |
# Define the trigger for the automation | |
trigger: | |
- platform: numeric_state | |
entity_id: sun.sun | |
attribute: elevation | |
below: !input elevation_shift | |
- platform: homeassistant | |
event: start | |
condition: | |
# check if the sun is settling (between noon and midnight only) | |
- condition: state | |
entity_id: sun.sun | |
attribute: rising | |
state: false | |
# check if persistency state actions are needed | |
- condition: template | |
value_template: '{{ trigger.platform!="homeassistant" or (trigger_at_startup and state_attr("sun.sun", "elevation") <= elevation_shift and state_attr("sun.sun", "elevation") >= elevation_shift - 2) }}' | |
action: !input sunset_actions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment