Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- remote_receiver:
- pin:
- number: D6
- inverted: false
- # dump: raw
- idle: 10ms
- filter: 250us
- buffer_size: 3k
- on_raw:
- then:
- - lambda: |-
- id(codice) = 0;
- id(indirizzo) = 0;
- ESP_LOGV("DEBUG", "RICEVUTO CODICE RAW DI LUNGHEZZA %u", size(x));
- char message[30];
- int bits = 0;
- if (size(x) >= 38 && size(x) <= 50) {
- for (auto it = x.begin() + 1; it != x.end() -1; it+=2) {
- if (-*it < 2500 && -*it > 1000)
- {
- message[bits] = 0;
- bits += 1;
- }
- else if (-*it < 6200 && -*it > 3500)
- {
- message[bits] = 1;
- bits += 1;
- }
- if (bits == 18) {
- int sum = 0;
- int checksum = 0;
- for (int i = 0; i < 14; i++)
- {
- if (message[i] == 1) sum++;
- }
- checksum = (message[17] * 8) + (message[16] * 4) + (message[15] * 2) + message[14];
- if (checksum == sum) {
- int msgCode[6];
- int msgAddr[8];
- for (int j = 0; j < 14; j++)
- {
- if (j < 6) msgCode[j] = message[j];
- else msgAddr[j - 6] = message[j];
- }
- id(codice) = (msgCode[5] * 32) + (msgCode[4] * 16) + (msgCode[3] * 8) + (msgCode[2] * 4) + (msgCode[1] * 2) + msgCode[0];
- id(indirizzo) = (msgAddr[7] * 128) + (msgAddr[6] * 64) + (msgAddr[5] * 32) + (msgAddr[4] * 16) + (msgAddr[3] * 8) + (msgAddr[2] * 4) + (msgAddr[1] * 2) + msgAddr[0];
- if (id(codice) < 63)
- {
- ESP_LOGD("DEBUG", "RICEVUTO COMANDO = %i", id(codice));
- ESP_LOGD("DEBUG", "RICEVUTO INDIRIZZO = %i", id(indirizzo));
- ESP_LOGD("DEBUG", "CHECKSUM OK");
- auto capi = new esphome::api::CustomAPIDevice();
- capi->fire_homeassistant_event("esphome.comelit_ricevuto", {{"indirizzo", std::to_string(id(indirizzo))}, {"comando", std::to_string(id(codice))}});
- } else {
- id(codice) = 0;
- id(indirizzo) = 0;
- }
- }
- }
- }
- }
- - if:
- condition:
- lambda: 'return (id(codice) > 0) && (id(indirizzo) > 0);'
- then:
- - lambda: |-
- std::string str = "";
- str = "codice " + to_string(id(codice)) + " indirizzo " + to_string(id(indirizzo));
- id(descrizione) = str;
- id(codice) = 0;
- id(indirizzo) = 0;
- - if:
- condition:
- lambda: 'return id(descrizione) != "";'
- then:
- - logger.log:
- format: "Descrizione codice: %s"
- args: ['id(descrizione).c_str()']
- - homeassistant.service:
- service: logbook.log
- data:
- name: "Citofono:"
- entity_id: "binary_sensor.comelit_stato"
- data_template:
- message: "{{ com }}"
- variables:
- com: 'return id(descrizione).c_str();'
- - lambda: 'id(descrizione) = "";'
Advertisement
Add Comment
Please, Sign In to add comment