Add Broadlink Entity to Lovelace with TAB action buttons for TV/ Volume etc.?

Hello,

I have successfully added Broadlink RM4 mini to HA and added some remote commands at it works, but what i need is add this commands to Lovelace so i can with a Single Tab action (a Toggle) set the TV on/off or set the volume repeatly to tab that button.

{
    "version": 1,
    "key": "broadlink_remote_234fa7asdfddaa_codes",
    "data": {
        "television": {
            "Turn off": "JgAUADNr777k+DEEKNx4rEAsNAA0FAAA=",
            "Turn on": "JgByABE2B84K1BFPEAABJQ9097xITEhMSExIUETcSNxMTEjcSNxI3EzYSOBITEhMSExI3ExISExMSEhQRNxI3EjgTEhI3EjcSNxI3EwADWT1LC5MRkAABJUoSAAyFFxQJTiWICmwKmRI/CQANBQAAAAA=",
            "mute": "JgASACMpIioLNwsJF7cMPx04EQANBQAAAAA=",
            "ok": "JgBgAAABJpMSExITEjgSExITEhMSExITgsgdjcSOBM2EzYSNxI4EhMSExI3EhMTEhITEhMSExI3EjcSExI4EzYSNxM2EgAFIgABJkoTAAxNAAEnSRIADE8AASZKEgANBQAAAAAAAA==",
            "power": [
                "JgBoAAABJ5ISExITFDUSExQRFBESgdfdfSNxQSEzYUNRI3FDUUNhITFDUSExQRFBEUERQRFBEUNRITFDYTNhI3EjcSNxI4FAAFHgABJ0kSAAxNAAEoSBIADE0AASZKEgAMTgABJUoSAA0FAAAAAAAAAAAAAAAAAAA=",
                "JgBIAAABKJEUERQRFDYTEhMSExIUEhghgdFDUUNhM2FDUUNRQ2EjcUERQRFBEUERQREhMUERQRFDUUNRQ2EzYSNxQ1FAANBQAAAAAAAAAAAAAAAAAA"
            ],
1 Like

Sure there is more than one way to do it, but one way is to create a script that you can toggle.

Then you can add a button to toggle the script on to trigger your IR signal.

I have this working in an automation to increase the TV volume if someone turns the large fan on:

- id: '1600677311334'
  alias: Lounge TV Volume Adjust
  description: ''
  trigger:
  - platform: state
    entity_id: switch.sonoff04
  condition:
  - condition: state
    entity_id: binary_sensor.samsung_smart_tv
    state: 'on'
  action:
  - choose:
    - conditions:
      - condition: state
        entity_id: switch.sonoff04
        state: 'on'
      sequence:
      - service: remote.send_command
        data:
          device: lounge_tv
          command: volume_up
          num_repeats: 10
        entity_id: remote.broadlink01
    default: []
  - choose:
    - conditions:
      - condition: state
        entity_id: switch.sonoff04
        state: 'off'
      sequence:
      - service: remote.send_command
        data:
          device: lounge_tv
          command: volume_down
          num_repeats: 10
        entity_id: remote.broadlink01
    default: []

In response to your question, I tried to set up the following in a Lovelace button card bit could not get it to work:

type: button
tap_action:
  action: call-service
  service: remote.send_command
  data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: power
name: TV Power

Sorry this does not solve your problem but it may help a bit if you want to go down the automation route.

No luck, where did you get the ID. Is that the device ID? What i need really so simple one touch button in lovelace but it likes so difficult this. It works wel with switch but the i need then click double on the button :face_with_head_bandage:

type: horizontal-stack
cards:
  - type: button
    tap_action:
      action: toggle
    entity: switch.magbox_power
    hold_action:
      action: ''
    show_name: true
    icon: 'mdi:kodi'
  - type: button
    tap_action:
      action: toggle
    entity: switch.magbox_mute
    icon: 'mdi:volume-mute'
  - type: button
    tap_action:
      action: toggle
    entity: switch.magbox_volume_down
    icon: 'mdi:volume-minus'
  - type: button
    tap_action:
      action: toggle
    entity: switch.magbox_volume_up
    icon: 'mdi:volume-plus'
    show_name: true

The entity_id is your Broadlink remote, the Device and Command parameters come from your broadlink_remote_xxxxxxx_coes file located in /config/.storage (these are the names you gave when you recorded the codes):

Thanks, i did that but no luck, it says;

Failed to call service remote/send_command. required key not provided @ data['command']
type: button
tap_action:
  action: call-service
  service: remote.send_command
  data:
    entity_id: remote.irreceiver_remote
    device: magbox
    command: magbox_mute
name: Magbox Mute

this is my set up

in my switch i have this

  - platform: broadlink
    host: bla.bla.bla.bla
    mac: 'bla:bla:bla:nla'
    switches:
      gas_heater:
        friendly_name: "Gas Heater"
        command_on: 'JgBIAAABKJQUERQ2FBEVEBQRFBITEhQ2FBEUNRQ2FRAUEhQ1FDYVEBUQFTUVEBUQFDYVEBURFDUVNRUQFTUVNRUQFTUVNRUQFQANBQ=='
        command_off: 'JgBIAAABK5EVDxY1FRAVEBUQFRAVEBU1FRAVNRU1FQ8WEBU1FTUVEBU1FRAVNRU1FRAVEBUQFTUVEBU1FRAVEBU1FTUVNRUQFQANBQ=='

      gas_control:
        friendly_name: "Gas Control"
        command_on: 'JgBIAAABK5EVEBY0FREVDxYQFRAVEBU1FRAVNBY0FREVEBU0FjQVEBU1FQ8WEBY0FRAWEBUQFTQVERU0FTUVEBU1FTUVNRUQFQANBQ=='
        command_off: 'JgBIAAABK5EVEBU1FRAUERUQFRAVEBY0FRAWNBU1FRAUERU1FDYUERUQFTUVNRUQFRAVEBUQFTUVNRUQFRAVNRU1FTUVNRUQFQANBQ=='

image

bla bla
  - entity: switch.gas_heater
  - entity: sensor.smart_plug_ii_energy_power
  - entity: script.gas_up
  - entity: script.gas_down
bla bla

and the scripts are

gas_up:
  alias: Gas Up
  sequence:
  - data:
      entity_id: input_number.gas_heater
    service: input_number.increment
  - data:
      entity_id: switch.gas_control
    service: switch.turn_on
gas_down:
  alias: Gas Down
  sequence:
  - data:
      entity_id: input_number.gas_heater
    service: input_number.decrement
  - data:
      entity_id: switch.gas_control
    service: switch.turn_off

Yes, in my earlier post I said that I can get it to work in automations but not in a lovelace button, not sure if this is a bug. Someone else has mentioned using a script (which runs the same code as an automation trigger) so maybe you could write a script similar to my config above then have you button turn on the script.

Hi, thanks for that.

I think we are OK with setting up switches to fire the IR codes. What we are discussing here is firing codes learned using the remote.learn_command service via the remote.send_command service. This has the advantage of keeping the long complex IR codes out of your yaml as you only need the specify the device (e.g. “tv”) and command (e.g. “power”).

So far this only seems to work in automations & scripts but not in lovelace.

Can you please help me in my situation how to and what to add in scripts such as “mute” command and what to be added in Lovelace. Guys why is this now so difficult… :sleepy:

OK I will try, I have just configured the following on my system and can comfirm it works.

First the button card (just paste this into a new manual card):

type: button
tap_action:
  action: call-service
  service: script.turn_on
  service_data:
    entity_id: script.tv_mute
name: TV Mute

Now the script:

tv_mute:
  alias: tv_mute
  sequence:
  - service: remote.send_command
    data:
      device: lounge_tv
      command: mute
    entity_id: remote.broadlink01
  mode: single

You should be able to use the above by substituting your entity, device, and command names.

Cheers!

Hello again, while looking into your problem I was able to resolve why my TV remote cards were not working - it was because I had “data” rather than “service_data” in the config.

If you want to try this out you can use the custom:tv-card from HACS as follows:

My yaml for this is shown below:

name: Samsung TV 
theme: ios-dark-mode
tv: true
type: 'custom:tv-card'
back:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: return
channeldown:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: program_down
channelup:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: program_up
down:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: down
entity: binary_sensor.samsung_smart_tv
forward:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: ffwd
home:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: smarthub
info:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: info
left:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: left
play:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: play
power:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: power
reverse:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: rewind
right:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: right
select:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: enter
source:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: source
up:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: up
volume_down:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: volume_down
volume_mute:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: mute
volume_up:
  service: remote.send_command
  service_data:
    entity_id: remote.broadlink01
    device: lounge_tv
    command: volume_up

If you do not want to emulate a remote control then you can just create buttons in a horizontal stack for the functions you require as mentioned in my previous post. The nice thing about doing this way is that you avoid having to deal with all the lengthy IR codes

1 Like

This works now like a charm!!! Thank you so much for that!!!
afbeelding

Another question is just say i want to volume be by every startup stay on the +10 (it should not be when the TV was +5 just you turn off the TV and turn On the TV back not the +15)

And how can i customize such as when you click on a button it must repeat ‘4x down - OK - OK’ so i can automate that a channel will startup automatically on the Box?

Sorry but I don’t understand your question about the TV volume going +5 or +10. Typically when you switch a TV on it will be at the last set volume.

There is a way to have muitiple key presses using the “num_repeats: x” parameter. I use this to automatically turn the TV volume +10/-10 when someone turns on our big noisy fan in the lounge. Here is the automation for it (sonoff04 is the switch for the fan):

- id: '1600677311334'
  alias: Lounge TV Volume Adjust
  description: ''
  trigger:
  - platform: state
    entity_id: switch.sonoff04
  condition:
  - condition: state
    entity_id: binary_sensor.samsung_smart_tv
    state: 'on'
  action:
  - choose:
    - conditions:
      - condition: state
        entity_id: switch.sonoff04
        state: 'on'
      sequence:
      - service: remote.send_command
        data:
          device: lounge_tv
          command: volume_up
          num_repeats: 10
        entity_id: remote.broadlink01
    default: []
  - choose:
    - conditions:
      - condition: state
        entity_id: switch.sonoff04
        state: 'off'
      sequence:
      - service: remote.send_command
        data:
          device: lounge_tv
          command: volume_down
          num_repeats: 10
        entity_id: remote.broadlink01
    default: []

If you always want the TV to come on at a set volume regardless of the way it was last left then maybe you could send a mute command followed by a volume_up with num_repeats:10.

Ok i think with repeats command it works.

Another question, how can i fire multiple scripts after and after. Such as command source, and then arrow left and then OK. In this way i want to do a button so i can with one click set TV on chromecast.

Hi, I think you have two options here …

The first is to create a new longer script to do what you want by chaining the commands together e.g. :

watch_chromecast:
  alias: watch_chromecast
  sequence:
  - service: remote.send_command
    data:
      device: lounge_tv
      command: power
    entity_id: remote.broadlink01
  - delay:
      seconds: 2
  - service: remote.send_command
    data:
      device: lounge_tv
      command: left
    entity_id: remote.broadlink01
  - service: remote.send_command
    data:
      device: lounge_tv
      command: enter
    entity_id: remote.broadlink01
  mode: single

This is just intended as an example and note that you might need a delay after powering on the TV to let it get started and ready to accept the following commands.

The other option would be to create a new script and then call your existing scripts from this one using the script.turn_on service e.g.

watch_chromecast:
  alias: watch_chromecast
  sequence:
  - service: script.turn_on
    entity_id: tv_power
  - delay:
      seconds: 2
  - service: script.turn_on
    entity_id: tv_left
  - service: script.turn_on
    entity_id: tv_enter
  mode: single

Again, this is not real code but just intended to illustrate whow you might go about this. This option would obviously make sense if you already have scripts setup for your codes.

1 Like

This works like a charm!!! Thank you…