Create custom component or any other tips i can follow

In my home i have 2 TCL dumb airco’s i would like to control from within HA.
I have bought a Broadlink RM4 Mini which works like a charm to control the airco from within the Broadlink App.
Now i want to integrate Broadlink into HA, but then i have to setup and learn the commands to HA while the broadlink app has all the codes.
The Codes for my airco are however all available in ESPHome (experimented with that using an ESP32 Wroom controller and ESPHome flashed to it with a small Infra Red LED connected to one of the pins, and that worked, but it was homebrew and prone to breaking) Is there any way for me to setup an airco component and have that component send the correct codes using the broadlink but without learning the codes, but using the library from ESPHome to calculate the correct code to send including the nice Airco control display in HA.

Are there so many buttons on the remotes?
Seems to me that whatever you plan to do as a workaround is more effort than the learning process…

But if you want to proceed, please post your ESPHome code.

this is the required part of my ESPHome code:

remote_transmitter:
  pin: GPIO18
  carrier_duty_percent: 50%

climate:
  - platform: tcl112       # adjust to match your AC unit!
    name: "Living Room AC"
    sensor: LRT
    visual:
      temperature_step: 1

sensor:
  - platform: dht
    model: AM2302
    pin: GPIO19
    temperature:
      id: LRT
      name: "Living Room Temperature"
      accuracy_decimals: 1
    humidity:
      name: "Living Room Humidity"
      accuracy_decimals: 1
    update_interval: 60s

But i want to use the Broadlink transmitter to transmit the codes without using an ESPHome if possible.
The TCL112 library from ESPHome works like a charm for my Aircon unit. and the ESPHome does give the nice Aircon widget whereas the custom learned commands are just buttons.
If i want to have the aircon set to anything i havent learned it yet using the normal Broadlink way, i have to learn it a new button, create a new automation to send the code, add a button to HA while if i can use the Climate component that HA already has, it would be so much nicer.

The main issue is that my remote sends all command in a single go so when it is turned on, it sends on, temp, swing, heat/cool/fan/dehumidify in a single command. if i change the temp, it still send all commands: on, new temp, swing, heat/cool/fan/dehumidify and everything else i forgot to mention for the settings, that means i have to learn more then 50 commands to the Broadlink. On 17 degrees swing cool, On 18 degreees swing cool, On 19 degrees swing cool etc. etc. and also an off as alternate command for all settings. that immediatly doubles the ammount of commands.

For reference, the ESPHome code: https://github.com/esphome/esphome/blob/b9e9223fddfa47e8641c25d4e87a7c90866606f8/esphome/components/tcl112/tcl112.cpp

The IR codes are programmatically generated, there is no “list”.
And that won’t magically creates a climate entity in HA, anyway.

As I said, just learn the code the dumb way, then use a “Generic Themostat” to “build” an HA entity, no need to “on 17 degrees swing cool, On 18 degreees swing cool, On 19 degrees swing cool”…

Now, you’ll still need a temperature sensor, somewhere, like the DHT you had in ESP…

Hey @koying i never said that ESPHome had a list. i only said that ESPHome has the codes (indeed it generates them, i found that myself already) But this still needs me to learn all the combinations that are possible. That means about 75 (including the alternate) codes i need to learn.

I’ll go ahead and try if i can generate the codes (using the ESPHome code as a base) that needs to bee send using the broadlink and indeed the sensor that i can use i already have in my HA instance (living room ac can use temp sensor from thermostat for central heating which has a temp sensor i already see in HA.

I’m just wondering if i create the custom Generic Thermostat, how can i set it to send codes using the broadlink? that is something i don’t understand.

Ah, that won’t work if your unit can do both cold and heat, indeed.
There is custom component that does both, though:

The way it work is that you create 2 template switches, one that sends the IR “cool” command, the other that sends the “hot” command.
Those are basically the only 2 buttons that you need. The component has all the logic regarding when to activate one or the other based upon the temperature given by a sensor.

And how do i make it set a temperature like 20 degrees when setting it to cool? or enable or disable swing or… or… or…

That’s managed by the climate entity in HA. You set a desired temperature.
Looks like you didn’t read the doc.

That’s 1 (one) button on your remote

Whatever pal. You seem to have your mind set :wink:
You asked for tips, those were mine.
Good luck.

Sorry that i don’t understand how this works. i don’t have my mind set to completely understand this, i’m trying to understand. my mind can’t grasp this concept at this moment. that’s why i ask for advice.
I’m willing to learn but the docs don’t mention how i can send a specific temperature. as said, the IR code for my aircon sends all commands in a single burst always. that’s why i can’t grasp how to just send temperature, my aircon doesn’t understand just a temperature command.

Using this page: https://www.onlinegdb.com/online_c++_compiler and this small bit of code on that site

#include <iostream>
#include <string>
#include <string_view>

using namespace std;

int main()
{
    const uint16_t TCL112_STATE_LENGTH = 14;
    const uint16_t TCL112_BITS = TCL112_STATE_LENGTH * 8;

    const uint8_t TCL112_HEAT = 1;
    const uint8_t TCL112_DRY = 2;
    const uint8_t TCL112_COOL = 3;
    const uint8_t TCL112_FAN = 7;
    const uint8_t TCL112_AUTO = 8;

    const uint8_t TCL112_FAN_AUTO = 0;
    const uint8_t TCL112_FAN_LOW = 2;
    const uint8_t TCL112_FAN_MED = 3;
    const uint8_t TCL112_FAN_HIGH = 5;

    const uint8_t TCL112_VSWING_MASK = 0x38;
    const uint8_t TCL112_POWER_MASK = 0x04;
    
    const uint8_t TCL112_HALF_DEGREE = 0b00100000;

    const uint16_t TCL112_HEADER_MARK = 3100;
    const uint16_t TCL112_HEADER_SPACE = 1650;
    const uint16_t TCL112_BIT_MARK = 500;
    const uint16_t TCL112_ONE_SPACE = 1100;
    const uint16_t TCL112_ZERO_SPACE = 350;
    const uint32_t TCL112_GAP = TCL112_HEADER_SPACE;
    uint8_t remote_state[TCL112_STATE_LENGTH] = {0};
    remote_state[0] = 0x23;
    remote_state[1] = 0xCB;
    remote_state[2] = 0x26;
    remote_state[3] = 0x01;
    remote_state[5] = 0x24;
    remote_state[6] = 0x03;
    remote_state[7] = 0x07;
    remote_state[8] = 0x40;
    for (uint8_t checksum_byte = 0; checksum_byte < TCL112_STATE_LENGTH - 1; checksum_byte++)
        remote_state[TCL112_STATE_LENGTH - 1] += remote_state[checksum_byte];
    printf ("Sending: %02X %02X %02X %02X   %02X %02X %02X %02X   %02X %02X %02X %02X   %02X %02X\n", remote_state[0],
           remote_state[1], remote_state[2], remote_state[3], remote_state[4], remote_state[5], remote_state[6],
           remote_state[7], remote_state[8], remote_state[9], remote_state[10], remote_state[11], remote_state[12],
           remote_state[13]);

    remote_state[6] &= 0xF0;
    remote_state[6] |= TCL112_COOL;
    remote_state[5] &= ~TCL112_POWER_MASK;

    for (uint8_t checksum_byte = 0; checksum_byte < TCL112_STATE_LENGTH - 1; checksum_byte++)
        remote_state[TCL112_STATE_LENGTH - 1] += remote_state[checksum_byte];
    printf ("Sending: %02X %02X %02X %02X   %02X %02X %02X %02X   %02X %02X %02X %02X   %02X %02X\n", remote_state[0],
           remote_state[1], remote_state[2], remote_state[3], remote_state[4], remote_state[5], remote_state[6],
           remote_state[7], remote_state[8], remote_state[9], remote_state[10], remote_state[11], remote_state[12],
           remote_state[13]);

    return 0;
}

i have figured out that i need to send this command to turn the aircon on at temp 24C set to cool (hexadecimal) 23 CB 26 01 00 24 03 07 40 00 00 00 00 83 and that i need to send 23 CB 26 01 00 20 03 07 40 00 00 00 00 02 to turn the airco off. if i want to send the heat command at the same temp and power on the airco (if it is not on) i need to send 23 CB 26 01 00 24 01 07 40 00 00 00 00 04. when looking through the docs of the custom component and the code of that component, nowhere is mentioned that that code is being sent. as you can see the differences are minor that need to be sent, but to send the command it also needs to be base64 encoded, which means each command is completely different thansk to the base64 encoding.

maybe now you understand why i have such a difficult time grasping this as you explain it so easily. it means that i still have to learn all commands to the broadlink and not just on (as that always has the last temp set, also being sent to the aircon). if i set the aircon to heat at 30 degrees and then turn it of. when i turn it back on (using the original remote) it always returns to the last setting.

anybody else with suggestions and/or help?

I’m sorry, if I might get that wrong, but what you want to do is use an ESP device to control your climate via IR and not via Broadlink, correct?

Than use this:

If you still want to go with the Broadlink, here is an app to make that easier:

And on top of all of this, what TCL unit are you running? Is there a possibility it can be equipped with some sort of WIFI dongle (from the manufacturer)? If so, you might want to take a broader search, chances are high someone already had it covered with an ESP component… :wink:

I am indeed going the Broadlink route (ir atleast try to go that route) but this SmartIR looks like exactly what i need. the TCL i have doesn’t have a wifi builtin and if i want wifi, i need a new mainborad. i hvae searched hard and long for this, but no ability to use an ESP (atleast not directly like some other projects)

SmartIR is a nifty little integration, that works quite nice. I had it running with a RFMini before the Midea component in ESPHome became available.

And you could as well use an ESP device with added IR. Many possibilities, and you have your climate entity. :+1: :slight_smile:

I implemented it and indeed this works like a charm. exactly like i imagined it.
Thank you for this. But what i can see in the source, is that it still send normal encoded ir commands which still contain all the settings. just as i thought :smiley: but nonetheless, this works.