Here a small package I wrote, I enjoy it a lot and want to share it with the community.
Install instructions:
- Put everything in a file called
\config\packages\christmas_mood.yaml
- Please adjust the lines marked with
please adjust this
to fit your setup. - Restart home assistant.
- Enable the two groups:
christmas_mood_trigger
andchristmas_mood_automations
- Disable all “switch.circadian_lighting_" and/or "switch.adaptive_lighting_” switches, for the first time using. No worries, they will be automatically enabled and disabled by the time triggers. Only for testing you need to disable them once manually.
- Enjoy
Features:
- Every time a color capable light is turned on is set to red or green
- If a motion is detected by a sensor of your choice an Alexa of your choice plays some Christmas radio song for 60 seconds
- Works flawlessly also if you have the plugin “Circadian lights” or “Adaptive Lighting” installed, by disabling those it in the chosen period.
- All automations are automatically turned on at 18 o’clock and deactivated at 22 o’clock every day
- After Christmas time just delete the package file
- Disable the automatic triggers and the whole package by enabling and disabling the two newly added
christmas_mood_trigger
andchristmas_mood_automations
group.
Please edit the file to adjust the activation time, the motion sensor and the Alexa device to your liking
Improvements are welcome!
# by KoffeinSchluck, No Copyright, CC0 1.0 Universell (CC0 1.0)
# Merry christmas !
#
# . . . + . . .
# . . . # . .
# . . ### . . .
# . . "#:. .:##"##:. .:#" . .
# . . "####"O##"####" .
# . "#:. .:#"###"#:. O .:#" . . .
# . "####O####"###O#####" . .
# . "#:. "####"###"####" .:#" . .
# . . "#####O#""##"##""###O####" .
# O ."##"###O#"#####"##" O . .
# . "#:. ... .:##"###"###"##:. ... .:#" .
# . "###O###"##"#O###"#O"###O###" O . .
# . . "#####""#######""#####" . .
# . O " 000 " . .
# . . . 000 . . .
#.. .. ..................O000O........................ ...... ...
################################################################
## Packages / Christmas mood
################################################################
################################################
## Customize
################################################
homeassistant:
customize:
################################################
## Node Anchors
################################################
package.node_anchors:
customize: &customize
package: 'christmas_mood'
expose: &expose
<<: *customize
haaska_hidden: false
homebridge_hidden: false
################################################
## Group
################################################
group.christmas_mood_trigger:
<<: *customize
friendly_name: "Christmas mood automatic on/off"
icon: mdi:pine-tree
group.christmas_mood_automations:
<<: *customize
friendly_name: "Christmas mood"
icon: mdi:pine-tree
################################################
## Group
################################################
group:
christmas_mood_trigger:
entities:
- automation.christmas_mood_off
- automation.christmas_mood_on
christmas_mood_automations:
entities:
- automation.christmas_mood_motion_christmas_songs
- automation.christmas_mood_light_trigger
################################################
## Scripts
################################################
script:
christmas_mood_adaptive_off:
description: 'Disable all adaptive lightning automations'
variables:
adaptive_switches: >-
{%- set ns = namespace(switch_adaptive_lighting=[]) -%}
{%- for s in states.switch if ('switch.circadian_lighting_' in s.entity_id or 'switch.adaptive_lighting_' in s.entity_id) -%}
{%- set ns.switch_adaptive_lighting = ns.switch_adaptive_lighting + [ s ] -%}
{%- endfor -%}
{{ ns.switch_adaptive_lighting | map(attribute='entity_id') | list() }}
sequence:
- service: switch.turn_off
data_template:
entity_id: "{{ adaptive_switches }}"
christmas_mood_adaptive_on:
description: 'Disable all adaptive lightning automations'
variables:
adaptive_switches: >-
{%- set ns = namespace(switch_adaptive_lighting=[]) -%}
{%- for s in states.switch if ('switch.circadian_lighting_' in s.entity_id or 'switch.adaptive_lighting_' in s.entity_id) -%}
{%- set ns.switch_adaptive_lighting = ns.switch_adaptive_lighting + [ s ] -%}
{%- endfor -%}
{{ ns.switch_adaptive_lighting | map(attribute='entity_id') | list() }}
sequence:
- service: switch.turn_on
data_template:
entity_id: "{{ adaptive_switches }}"
christmas_mood_light_red_green:
description: 'Turn light red or green'
mode: parallel
fields:
entity_id:
description: 'Entity or group of lights'
example: 'group.bath_lights'
sequence:
- service: light.turn_on
data_template:
entity_id: "{{ entity_id }}"
brightness_pct: 100
rgb_color: >
{% set color=range(2)|random %}
{%- if color == 1 -%}
[255, 0, 0] # red
{%- else -%}
[0, 255, 0] # green
{%- endif %}
################################################
## Automation
################################################
automation:
- alias: christmas_mood_off
trigger:
- platform: time
at: '18:00:00' # please adjust this
action:
- service: script.christmas_mood_adaptive_off
- service: homeassistant.turn_on
data:
entity_id: group.christmas_mood_automations
- alias: christmas_mood_on
trigger:
- platform: time
at: '22:00:00' # please adjust this
action:
- service: script.christmas_mood_adaptive_on
- service: homeassistant.turn_off
data:
entity_id: group.christmas_mood_automations
- alias: christmas_mood_light_trigger
mode: parallel
initial_state: false
trigger:
- platform: event
event_type: state_changed
condition:
condition: and
conditions:
- condition: template
value_template: '{{ trigger.event.data is not none }}'
- condition: template
value_template: '{{ trigger.event.data.entity_id is not none }}'
- condition: template
value_template: '{{ trigger.event.data.entity_id.split(".")[0] == "light" }}'
- condition: template
value_template: '{{ trigger.event.data.old_state.attributes["is_hue_group"] != true }}'
- condition: template
value_template: '{{ trigger.event.data.old_state.attributes["is_deconz_group"] != true }}'
- condition: template
value_template: '{{ trigger.event.data.old_state.state == "off" }}'
- condition: template
value_template: '{{ trigger.event.data.new_state.state == "on" }}'
action:
- service: script.christmas_mood_light_red_green
data_template:
entity_id: '{{ trigger.event.data.entity_id }}'
- alias: christmas_mood_motion_christmas_songs
mode: single
initial_state: false
trigger:
- to: 'on'
entity_id: binary_sensor.flur_1 # please adjust this
platform: state
condition: # don't change music, if it is already playing
condition: not
conditions:
- condition: state
entity_id: media_player.alexa_kuche # please adjust this
state: 'playing'
action:
- service: media_player.play_media
data:
entity_id: media_player.alexa_kuche # please adjust this
media_content_id: "christmas radio"
media_content_type: "AMAZON_MUSIC"
extra: {"timer": 60} # stop after 60 seconds