I’m trying to create an rf433 rc switch, which works with different codes.
the codes are decimal.
I was able to create a binary string for esphome, but i cant figure out how to send id.
globals:
- id: rfcodebinary
type: char[65]
restore_value: no
- id: rfprotocolstring
type: char[4]
restore_value: no
switch:
- platform: template
name: Send Custom RF
id: customrfsend
optimistic: true
restore_state: false
turn_on_action:
- lambda: |-
unsigned long Dec = id(rfcode_custom).state;
unsigned long decimalvalue = id(rfcode_custom).state;
unsigned long bitLength = id(rfbitLength_custom).state;
unsigned int protocol = id(rfprotocol_custom).state;
static char bin[65];
unsigned int i=0;
while (Dec > 0) {
bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0';
Dec = Dec >> 1;
}
for (unsigned int j = 0; j< bitLength; j++) {
if (j >= bitLength - i) {
bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
} else {
bin[j] = '0';
}
}
bin[bitLength] = '\0';
sprintf (id(rfcodebinary), "%s",bin);
sprintf (id(rfprotocolstring), "%d",protocol);
ESP_LOGI("custom", "Custom RF Code to send: decimal: %lu - %d Bit, protocol: %d , binary: %s",decimalvalue,bitLength, protocol, bin) ;
- remote_transmitter.transmit_rc_switch_raw:
protocol: 4
code: !lambda "return id(rfcodebinary).state;"
the ESP LOG values are correct, so it works fine. But, im unable to send to rc switch the binary dode and protocol value…