Skip to content

Instantly share code, notes, and snippets.

@hugalafutro
Created February 6, 2022 11:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save hugalafutro/07a15a55d1e8394744e423a9ce7c8223 to your computer and use it in GitHub Desktop.
Save hugalafutro/07a15a55d1e8394744e423a9ce7c8223 to your computer and use it in GitHub Desktop.
Color Loop
blueprint:
name: Color Loop
description: ''
domain: automation
input:
cl_light:
name: Color Loop Light
description: 'Choose Light entity to Color Loop'
selector:
target:
entity:
domain: light
variables:
colors: |-
{{ [[0.217,0.077], [0.157,0.05], [0.136,0.04], [0.137,0.065],
[0.141,0.137], [0.146,0.238], [0.151,0.343], [0.157,0.457],
[0.164,0.591], [0.17,0.703], [0.172,0.747], [0.199,0.724],
[0.269,0.665], [0.36,0.588], [0.444,0.517], [0.527,0.447],
[0.612,0.374], [0.677,0.319], [0.701,0.299], [0.667,0.284],
[0.581,0.245], [0.477,0.196], [0.385,0.155], [0.301,0.116],
[0.217,0.077]] }}
trigger:
- platform: time_pattern
hours: '*'
minutes: '*'
seconds: '/1'
action:
- service: light.turn_on
data_template:
xy_color: '{{ colors[(now().second/2.5)|round(0)] }}'
transition: 1
target: !input cl_light
mode: single
@tcaddy
Copy link

tcaddy commented Mar 15, 2022

This is cool, I really enjoy the effect. Thank you for sharing this.

However, I found that the only way to turn it off is to disable the automation using the blueprint. Am I using this wrong?

When I turned off the bulbs, they turned back on again 1 second later and continued the color loop.

@hugalafutro
Copy link
Author

hugalafutro commented Mar 15, 2022

To give credit where credit is due, I "stole" this from https://gist.github.com/dglaude/619a9e415e1e34019a6b1f5f274e0d14?permalink_comment_id=3668660#gistcomment-3668660 and made it into a blueprint @ https://community.home-assistant.io/t/color-loop-effect-for-any-light-with-color-wheel-selector/389343.

To answer your question, your assumption is correct, I use following convoluted method to control both at once (I think triggering automation is enough, the template and script are to make the button on HA dashboard follow the color of the light as if it was pointing to an actual light).

automation lightstrip_helper

alias: lightstrip_helper
description: ''
trigger: []
condition: []
action:
  - choose:
      - conditions:
          - condition: device
            type: is_on
            device_id: 543788980a094a5589663dfcdf662251
            entity_id: light.lightstrip
            domain: light
        sequence:
          - service: automation.turn_off
            data:
              stop_actions: true
            target:
              entity_id: automation.colorloop_lightstrip
          - type: turn_off
            device_id: 543788980a094a5589663dfcdf662251
            entity_id: light.lightstrip
            domain: light
      - conditions:
          - condition: device
            type: is_off
            device_id: 543788980a094a5589663dfcdf662251
            entity_id: light.lightstrip
            domain: light
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.lightstrip
            data:
              brightness_pct: 100
          - service: automation.turn_on
            target:
              entity_id: automation.colorloop_lightstrip
            data: {}
    default: []
mode: single

script lightstrip_Switch_helper:

alias: lightstrip_Switch_helper
sequence:
  - service: automation.trigger
    target:
      entity_id: automation.lightstrip_helper
    data:
      skip_condition: true
mode: single
icon: mdi:led-strip

template switch defined in switch.yaml (assuming split ha config)

  - platform: template
    switches:
      lightstrip_colorloop:
        value_template: "{{ is_state('light.lightstrip', 'on') }}"
        turn_on:
          service: script.lightstrip_switch_helper
        turn_off:
          service: script.lightstrip_switch_helper

I think the script could be omitted, but iirc I couldn't find out the syntax to trigger the automation directly form the template switch and since it's been working reliably I promptly forgot about it.

edit: The way it works iirc is the template switch automatically calls the script whenever the actual light switch turns off or on, I don't remember why I didn't just do it with another automation with the light state as trigger, iirc had to do something with the button icon reflecting the color light.

@tcaddy
Copy link

tcaddy commented Mar 15, 2022

Thanks for the info, I'll see if I can get my HA setup working a little better.

@tcaddy
Copy link

tcaddy commented Mar 17, 2022

I was able to get a toggle button on my dashboard to turn this off and on. Thanks for sharing your code. automation.turn_on and automation.turn_off are the key to controlling this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment