Created
May 12, 2022 10:40
-
-
Save erkr/c0e3a3ab4aaccfbe183ae40e0b12456f to your computer and use it in GitHub Desktop.
Home Assistant Blueprint for 'persistent' Sunset with a time offset 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 Offset | |
description: Persistant offset based actions around sunset. These actions can be any sequence including checking additional conditions if you like | |
domain: automation | |
input: | |
time_shift: | |
name: Time Shift | |
description: Using time shift around Sunrise. A negative value is earlier, a positive value is later. | |
default: "-00:01:00" | |
selector: | |
text: {} | |
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' | |
# Define the trigger for the automation | |
trigger: | |
- platform: sun | |
event: sunset | |
offset: !input time_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 is it is after the defined offset | |
- condition: sun | |
after: sunset | |
after_offset: !input time_shift | |
# check if persistency state actions are needed | |
- condition: template | |
value_template: '{{ trigger.platform!="homeassistant" or trigger_at_startup }}' | |
# now() > today_at("10:15") | |
# today_at("20:33") >= as_datetime(state_attr("sun.sun", "next_setting")) + timedelta( hours = -24, minutes = 10) | |
action: !input sunset_actions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment