Skip to content

Instantly share code, notes, and snippets.

@jnsw
Created December 14, 2025 19:40
Show Gist options
  • Select an option

  • Save jnsw/f62a0e89b11a7c6e436063ccf1a5139a to your computer and use it in GitHub Desktop.

Select an option

Save jnsw/f62a0e89b11a7c6e436063ccf1a5139a to your computer and use it in GitHub Desktop.
A minimal Home Assistant blueprint that runs user-defined ON and OFF actions based on either a sun event or a fixed time. The logic is selectable: sun → ON & time → OFF or time → ON & sun → OFF. Works with any entity or service via generic actions.
blueprint:
name: Sun ↔ Time Actions (Generic)
description: Run any action based on a sun event and a fixed time. Choose which one turns ON and which turns OFF.
domain: automation
input:
mode_selector:
name: Logic Mode
description: Choose which trigger runs ON and which runs OFF
default: sun_on
selector:
select:
options:
- label: "Sun → ON, Time → OFF"
value: sun_on
- label: "Time → ON, Sun → OFF"
value: time_on
sun_event:
name: Sun Event
default: sunset
selector:
select:
options:
- sunrise
- sunset
sun_offset:
name: Sun Offset
default: "00:00:00"
selector:
time: {}
fixed_time:
name: Fixed Time
default: "01:00:00"
selector:
time: {}
on_action:
name: ON Action
selector:
action: {}
off_action:
name: OFF Action
selector:
action: {}
mode: single
trigger:
- id: sun
platform: sun
event: !input sun_event
offset: !input sun_offset
- id: time
platform: time
at: !input fixed_time
action:
- choose:
# Sun → ON | Time → OFF
- conditions:
- condition: trigger
id: sun
- condition: template
value_template: "{{ iif(input.mode_selector == 'sun_on', true, false) }}"
sequence: !input on_action
- conditions:
- condition: trigger
id: time
- condition: template
value_template: "{{ iif(input.mode_selector == 'sun_on', true, false) }}"
sequence: !input off_action
# Time → ON | Sun → OFF
- conditions:
- condition: trigger
id: time
- condition: template
value_template: "{{ iif(input.mode_selector == 'time_on', true, false) }}"
sequence: !input on_action
- conditions:
- condition: trigger
id: sun
- condition: template
value_template: "{{ iif(input.mode_selector == 'time_on', true, false) }}"
sequence: !input off_action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment