Problem creating a blueprint to control aquarium lights

I have a 4 channels led aquarium light that is controlled by an IR control. With the remote I can control the intensity of every channel, because every channel have one color, to simulate sunlight at dawn, noon, evening, etc…what I want to do is use a broadlink rm3 IR remote that I integrated with HA and use to power on and off other devices, to control this light. I learned the light remote control , tried, and all works fine.

So, what I really need is write a blueprint to automate the intensity of every channel at different day hours. With my little acknowledgment writing blueprints and the gemini help,. I wrote it, but have two problems… I can choose the broadlink rm3 as IR emitter, but can’t choose the device that is controlled. I am loosing something in the code for this. And in the automation, after load the bIueprint, I can add the time to trigger the remote.send_command action, but I have no idea how to add the % of power for every channel in the list created… Maybe I am focusing the automation in a wrong way, and there is better options than a blueprint. I know I can do it with several automations, creating one for every light and for every channel intensity change, but this will be a lot of automations to create and would consume a lot of resources. I even thought to do it with an esp32 with IR led with esphome, but I have the broadlink that already control IR devices… this is the code

blueprint:
  name: Control de luces de acuario marino
  description: Controla las luces de un acuario marino según un horario y porcentajes de intensidad.
  domain: automation
  input:
    dispositivo_ir:
      name: Dispositivo
      description: Selecciona el dispositivo que controlarás.
      selector:
        device:
    horarios:
      name: Horarios
      description: Lista de horarios y porcentajes de intensidad.
      selector:
        object:
mode: single
trigger:
  - platform: time
    at: "{{ repeat.item.horario }}"
action:
  - variables:
      estados_deseados: "{{ repeat.item.estados }}"
      estados_actuales: "{{ states('sensor.estados_actuales_luces') | from_json | default({}) }}"
      porcentajes: [0, 2, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
  - repeat:
      for_each: "{{ horarios }}"
      sequence:
        - repeat:
            until:
              - condition: template
                value_template: "{{ estados_actuales == estados_deseados }}"
            sequence:
              - choose:
                  - conditions: "{{ estados_actuales.canal1 < estados_deseados.canal1 }}"
                    sequence:
                      - service: remote.send_command
                        target:
                          device_id: "{{ dispositivo_ir }}"
                        data:
                          command: Canal1+
                          device: rm3
                  - conditions: "{{ estados_actuales.canal1 > estados_deseados.canal1 }}"
                    sequence:
                      - service: remote.send_command
                        target:
                          device_id: "{{ dispositivo_ir }}"
                        data:
                          command: Canal1-
                          device: rm3
                  - conditions: "{{ estados_actuales.canal2 < estados_deseados.canal2 }}"
                    sequence:
                      - service: remote.send_command
                        target:
                          device_id: "{{ dispositivo_ir }}"
                        data:
                          command: Canal2+
                          device: rm3
                  - conditions: "{{ estados_actuales.canal2 > estados_deseados.canal2 }}"
                    sequence:
                      - service: remote.send_command
                        target:
                          device_id: "{{ dispositivo_ir }}"
                        data:
                          command: Canal2-
                          device: rm3
                  - conditions: "{{ estados_actuales.canal3 < estados_deseados.canal3 }}"
                    sequence:
                      - service: remote.send_command
                        target:
                          device_id: "{{ dispositivo_ir }}"
                        data:
                          command: Canal3+
                          device: rm3
                  - conditions: "{{ estados_actuales.canal3 > estados_deseados.canal3 }}"
                    sequence:
                      - service: remote.send_command
                        target:
                          device_id: "{{ dispositivo_ir }}"
                        data:
                          command: Canal3-
                          device: rm3
                  - conditions: "{{ estados_actuales.canal4 < estados_deseados.canal4 }}"
                    sequence:
                      - service: remote.send_command
                        target:
                          device_id: "{{ dispositivo_ir }}"
                        data:
                          command: Canal4+
                          device: rm3
                  - conditions: "{{ estados_actuales.canal4 > estados_deseados.canal4 }}"
                    sequence:
                      - service: remote.send_command
                        target:
                          device_id: "{{ dispositivo_ir }}"
                        data:
                          command: Canal4-
                          device: rm3
              - variables:
                  nuevos_estados: >
                    {% set nuevos_estados = estados_actuales.copy() %}
                    {% if estados_actuales.canal1 < estados_deseados.canal1 %}
                      {% set nuevos_estados = nuevos_estados | combine({'canal1': [estados_actuales.canal1 + 1, estados_deseados.canal1] | min}) %}
                    {% elif estados_actuales.canal1 > estados_deseados.canal1 %}
                      {% set nuevos_estados = nuevos_estados | combine({'canal1': [estados_actuales.canal1 - 1, estados_deseados.canal1] | max}) %}
                    {% elif estados_actuales.canal2 < estados_deseados.canal2 %}
                      {% set nuevos_estados = nuevos_estados | combine({'canal2': [estados_actuales.canal2 + 1, estados_deseados.canal2] | min}) %}
                    {% elif estados_actuales.canal2 > estados_deseados.canal2 %}
                      {% set nuevos_estados = nuevos_estados | combine({'canal2': [estados_actuales.canal2 - 1, estados_deseados.canal2] | max}) %}
                    {% elif estados_actuales.canal3 < estados_deseados.canal3 %}
                      {% set nuevos_estados = nuevos_estados | combine({'canal3': [estados_actuales.canal3 + 1, estados_deseados.canal3] | min}) %}
                    {% elif estados_actuales.canal3 > estados_deseados.canal3 %}
                      {% set nuevos_estados = nuevos_estados | combine({'canal3': [estados_actuales.canal3 - 1, estados_deseados.canal3] | max}) %}
                    {% elif estados_actuales.canal4 < estados_deseados.canal4 %}
                      {% set nuevos_estados = nuevos_estados | combine({'canal4': [estados_actuales.canal4 + 1, estados_deseados.canal4] | min}) %}
                    {% elif estados_actuales.canal4 > estados_deseados.canal4 %}
                      {% set nuevos_estados = nuevos_estados | combine({'canal4': [estados_actuales.canal4 - 1, estados_deseados.canal4] | max}) %}
                    {% endif %}
                    {{ nuevos_estados }}
              - service: sensor.update_entity
                target:
                  entity_id: sensor.estados_actuales_luces
                data:
                  state: "{{ nuevos_estados | to_json }}"

Hello Josep,

That looks pretty good for a first blueprint, congratulations on getting it to run at all.

My advice is to try to walk a bit before you run. I’m not sure exactly what buttons on your remote you created or what your device requires, but I suggest starting with the Developer / Actions page
Open your Home Assistant instance and show your action developer tools.
and try all your commands to get it doing what you want, then plug those into the blueprint.
Generally I suggest making a simople automation or script that does the action without variables, just to get the base logic working, then expand it. You have the blueprint basically done, you just need to determine what actions you want to do at this point. That is something you have to trial and error yourself.

If you want to compare how I solved a similar problem with a blueprint, you can look at this.
🧯 Script Blueprint to turn my TV on and put it into the correct mode for the Input Device I want (NOT an Automation Blueprint).

Home-Assistant-Config/script2/jennifer_script.yaml at 4d90e91e7bf37d5e6c405d1517aa93a52458693d · SirGoodenough/Home-Assistant-Config · GitHub,

1 Like