433Mhz Transmitter not working on ESPHome

I have a FS1000A transmitter which I would like to get working with an ESPHome. The transmitter itself has been tested to work fine on a raspberry pi using the following code:

RCSwitch mySwitch = RCSwitch();
mySwitch.setProtocol(4);
mySwitch.setPulseLength(320);

mySwitch.send("0110010110011010001101000110");

I tried to get the transmitter working on both ESP32 and ESP32C3, here’s the config from my ESP32C3:

esphome:
  name: esphome-dev
  friendly_name: esphome-dev

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: redacted

ota:
  - platform: esphome
    password: redacted

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

remote_transmitter:
  pin: GPIO1
  rmt_channel: 1
  # RF uses a 100% carrier signal
  carrier_duty_percent: 100%

remote_receiver:
  pin: GPIO0
  dump: rc_switch
  # Settings to optimize recognition of RF devices
  tolerance: 50%
  filter: 250us
  idle: 4ms
  rmt_channel: 2
  # buffer_size: 2kb # only for ESP8266

binary_sensor:
  - platform: remote_receiver
    name: "D_ON"
    rc_switch_raw:
      code: '0110010110011010001101000110'
      protocol: 
        pulse_length: 320
    filters:
      - delayed_off: 
          500ms

button:
  - platform: template
    name: RF Power Button
    on_press:
      - remote_transmitter.transmit_rc_switch_raw:
          code: '0110010110011010001101000110'
          protocol: 
            pulse_length: 320
            sync: [1,6]
            zero: [1,3]
            one: [3,1]
            inverted: False

I also tried it without having a receiver attached simultaneously, but that did not change anything. Potential problems:

  • in the code on the raspi, I set protocol to 4 and changed the pulse length. On esphome, only one of the two is possible, I think. Therefore, I defined the protocol completely to correspond with the RCSwitch protocol 4.
  • esphome seems to swallow the last bit of the payload. If I click the button defined above, I see the following in the log:
[11:09:35][D][button:010]: 'RF Power Button' Pressed.
[11:47:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=4 data='011001011001101000110100011'

In comparison, when I send the signal from the raspi the plug is switched on and the binary_sensor defined above is triggered. The log I get is the following:

[11:48:22][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='0110010110011010001101000110'

Interestingly, it’s caught as protocol 1, whereas the above is caught as protocol 4.

Obviously, the plug is not turning on with the ESPHome which is the reason fot this thread…

Another strange thing: the signals sent from the ESP are not showing up in an openmqttgateway I have running. However, it cannot be an antenna problem, because if I use this transmitter on my raspi and execute the code above, openmqttgateway catches the signal.

Does this mean, that you don’t know if the signal is sent at all?
Since you have some receiver as well, try to catch the raw signal while you transmit.

Anyway, you also should define some repeats, like:

      repeat:
        times: 10
        wait_time: 0ms

Good news first: the ESP with ESPHome is transmitting something!

I looked at my raspi code again and realized I had made some changes back then - modify date was 2015, so guess I just forgot that :wink: The protocol that I implemented for the plugs was basically as follows (so in my config in the start post, sync was wrong):

        protocol: 
          pulse_length: 320
          sync: [1,15]
          zero: [1,3]
          one: [3,1]
          inverted: False

If I set this as protocol in my ESPHome transmitter config and add a 0 to the binary payload (code), the plug switches! Yay! So, I guess I’m on the right track. Still, the OpenMQTTGateway does not hear the ESP talk, but it does so with the raspi (nb: same transmitter). Assumption: The OMG only logs signals it can decode or map to a known protocol and the ESP transmission is still a bit different from the raspi transmission. Interestingly, the raspi transmission is logged in the OMG as protocol 2 with delay of ~490 which would equal

        protocol: 
          pulse_length: 490
          sync: [1,10]
          zero: [1,2]
          one: [2,1]
          inverted: False

Indeed, this protocol definition is similar to the one above. 0’s are about the same length, but 1’s are ~50% longer in this version. The plugs seem to be very tolerant on that regard and work with either of the protocol definitions.

Now, to conclude: Something is off with the ESPHome rc_switch transmission.

  • The last bit of the code is definitely swallowed. If I add a 0 to the end, my plugs switch and ESPHome recognizes the transmission in the receiver. If I put as code what I actually want to send, the plugs do not switch and the receiver log shows a 27 bit code (i.e. last bit missing).
  • Probably, there’s something else odd about the rc_switch capability in ESPHome, because OMG does not recognize signals sent from ESPHome, but does so if they are sent from a raspi. Possibliy, different or missing preamble, header or whatever? Hard to say.

My assumption, no sufficient repeats.

RC-Switch is not a “classic” protocol, it’s a approach to fit received signal to one of these protocols. So if you give 50% tolerance on the receiving code, multiple RC-Sw protocols can be fulfilled.

You’re right! If I set

as you suggested above, it works and OMG recognizes the signal and the plug switches. However, I’m still somewhat convinced, ESPHome just swallows the last bit of the code, because it only works if wait_time is 0. So I guess, it’s just that the second transmission starts with a 0 directly, and OMG and my plug recognize this 0 as still part of the first repetition. If I set wait_time even to only 1ms, it no longer works.

Not sure what the tolerance in OMG is, but probably something in the 50% range.

1ms is long time, try 100us…

But does the fact that it only works with pauses less than one pulse not confirm the assumption that ESPHome loses the last bit in the transmission?

Or maybe I am just misunderstanding something. If so, could you please explain it to me? NB: with the ‘original’ rc_switch lib on the raspi, I do not need a repetition of the signal

I really don’t know, because I don’t have your setup. I’m only assuming from my experience that successful transmissions should be doable with some fine tuning.
Esphome documentation gives:
" If you’re looking for the same functionality as is default in the rpi_rf integration in Home Assistant, you’ll want to set the times to 10 and the wait_time to 0s."

I’m not using HA on my raspi, but a script which I wrote long before I installed HA. Anyways, with repetitions it works, so that will do for me.