Create remote template entity

I’d like to be able to add a templated remote, like we can do for an alarm control panel, for example (see docs).

My specific use case is that I’m using a ZigBee device which is not respecting ZigBee standards, so I’m using a quirk. But the quirk is not yet integrated, and it is not producing a Remote entity, so you need to call into its services directly, which is cumbersome. People are developing all types of hacks to be able to make this less painful, but it is very painful nonetheless.

A templated remote would ease a lot of that pain, allowing us to simply call the underlying learn/send ZigBee commands.

Such templated remote should be able to store the codes it learned somewhere. I don’t know the best way to do this, but I’ve seen the implementation from LocalTuya, where they save in a json file. Something like that would be good enough, but I don’t care about this details so much. What I can say about it is that it makes it very easy to reuse codes, for example, if you have more than one device of a type you simply edit the json file, copying the json nodes and changing the device name.

I was going to hack something quick as it does not seem like a super hard task but 1. I’m not an expert in Python and 2. this seems complex for someone that doesn’t know the inner workings of Home Assistant. I’ve seen a custom templated climate entity, and it seems simple. These projects would be what I’d use to build such an implementation.

What do you think?

Why not just create template buttons?

They would be repetitive. If I have 10 devices I control with the IR blaster I’d need to create 10 template buttons with the exact same yaml, only varying the infrared code.

If I have a templated remote it would mimic the existing, physical device, which, at this moment, does not offer yet a Remote entity. Only the one entity for the existing one physical device.

Another reason I have for this is I’d have hundreds of unnecessary buttons. Because of the way air conditioners frequently work (all 4 at my home are like this), they send the whole configuration whenever you press any key (for example: temperature x cold x fan speed). This means I have to record hundreds of IR codes, and that would create hundreds of templated buttons.
At the moment I’m using a wifi IR remote which shows in HA as a Remote (I’m switching to ZigBee) and the climate template I linked. All I need to do is detect the change from HA and, using standard names, compose the name of the command, from the hundred codes I already recorded.

I hope that clarifies the use case.

You’d still need to do the same thing with remote, how else do you think it’ll know what to do with each command you run?

1 Like

No, with the remote I’d need only one Remote, the one that matches the physical one.
The commands are saved in the device’s database, as I showed in the current example, with LocalTuya.

You’d still need to map actions for each physical remote button. That’s how template entities work.

Yes, and you’d have to build that in the template entity… the exact same way you’d build that in template buttons…

As I mentioned before, I’m using standard names to find the combination using the climate template. For example:

    set_fan_mode:
      - alias: configura o ventilador
        service: remote.send_command
        target:
          device_id:
            - 707753043101d2fd6d551841f434b9f2
        data:
          device: Ar condicionado Fujitsu ASBG12LMCA
          command:
            - "{{
              'Frio' if states('climate.ar_escritorio') == 'cool' else (
                'Seco' if states('climate.ar_escritorio') == 'dry' else (
                  'Ventilador' if states('climate.ar_escritorio') == 'fan_only' else (
                    'Quente' if states('climate.ar_escritorio') == 'heat' else 'Auto'
                  )
                )
              )}}{{
                '_Temp' ~ (state_attr('climate.ar_escritorio', 'temperature')) if states('climate.ar_escritorio') != 'fan_only' else ''
              }}{{
                '_FanAuto' if states('climate.ar_escritorio') == 'dry' else '_Fan' ~ state_attr('climate.ar_escritorio', 'fan_mode')
              }}"

This few lines can run a combination of hundreds of codes.

Which is no different than a script.

fake_remote:
  variables:
    config:
      tv_power: "BW4jyBE+AsABA5EGPgLgCwFAF0ADQAFAB+AHA+ADAUAb4AcBQBPAA0ABwAvABwf3nW4jAAk+Ag=="
      tv_input_next: "B3MjkRFkAhsCgAMEhAZkAhtgAeADBwFkAkAXQAPgAwtAD+APA8AnQAfgCwNANwAbIAEBhAZAAxFkAgydcyPLCGQC//9zI8sIZAI="
      tv_channel_up: "BUQj3xE8AsABA5EGPALgCwFAF0ADQAFAB+AHA+AXAeAHL+AHDwfinUQj9Ag8Ag=="
      tv_channel_down: "BYgjwBE8AsABA5UGPALgCwFAF0ADQAFAB+ALA+AXAeALM8ATB+CdiCPdCDwC"
      tv_nav_up: "BXsjwBE8AsABA5IGPALgCwFAF0ADQAFAB+ALA0ABQBfgAwHgAw/AC0AHwANAAQuSBjwCyJ17I/EIPAI="
      tv_nav_down: "BUEj3xE8AsABA5QGPALgCwFAF0ADQAFAB+AHA0ABwBPgAwFAE0ABwAdAAUALwANAAQuUBjwC1p1BI/YIPAI="
      tv_nav_left: "BVgjwxE7AsABA5cGOwLgCwFAF0ADQAFAB+ATA+ADAUAn4AcBQBPAA0ABC5cGOwLKnVgj7wg7Ag=="
      tv_nav_right: "BVkjxBE6AsABA5UGOgLgCwFAF0ADQAFAB+AHA+ADAUAbwAHAC0AHwANAAeAHCwfPnVkjBwk6Ag=="
      tv_nav_ok: "BWAjwBE7AsABA5QGOwLgCwFAF0ADQAFAB+AHA8ABQBfgAwHAD0AHQANAAUAHwAMHOwI7ApQGOwI="
  sequence:
      - condition: template
        value_template: "{{ command is defined and command in config }}"
      - alias: configura o ventilador
        service: remote.send_command
        target:
          device_id:
            - 707753043101d2fd6d551841f434b9f2
        data:
          device: Ar condicionado Fujitsu ASBG12LMCA
          command: "{{ config.get(command) }}"

using it…

- service: script.fake_remote
  data:
    command: tv_channel_up

I hadn’t thought of that, I’ll try to use the idea and report back.

I just tried it, it works great. Thanks for the insight!

I’ll work on it a little further and I’ll share what I find in the Github thread, I imagine a lot of people are going through similar issues.

This is good enough, I won’t need the templated IR remote. Thanks again!

A template remote wouldn’t be hard to implement, but I don’t think it gives the user any benefits. It essentially would just allow you to create a switch that has the ability to send commands.

I have been working on getting everything in order, and there is one use case that has been taking much more time: learning the IR codes. With the built-in service call it is as easy as listing tens of codes, and then pressing the physical remote buttons in order. Now I need to do one by one, recording every code learned and pasting it in the file.
It is a lot of work.

I’m not sure if there is an easy way to solve this. When I get to the air conditioner this will take at long time, as there are hundreds of combinations…

In my case, I would like to use Remote template to split a physical/real remote entity of a hub (like Broadlink, Tuya IR through LocalTuya) into multiple remote entities that I can use in the Universal TV Card.

This should make configuring the card a lot simpler, as I could just make the template entity mimic the command names of an Android TV remote entity, and therefore the card would self-configure.

I’m also interested in using it for connecting non Airplay TVs to the native remote integration with HomeKit. Currently I can create switches to emulate the TV but I cannot expose it as a remote entity to the native IOS remote feature.
Currently I’m using Tuya local as well with a generic Chinese IR blaster.

I will likely implement this in the future however we need to wait for a few PRs to go through to fix other aspects of template sensors before this can be added.

1 Like