Doh! I should’ve thought of that. Apologies, thank you.
For the fools like me who come here later, it was this that did it:
alias: Xmas Outside Christmas Lights Off randomized
trigger:
- platform: sun
event: sunset
offset: -00:30:00
- platform: time
at: sensor.xmas_front_door
action:
- service: switch.turn_{{ 'on' if trigger.platform == 'sun' else 'off' }}
target:
entity_id: switch.outdoorplug
I’m not sure how best to merge these tasks except to add the same condition so it runs the same -or- dropping the variable to just be _off at the trigger time of the time-based sensor I have in configuration.yml.
template:
- trigger:
- platform: time
at: '00:00:00'
- platform: homeassistant
event: start
- platform: event
event_type: event_template_reloaded
sensor:
- name: livingroom_tree_off
unique_id: livingroom_tree_off
state: "{{ (today_at('22:10') + timedelta(minutes = range(2,36) | random)).isoformat() }}"
device_class: timestamp
- name: familyroom_tree_off
unique_id: familyroom_tree_off
state: "{{ (today_at('21:00') + timedelta(minutes = range(2,36) | random)).isoformat() }}"
device_class: timestamp
- name: xmas_front_door
unique_id: xmas_front_door
state: "{{ (today_at('22:20') + timedelta(minutes = range(2,36) | random)).isoformat() }}"
device_class: timestamp
- name: upstairs_wrap_lights
unique_id: upstairs_wrap_lights
state: "{{ (today_at('20:00') + timedelta(minutes = range(2,36) | random)).isoformat() }}"
device_class: timestamp
I think I’ll just do this and hope for the best:
- id: '5000000100011'
alias: Xmas Outside Christmas Lights On and then Off randomized
trigger:
- platform: sun
event: sunset
offset: -00:12:00
- platform: time
at: sensor.xmas_front_door
condition:
- condition: template # Only between Nov 26 and January 5.
value_template: >
{% set n = (now().month, now().day) %}
{{ n >= (11, 26) or n <= (1, 5) }}
action:
- service: switch.turn_{{ 'on' if trigger.platform == 'sun' else 'off' }}
target:
entity_id: switch.outdoorplug
Have a great weekend!