Controlling a light based on the status of another "light"

I have a wifi based dimmer switch that works with Tuya. It’s a rotary switch… like, a wheel to adjust the intensity, and a button for on/off.

It is recognised as a light in HA.

I want to control another wifi light (for now, later I will want to control a full group of lights) using said dimmer.

How should I tackle this? I’m a complete newbie in “complex” programming… :frowning:

If you simply want to synchronize their states (when you turn on/off one light, the other is also turned on/off) there are at least three Blueprints available that can do that:

However, if you want to also synchronize their brightness, that’s more challenging (and, to my knowledge, there’s no Blueprint for it).

The alternative is to create a Light Group. It will be a new light entity that controls the state and brightness (and color) of one or more other lights.

1 Like

Nice, I’ll take a look, but you did point something out… I need to control the brightness too… :slightly_frowning_face:

Edit: found a solution that works for me:

1 Like

The light group feature in the latest versions of HA works perfectly! (at least in brightness/on-off, can’t say if colour will work)

The link I gave works for rgb color and and effects (for light strips for instance), too. I think it’s more robust than light group feature (which didn’t work for me). Glad you found a solution that works for you!

I have used ChatGPT’s help to create a solution that lets you map a wider color temperature range (2000 K–6535 K) on your LED strip even though your Hue lamp only supports 2202 K–6535 K. Essentially, when the Hue lamp hits its lower limit of 2202 K, the LED strip will go down to 2000 K, and everything between those values is linearly scaled. Below is the YAML for a Master-Slave automation that you can paste directly into the UI Automation Editor in Home Assistant (no leading dash before alias:!).

yaml

Code kopieren

alias: "LED-Strip follows Master Lamp (Extended Color Temperature Range)"
description: "Linearly map Hue lamp's 2202–6535 K to LED strip's 2000–6535 K."
trigger:
  - platform: state
    entity_id: light.hue_ambiance_spot_1_2
    for:
      seconds: 2   # Wait until the lamp is stable for 2 seconds
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.hue_ambiance_spot_1_2
            state: "on"
        sequence:
          - service: light.turn_on
            data:
              entity_id: light.schreibtisch_led_stripe
              brightness: >
                {{ state_attr('light.hue_ambiance_spot_1_2', 'brightness') | default(255) }}
              color_temp_kelvin: >
                {% set hue_val = state_attr('light.hue_ambiance_spot_1_2', 'color_temp_kelvin') | int(default=3164) %}
                {% set hue_min = 2202 %}
                {% set hue_max = 6535 %}
                {% set led_min = 2000 %}
                {% set led_max = 6535 %}

                {# Clamp if the Hue lamp goes out of its own range #}
                {% if hue_val < hue_min %}
                  {% set hue_val = hue_min %}
                {% elif hue_val > hue_max %}
                  {% set hue_val = hue_max %}
                {% endif %}

                {# Linear mapping:  
                   LED_val = led_min + ( (hue_val - hue_min) / (hue_max - hue_min) ) * (led_max - led_min) #}
                {% set ratio = (hue_val - hue_min) / (hue_max - hue_min) %}
                {% set led_val = led_min + ratio * (led_max - led_min) %}
                {{ led_val | int }}

      - conditions:
          - condition: state
            entity_id: light.hue_ambiance_spot_1_2
            state: "off"
        sequence:
          - service: light.turn_off
            entity_id: light.schreibtisch_led_stripe
mode: single

How It Works

  • Trigger: The automation fires when the Hue lamp (light.hue_ambiance_spot_1_2) changes state and remains stable for 2 seconds.
  • Linear Mapping: We take the lamp’s color_temp_kelvin attribute and map it from 2202 K–6535 K to 2000 K–6535 K for the LED strip. At 2202 K on the Hue lamp, the LED strip will show 2000 K. Higher values are scaled proportionally.
  • Clamping: If the Hue lamp somehow reports a value below 2202 or above 6535, we clamp it to its minimum or maximum before mapping.
  • Brightness: The brightness is passed through directly. You can remove or adjust that line if you only want to control color temperature.

This way, you fully utilize your LED strip’s lower color temperature without losing synchronization with the Hue lamp’s state. If you change the Hue lamp’s color temperature, the LED strip will smoothly follow, using the lamp’s upper limit (6535 K) but extending the lower limit down to 2000 K.