Skip to content

Instantly share code, notes, and snippets.

@erkr
Created May 12, 2022 10:40
Show Gist options
  • Save erkr/7abf78d6ce9a1edc904124b1e1ee512c to your computer and use it in GitHub Desktop.
Save erkr/7abf78d6ce9a1edc904124b1e1ee512c to your computer and use it in GitHub Desktop.
Home Assistant Blueprint for 'persistent' Sunrise with a time offset triggered actions
# Author Eric Kreuwels, Copyright 2022, publiced under the free MIT license conditions
blueprint:
name: Actions at Sunrise Offset
description: Persistant offset based actions around sunrise. 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 Midnight and Solar Noon.
default: true
selector:
boolean: {}
sunrise_actions:
name: Sunrise Actions
description: Action to run at the defined elevations around sunrise
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: sunrise
offset: !input time_shift
- platform: homeassistant
event: start
condition:
# check if the sun is rising (between midnight and noon only)
- condition: state
entity_id: sun.sun
attribute: rising
state: true
# check is it is after the defined offset
- condition: sun
after: sunrise
after_offset: !input time_shift
# check if persistency state actions are needed
- condition: template
value_template: '{{ trigger.platform!="homeassistant" or trigger_at_startup }}'
# now() >= as_datetime(state_attr("sun.sun", "next_rising")) + timedelta( hours = day_shift, minutes = time_shift) }}'
# now() > today_at("10:15")
action: !input sunrise_actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment