#Automation Blueprint, how do I filter lights based on color_mode?

1 messages · Page 1 of 1 (latest)

haughty folio
#

So what I'm trying to do is create a blueprint which will run logic only on lights which aren't in xy mode, so off/on CCW lights only. I've tried expanding the !input input_lights variable but it'd just give me an empty example.

I could do if/else for entity, device, area, group and try to get it that way but that's way too cumbersome and I'm 99% there's a better way to do it but I couldn't find it.

I want to just retrieve a list of entity_ids for lights for any type of selection. That's it basically.

Is there any way which is known to do this without a ton of jinja code?

stoic cipher
#

You need Jinja, but not a ton

#
variables: 
  input_lights: !input input_lights
  no_xy_mode: >
    {{
      input_lights
        | reject('is_state_attr', 'color_mode', 'xy')
        | list
    }}
haughty folio
#

Sadly, that doesn't work

blueprint:
  name: Lux Level RGBCCCW Lights
  domain: automation
  homeassistant:
    min_version: 2025.9.4
  description: Turn on or off lights dependent on the current Lux and if the lights are CCCW mode
  input:
    lux_sensor:
      name: Light sensor
      selector:
        entity:
          filter:
            - domain: sensor
              device_class: illuminance
    input_lights:
      name: Lights
      selector:
        target:
          entity:
            - domain: light
    lux_low:
      name: Low Lux Threshold
      description: Below this value, the lights will turn on
      default: 150
      selector:
        number:
          min: 0
          max: 1000
          unit_of_measurement: lx
          mode: box
    lux_high:
      name: High Lux Threshold
      description: Above this value, the lights will turn off
      default: 800
      selector:
        number:
          min: 0
          max: 2000
          unit_of_measurement: lx
          mode: box

triggers:
  - trigger: numeric_state
    entity_id: !input lux_sensor
    below: !input lux_low

  - trigger: numeric_state
    entity_id: !input lux_sensor
    above: !input lux_high

actions:
  - variables:
      input_lights: !input input_lights
      no_xy_mode: >
        {{
          input_lights
            | reject('is_state_attr', 'color_mode', 'xy')
            | list
        }}
  - action: system_log.write
    data:
      level: error
      message: "The input lights are: {{ no_xy_mode }}"

Gave me:

The input lights are: ['entity_id']
#

Hm maybe due to selector, I'll try targets, idk

#

idk if I changed anything, used the light selector from the tutorial:

blueprint:
  name: Lux Level RGBCCCW Lights
  domain: automation
  homeassistant:
    min_version: 2025.9.4
  description: Turn on or off lights dependent on the current Lux and if the lights are CCCW mode
  input:
    lux_sensor:
      name: Light sensor
      selector:
        entity:
          filter:
            - domain: sensor
              device_class: illuminance
    input_lights:
      name: Lights
      selector:
        target:
          entity:
            - domain: light
    lux_low:
      name: Low Lux Threshold
      description: Below this value, the lights will turn on
      default: 150
      selector:
        number:
          min: 0
          max: 1000
          unit_of_measurement: lx
          mode: box
    lux_high:
      name: High Lux Threshold
      description: Above this value, the lights will turn off
      default: 800
      selector:
        number:
          min: 0
          max: 2000
          unit_of_measurement: lx
          mode: box

triggers:
  - trigger: numeric_state
    entity_id: !input lux_sensor
    below: !input lux_low

  - trigger: numeric_state
    entity_id: !input lux_sensor
    above: !input lux_high

actions:
  - variables:
      input_lights: !input input_lights
      no_xy_mode: >
        {{
          input_lights
            | reject('is_state_attr', 'color_mode', 'xy')
            | list
        }}
  - action: system_log.write
    data:
      level: error
      message: "The input lights are: {{ no_xy_mode }}"

Same issue, only shows the top-level keywords: ['entity_id', 'area_id']

stoic cipher
#

That's because you are using a target selector

#

Use an entity selector instead

#

Unless you want to also be able to select areas and devices

haughty folio
#

Ye, I want to select areas mostly

stoic cipher
#

But then you do need to use a ton of Jinja

haughty folio
#

Ah that's what I hoped I don't need to do 😢

stoic cipher
#

Because you need to account for all possible inputs, and select the light entities from there

haughty folio
#

hoped there was one catch-em-all that can traverse the selections and just plop out light entities or at least their id's

stoic cipher
#

I know there was a thread about getting the entities out of a target selector a while ago

haughty folio
#

Okay that's great!

      target_entities: >
        {% set data = namespace(expanded_targets=[]) %}
        {% macro dummy(someValue, returns) %}
        {%   do returns(someValue) %}
        {% endmacro %}
        {# Declare our helper macros as functions, so they can return values #}
        {% set dummy = dummy | as_function %}

        {% set funcs = {"device_id": device_entities, "area_id": area_entities, "label_id": label_entities} %}

        {% for key, value in light_target.items() %}
          {% set entities = funcs.get(key, dummy) %}
          {% set items = [value] if value is not list else value %}
          {% set data.expanded_targets = data.expanded_targets + entities(value) | select("match", "light") | list %}
        {% endfor %}
        {{ data.expanded_targets | unique | list }}

Am able to get the light entities, now just have to filter them out

stoic cipher
#

So that will be the lights. You can then use the template I provided above to reject the ones on color_mode xy