[Package] Christmas mood lights and motion activated music

Tags: #<Tag:0x00007f32653e7d78> #<Tag:0x00007f32653e7c10> #<Tag:0x00007f32653e7ad0> #<Tag:0x00007f32653e7a08>

Here a small package I wrote, I enjoy it a lot and want to share it with the community.

Install instructions:

  1. Put everything in a file called \config\packages\christmas_mood.yaml
  2. Please adjust the lines marked with please adjust this to fit your setup.
  3. Restart home assistant.
  4. Enable the two groups: christmas_mood_trigger and christmas_mood_automations
  5. 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.
  6. Enjoy :christmas_tree::santa:

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 :slight_smile:
  • Disable the automatic triggers and the whole package by enabling and disabling the two newly added christmas_mood_trigger and christmas_mood_automations group.

Please edit the file to adjust the activation time, the motion sensor and the Alexa device to your liking :slight_smile:

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
1 Like

Could you update it to work with adaptive lighting as well?

Which adaptive lighting do you use? I use circadian lightning and adapted this to work with it.

This thing:

I will have a look into it and will come back to you :slight_smile:

Here’s some example entities:

thanks, looks easy :smiley: Looks just like my beloved circadian lighting, wait a second :wink:

You have categorized your topic as “Blueprint Exchange”. That appears to be a mistake because you have contributed a package containing no blueprints. A blueprint is a new Home Assistant feature that will become available in the next release.

2 Likes

Ups, sorry. I will move it :slight_smile:
UPDATE: Moved it now, is it correct?

Done. should be working for you now. Beware, for first time testing purposes, you have to disable those switches manually. Normally, those switches will be enabled and disabled automatically at 18 and 22 o’clock :wink:

You could make it into a blueprint instead of moving it you know… :slight_smile:

1 Like

I will have to look into blueprints :smiley:if people like it, I will do so :slight_smile:

What would the installation process look like if the automation portion of this package is converted to a blueprint?

Just a guess but it seems to me that using this topic’s URL, to import the blueprint, won’t install the balance of what’s in the package (or will it?).

Yeah, blueprints are for automations only. You’d have to simplify it into one blueprint or install everything else manually.

I think it would look pretty easy since everything indicated with # please adjust this is in the automation portion of the package. Basically it would be

  1. add package file (no need for user to edit)
  2. add blueprint file (again no need for user to edit)
  3. configure automations using blueprint (would replace user needing to edit # please adjust this)
1 Like

I think you made my point. The installation process remains a multi-step procedure when the blueprint automation is contained within a package.

Blueprints look promising, I like the user-customizable part. Unfortunately, the documentation seems down? I will have a look into it once it will become available. Automations are very powerful, why they haven’t been included into blueprints? Was it a technical decision?

The official docs page will go live with the next release.

You can see now by looking here

Yep, I agree. I do not think using a blueprint in a multi-step setup is the beginner friendly approach most people seem to feel these provide. But I think it’s cool to do all the heavy lifting in the blueprint an be able to quickly add automations after the fact.

If we could actually put the blueprint in the package file itself, or allow packages to be defined in the blueprint, I think this (blueprint) would be more useful. (EDIT to add, but that a topic of blueprints, I don’t want to steal the focus from this great package)

1 Like

The ability to easily import a package, with the same ease as importing a blueprint automation, would greatly simplify the installation process. It would be a boon for the same audience targeted by blueprint automations (unfamiliar/uncomfortable with copy/pasting/editing YAML).

To be clear, there’s no drawback to having a package containing a blueprint automation. However, the blueprint’s convenience is diluted by the task of installing the rest of the package.

2 Likes

Did you mean to say packages? Blueprints are (currently) designed for automations.

Refer to the link in troy’s post (above).