I am hoping someone can help me figure out what I’m doing wrong trying to control a https://www.amazon.com/Etekcity-Household-Appliances-Unlimited-Connections/dp/B00DQELHBS with a Wemos D1 Mini Pro and 433 Transmitter.
I have code that works on using the Arduino IDE that proves that the transmitter works but I can’t seem to adapt it to work in ESPHome.
Here’s the working Arduino IDE code:
#include <RCSwitch.h>
// Array of ON/OFF codes. You must replace these with your codes obtained using a sniffer. This matches the 5 outlet remote.
unsigned long rc_codes[5][2] = {
// ON //OFF
{4478259, 4478268}, /* Outlet 1 */
{4478403, 4478412}, /* Outlet 2 */
{4478720, 4478732}, /* Outlet 3 */
{4480259, 4480268}, /* Outlet 4 */
{4486403, 4486412}, /* Outlet 5 */
};
// The physical Arduino PIN (this will be called with pinMode()). Change this according to your board layout
#define RC_PIN_TX D6
//––//
#define RC_PROTOCOL 1
#define RC_PULSE_LENGTH 190 // 'Delay', if you got the right codes and this isn't working, check that the delay/pulse length from the sniffer matches this
#define RC_BIT_LENGTH 24
RCSwitch sendSwitch = RCSwitch();
void setup()
{
Serial.begin(9600);
sendSwitch.enableTransmit(RC_PIN_TX);
sendSwitch.setProtocol(RC_PROTOCOL); // defaults to 1 anyway
sendSwitch.setPulseLength(RC_PULSE_LENGTH); // this is critical
}
void enableOutlet(int outletNumber, bool onOrOff)
{
if (outletNumber < 1 || outletNumber > 5)
{
Serial.println("Invalid outlet number");
return;
}
unsigned long *onOffCodes = rc_codes[outletNumber - 1];
unsigned long codeToSend = onOffCodes[onOrOff ? 0 : 1];
sendSwitch.send(codeToSend, RC_BIT_LENGTH);
char outletNumberString[1];
int retVal = snprintf(outletNumberString, 1, "%d", outletNumber);
if (retVal < 0)
{
Serial.println("Log encoding error");
return;
}
if (onOrOff)
{
Serial.print("Enabling");
}
else
{
Serial.print("Disabling");
}
Serial.print(" outlet ");
Serial.println(outletNumberString);
}
void loop()
{
delay(1000);
enableOutlet(1, true);
delay(1000);
enableOutlet(1, false);
enableOutlet(2, true);
delay(1000);
enableOutlet(2, false);
}
Here’s my YAML code.:
esphome:
name: 433_remote_transmitter
platform: ESP8266
board: d1_mini_pro
wifi:
ssid: "XXXX"
password: "XXXX"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "433 Remote Transmitter"
password: "c4FOmXCTDPJb"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
remote_transmitter:
pin: D6
carrier_duty_percent: 100%
# Individual switches
switch:
- platform: template
name: "Etekcity 01"
turn_off_action:
remote_transmitter.transmit_rc_switch_raw:
code: '010001000101010100110011'
protocol: 1
turn_off_action:
remote_transmitter.transmit_rc_switch_raw:
code: '010001000101010100111100'
protocol: 1
- platform: template
name: "Etekcity 02"
turn_off_action:
remote_transmitter.transmit_rc_switch_raw:
code: '010001000101010111000011'
protocol: 1
turn_off_action:
remote_transmitter.transmit_rc_switch_raw:
code: '010001000101010111001100'
protocol: 1
The logs say that it’s transmitting but the outlets are not responding.
I tried to change the protocol to:
protocol:
pulse_length: 196
but that doesn’t seem to work either.
Any help is appreciated.