I figured it out a bit and found the sensors of the drink counter. Created a table of what and how to parse bytes. It turns out that bytes of this type AA:AA:AA:FF are sensors
AA:AA:AA:FF:B0:01:B0:30:A5:65:E8:55 - Drinks counter (Cappuccino) - number 65
AA:AA:AA:FF:CB:01:CB:35:8A:16:77:55 - Drink counter (Latte ma.) - digit 16
AA:AA:AA:FF:2D:01:2D:6A:61:10:93:55 - Drinks counter (Hot) - digit 10
AA:AA:AA:FF:B4:01:B4:F5:C9:01:E8:55 - Drinks counter (Coffee with mo.) - digit 01
AA:AA:AA:FF:18:01:18:32:82:03:E7:55 - Drink counter (Espresso) - digit 03
AA:AA:AA:FF:36:01:36:17:E4:06:09:55 - Drinks counter (Dairy) - digit 6
AA:AA:AA:FF:23:01:23:67:61:36:7E:55 - The drinks counter (Coffee with m.) is the number 36
AA:AA:AA:FF:D1:01:D1:E9:55:C5:9B:55 - Drinks counter (Express) - digit 197
AA:AA:AA:FF:66:01:66:53:9B:D1:0E:55 - Beverage counter (America.) - digit 521
AA:AA:AA:FF:A5:01:A5:40:20:55:9F:55 - Drinks counter (Coffee) - number 55
I’m not good at ESPHome. How do I create sensors to extract bytes, because they have changing data. ChatGPT shows me some kind of game and I have already stopped believing it, because it often gives false answers. Below I made a config with the iron-specified bits. For example bytes[9]==0xC5 is the number 197 if translated from HEX to a number. So the data bytes[7]==XX && bytes[8]==XX && bytes[9]==XX && bytes[10]==XX change here, but it needs to be displayed in the sensor as numbers
uart:
- id: uart_display
rx_pin: GPIO16
tx_pin: GPIO17
baud_rate: 115200
stop_bits: 1
data_bits: 8
parity: NONE
# rx_buffer_size: 256
# debug:
# direction: BOTH
# dummy_receiver: false
- id: uart_mainboard
rx_pin: GPIO3
tx_pin: GPIO1
baud_rate: 115200
stop_bits: 1
data_bits: 8
parity: NONE
rx_buffer_size: 256
debug:
direction: BOTH
dummy_receiver: false
sequence:
- lambda: |-
UARTDebug::log_hex(direction, bytes, ':');
if (bytes[0]==0xAA && bytes[3]==0xFF && bytes[4]==0xD1 && bytes[5]==0x01 && bytes[9]==0xC5 && bytes[11]==0x55) { id(idDrinkscountEspress).publish_state("197"); }
else if (bytes[0]==0xAA && bytes[3]==0xFF && bytes[4]==0x18 && bytes[5]==0x01 && bytes[9]==0x03 && bytes[11]==0x55) { id(idDrinkscounterEspresso).publish_state("03"); }
else if (bytes[0]==0xAA && bytes[3]==0xFF && bytes[4]==0x23 && bytes[5]==0x01 && bytes[9]==0x36 && bytes[11]==0x55) { id(idDrinkscounterCoffeeMilk).publish_state("36"); }
else if (bytes[0]==0xAA && bytes[3]==0xFF && bytes[4]==0xA5 && bytes[5]==0x01 && bytes[9]==0x55 && bytes[11]==0x55) { id(idDrinkscounterCoffee).publish_state("55"); }
else if (bytes[0]==0xAA && bytes[3]==0xFF && bytes[4]==0x66 && bytes[5]==0x01 && bytes[9]==0xD1 && bytes[11]==0x55) { id(idDrinkscounterAmerica).publish_state("521"); }
text_sensor:
##### Drinks counter
#Drink counter: Espresso 1
- platform: template
id: idDrinkscountEspress
name: "Espress counter"
update_interval: 30s
#Drink counter: Espresso 2
- platform: template
id: idDrinkscounterEspresso
name: "Espresso counter"
update_interval: 30s
#Beverage Counter: Coffee
- platform: template
id: idDrinkscounterCoffee
name: "Coffee Counter"
update_interval: 30s
#Beverage counter: Coffee with milk (Coffee with m.)
- platform: template
id: idDrinkscounterCoffeeMilk
name: "Coffee Counter with Milk"
update_interval: 30s
#Drinks counter: America.
- platform: template
id: idDrinkscounterAmerica
name: "Counter Americano"
update_interval: 30s
That's what GhatGPT offers me, utter nonsense. I will give examples to understand why I don't trust GhatGPT
text_sensor:
- platform: template
id: idDrinkscounterEspresso1
name: "Drink counter: Espresso 1"
update_interval: 60s
lambda: |-
if (id(uart_mainboard).state.length() >= 12 &&
id(uart_mainboard).state[0] == 0xAA &&
id(uart_mainboard).state[3] == 0xFF &&
id(uart_mainboard).state[9] == 0xE0 &&
id(uart_mainboard).state[11] == 0x55) {
char byte4Str[3];
snprintf(byte4Str, sizeof(byte4Str), "%02X", id(uart_mainboard).state[4]);
return std::string(byte4Str);
} else {
return std::string("");
}
text_sensor:
- platform: template
id: idDrinkscounterEspresso1
name: "Drink counter: Espresso 1"
update_interval: 60s
lambda: |-
if (bytes[0] == 0xAA && bytes[3] == 0xFF && bytes[9] == 0xE0 && bytes[11] == 0x55) {
char byte4Str[3];
snprintf(byte4Str, sizeof(byte4Str), "%02X", bytes[4]);
return std::string(byte4Str);
} else {
return std::string("");
}
and when you try to upload the firmware, I get this error
/config/esphome/esp32-smart-coffee-philips.yaml: In lambda function:
/config/esphome/esp32-smart-coffee-philips.yaml:135:11: error: 'bytes' was not declared in this scope
if (bytes[0] == 0xAA && bytes[3] == 0xFF && bytes[9] == 0xE0 && bytes[11] == 0x55) {
^~~~~
/config/esphome/esp32-smart-coffee-philips.yaml:135:11: note: suggested alternative: 'byte'
if (bytes[0] == 0xAA && bytes[3] == 0xFF && bytes[9] == 0xE0 && bytes[11] == 0x55) {
^~~~~
byte
/config/esphome/esp32-smart-coffee-philips.yaml:142:3: warning: control reaches end of non-void function [-Wreturn-type]
^
*** [/data/esp32-smart-coffee-philips/.pioenvs/esp32-smart-coffee-philips/src/main.cpp.o] Error 1
========================== [FAILED] Took 7.20 seconds ==========================