I had a few minutes to spare so here are a minimal nexa send code for esphome that rlt can pick up
433_switch_control.yaml
esphome:
name: 433_switch_control_test
platform: ESP8266
board: esp01_1m
includes:
- 433_switch_main.h
wifi:
fast_connect: true
ssid: "xxxxxx"
password: "xxxx"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
safe_mode: True
switch:
- platform: custom
lambda: |-
auto test0 = new New_remote_switch(9821046,0);
auto test1 = new New_remote_switch(9821046,1);
auto test2 = new New_remote_switch(9821046,2);
App.register_component(test0);
App.register_component(test1);
App.register_component(test2);
return {test0,test1,test2};
switches:
- name: "test0_"
- name: "test1_"
- name: "test2_"
text_sensor:
- platform: custom
lambda: |-
auto last_sent_received = new Last_sent_received();
App.register_component(last_sent_received);
return {last_sent_received};
text_sensors:
name: "last sent"
433_switch_main.h
just change the _tx_pin below to whatever you need
#include "esphome.h"
#define _tx_pin 1 //set tx pin here
unsigned long send_NRS_adress[4] = {0};
char send_NRS_unit[4] = {0};
char send_NRS_state[4] = {0};
int send_NRS_dimmer[4] = {0};
//-------------------------------------------------------------------------------------------------------------
class New_remote_switch : public Component, public Switch {
public:
int counter = 0;
uint32_t adress;
uint8_t unit;
New_remote_switch(uint32_t adress_, uint8_t unit_) {
adress = adress_;
unit = unit_;
}
void write_state(bool state) override {
extern unsigned long send_NRS_adress[4];
extern char send_NRS_unit[4];
extern char send_NRS_state[4];
for (int i = 0; i <= 3; i++)
{
if(send_NRS_adress[i]==0)
{
send_NRS_adress[i] = adress;
send_NRS_unit[i] = unit;
send_NRS_state[i] = state;
break;
}
}
publish_state(state);
}
};
//-----------------------NewRemoteSwitch---------------https://github.com/1technophile/NewRemoteSwitch
unsigned int pulselength;
bool invertedSignal;
uint8_t _repeats=4;
unsigned int _periodusec=260;
unsigned long _address;
void _sendBit(boolean isBitOne) {
if (isBitOne) {
// Send '1'
digitalWrite(_tx_pin, HIGH);
delayMicroseconds(_periodusec);
digitalWrite(_tx_pin, LOW);
delayMicroseconds(_periodusec * 5);
digitalWrite(_tx_pin, HIGH);
delayMicroseconds(_periodusec);
digitalWrite(_tx_pin, LOW);
delayMicroseconds(_periodusec);
} else {
// Send '0'
digitalWrite(_tx_pin, HIGH);
delayMicroseconds(_periodusec);
digitalWrite(_tx_pin, LOW);
delayMicroseconds(_periodusec);
digitalWrite(_tx_pin, HIGH);
delayMicroseconds(_periodusec);
digitalWrite(_tx_pin, LOW);
delayMicroseconds(_periodusec * 5);
}
}
void _sendAddress() {
for (int8_t i=25; i>=0; i--) {
_sendBit((_address >> i) & 1);
}
}
void _sendUnit(uint8_t unit) {
for (int8_t i = 3; i >= 0; i--) {
_sendBit(unit & 1 << i);
}
}
void _sendStopPulse() {
digitalWrite(_tx_pin, HIGH);
delayMicroseconds(_periodusec);
digitalWrite(_tx_pin, LOW);
delayMicroseconds(_periodusec * 40);
}
void _sendStartPulse(){
digitalWrite(_tx_pin, HIGH);
delayMicroseconds(_periodusec);
digitalWrite(_tx_pin, LOW);
delayMicroseconds(_periodusec * 10 + (_periodusec >> 1)); // Actually 10.5T insteat of 10.44T. Close enough.
}
void sendUnit(uint8_t unit, boolean switchOn,unsigned long adress) {
for (int8_t i = _repeats; i >= 0; i--) {
_address=adress;
_sendStartPulse();
_sendAddress();
// No group bit
_sendBit(false);
// Switch on | off
_sendBit(switchOn);
_sendUnit(unit);
_sendStopPulse();
}}
void sendDim(uint8_t unit, uint8_t dimLevel,unsigned long adress) {
for (int8_t i = _repeats; i >= 0; i--) {
_address=adress;
_sendStartPulse();
_sendAddress();
// No group bit
_sendBit(false);
//if we have dimmlevel send state 2 =dimmer..
if(dimLevel)
{
// Switch type 'dim'
digitalWrite(_tx_pin, HIGH);
delayMicroseconds(_periodusec);
digitalWrite(_tx_pin, LOW);
delayMicroseconds(_periodusec);
digitalWrite(_tx_pin, HIGH);
delayMicroseconds(_periodusec);
digitalWrite(_tx_pin, LOW);
delayMicroseconds(_periodusec);
}
else// if no dimmlevel send state 0 = off, sending dimmer 0 and state 2 leaves my dimmer turned on, on the lowest level
{
_sendBit(0);
}
_sendUnit(unit);
//0-15 dimm
for (int8_t j=3; j>=0; j--) {
_sendBit(dimLevel & 1<<j);
}
_sendStopPulse();
}
}
class Last_sent_received : public PollingComponent, public TextSensor {
public:
Last_sent_received() : PollingComponent(50) {}
void setup() override {
#if defined(ESP8266) // kill serial if rx/tx pins are used, like on esp01
if(_tx_pin==1||_tx_pin==3)
{
Serial.end();
}
#endif
pinMode(_tx_pin,OUTPUT);
}
void update() override {
for (int i = 0; i <= 3; i++)
{
if (send_NRS_adress[i])//we have data from NRS
{
if (send_NRS_state[i] == 2 ) {
sendDim(send_NRS_unit[i], send_NRS_dimmer[i], send_NRS_adress[i]);
}
else {
sendUnit(send_NRS_unit[i], send_NRS_state[i], send_NRS_adress[i]);
}
std::string my_data;
my_data = "send address ";
my_data += to_string(send_NRS_adress[i]);
my_data += "unit ";
my_data += to_string(send_NRS_unit[i]);
my_data += "switchType ";
my_data += to_string(send_NRS_state[i]);
if (send_NRS_state[i] == 2)
{
my_data += " dimmer ";
my_data += to_string(send_NRS_dimmer[i]);
}
publish_state(my_data);
send_NRS_adress[i] = 0;
break; // only send 1 signal per loop
}
}
}
};