I have some IR LEDs that i just cloned the remote of using an ESPHome device, and now i'm stuck with 22 buttons.
I'm currently in the process of making a template light with the following logic:
When a certain color is requested, press the button corresponding to the nearest one on the spectrum
I got it to stop spitting out errors every time I try to change a color, but now it simply doesn't press any button besides the on/off ones
#Approximate RGB value in a template
1 messages · Page 1 of 1 (latest)
Here is the template: ```yaml
light:
- platform: template
lights:
ir_led_strip:
friendly_name: "IR LED Strip"
turn_on:
service: button.press
target:
entity_id: button.remote_test_b2
turn_off:
service: button.press
target:
entity_id: button.remote_test_b1
set_color:
service: button.press
target:
entity_id: >
{% set requested_color = state_attr('light.ir_led_strip', 'rgb_color') %}
{% if requested_color is none %}
button.remote_test_b6
{% else %}
{% set color_buttons = {
(255, 0, 0): 'button.remote_test_b3',
(0, 255, 0): 'button.remote_test_b4',
(0, 0, 255): 'button.remote_test_b5',
(255, 255, 255): 'button.remote_test_b6'
} %}
{% set nearest_color = None %}
{% set min_distance = None %}
{% for rgb_tuple, button_id in color_buttons.items() %}
{% set distance = (requested_color[0] - rgb_tuple[0]) ** 2 + (requested_color[1] - rgb_tuple[1]) ** 2 + (requested_color[2] - rgb_tuple[2]) ** 2 %}
{% if min_distance is none or distance < min_distance %}
{% set min_distance = distance %}
{% set nearest_color = button_id %}
{% endif %}
{% endfor %}
{{ nearest_color }}
{% endif %}