Broadlink - Switch or Script?

Hi,

I’ve just got my first Broadlink device, the RM Mini 3 and wanted to add a couple of remotes, so I followed a tutorial on youtube where he sets up a switch.yaml for his remote. I did this for my Moretti Tower Fan however found that when I added a button I had to push it twice each time (toggle button) for it to send a signal. I got around this eventually by putting the code in twice.

- platform: broadlink
  host: 192.#.#.#
  mac: A0:#:#:#:#:#
  switches:
    fan_power:
      friendly_name: "Fan Power"
      command_on: "JgCwBCoPKBAMLCoPKQsRKw0rDSoOKg4qDioq7CkQKg8MKyoPKQ8OKg4qDSs=="
      command_off: "JgCwBCoPKBAMLCoPKQsRKw0rDSoOKg4qDioq7CkQKg8MKyoPKQ8OKg4qDSs=="

I found this way long winded so switched to a script instead for my tv.

#script.yaml
tv_power:
  sequence:
  - service: remote.send_command
    target:
      entity_id: remote.rm_mini3_remote
    data:
      device: LGTV
      command: Power

I’m not sure which is the preferred method?

Your thoughts?

Use:

              tap_action:
                action: call-service
                service: switch.turn_on
                target:
                  entity_id: switch.friendly_name_of_your_TV

That video is nearly 18 months old.

Thank you for replying guys, I’ll try your suggestion Vlad.

I tried to find an up-to-date video, but I could find at the time.

It’s just that the integration and GUI editing have moved on quite a bit since then, making the video over-complicated. The section about learning commands with Developer Tools is fine, but you no longer have to use .yaml to set up the broadlink device nor do you have to copy codes from the .storage file.

Once HA has learned the Broadlink commands in Developer Tools, using them in automations/scripts is very straightforward:

…which gives you:

  - service: remote.send_command
    data:
      device: study_spotlights
      command: Turn on
      num_repeats: 1
    target:
      entity_id: remote.reading_light_remote_remote

Or you can create switches as @vlad suggests. An alternative to switches is input_booleans, with short automations to toggle the Broadlink-controlled device on and off when the “helper” changes state.