I created sensors, and thanks to the sensors, I came to some understanding of how to run coffee recipes many times. It turns out that the counter is working and it is impossible to jump over the counter, the coffee recipe will not work. Here’s what I saw
The code for the operation of sensors message 91 and 93
In order for the Message 90 sensor to work, you need to enable debugging in both directions for uart_mainboard. It is not recommended to do this, because because of this, the changed coffee preparation parameters are not saved in the profile and interferes with the normal operation of the coffee machine, so I turned off BOTH and specified RX
- 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: RX
dummy_receiver: false
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
sequence:
- lambda: |-
UARTDebug::log_hex(direction, bytes, ':');
//Coffee drinks
//Message 93. Teaches bytes 0 through 11. We display in this form [0xAA, 0xAA, 0xAA, 0x93, 0x0F, 0x01, 0x01, 0xBC, 0xD7, 0xF1, 0xEB, 0x55]
if (bytes[0] == 0xAA && bytes[2] == 0xAA && bytes[3] == 0x93) {
std::string message93 = "[";
for (int i = 0; i <= 11; i++) {
char hex_str[6];
snprintf(hex_str, sizeof(hex_str), "0x%02X", bytes[i]);
message93 += hex_str;
if (i != 11) {
message93 += ", ";
}
}
message93 += "]";
id(id93message).publish_state(message93);
}
//Message 90. Accounting for bytes from 0 to 20. We display it in this form [0xAA, 0xAA, 0xAA, 0x90, 0x06, 0x0A, 0x00, 0x03, 0x00, 0x02, 0x03, 0x00, 0x1E, 0x00, 0x00, 0x00, 0xC5, 0x47, 0xCB, 0x8E, 0x55]
if (bytes[0] == 0xAA && bytes[2] == 0xAA && bytes[3] == 0x90) {
std::string message90 = "[";
for (int i = 0; i <= 20; i++) {
char hex_str[6];
snprintf(hex_str, sizeof(hex_str), "0x%02X", bytes[i]);
message90 += hex_str;
if (i != 20) {
message90 += ", ";
}
}
message90 += "]";
id(id90message).publish_state(message90);
}
//Message 91.Accounting for bytes from 0 to 11. We display it in this form [0xAA, 0xAA, 0xAA, 0x91, 0x12, 0x01, 0x08, 0xB0, 0x97, 0xDA, 0x2C, 0x55]
if (bytes[0] == 0xAA && bytes[2] == 0xAA && bytes[3] == 0x91) {
std::string message91 = "[";
for (int i = 0; i <= 11; i++) {
char hex_str[6];
snprintf(hex_str, sizeof(hex_str), "0x%02X", bytes[i]);
message91 += hex_str;
if (i != 11) {
message91 += ", ";
}
}
message91 += "]";
id(id91message).publish_state(message91);
}
text_sensor:
- platform: template
name: "Message1 93"
id: id93message
update_interval: 60s
- platform: template
name: "Message2 90"
id: id90message
update_interval: 60s
- platform: template
name: "Message3 91"
id: id91message
update_interval: 60s
To understand how the counter works, you can watch the video
Looking at the Message 90 and 93 sensors, I noticed the following.
This is what bytes look like when the coffee machine offers to choose a drink and before switching off
Turn off the coffee machine
The coffee machine is turned off
The coffee machine was completely de-energized and plugged into an outlet, after a pause of 5 seconds
The coffee machine was turned on, the heating and flushing stage began
The coffee machine has passed the washing stage and offers to choose a drink
I realized that immediately after the coffee machine turns on and offers to choose a drink, it is impossible to send a command to prepare a recipe, since the washing stage will start. To prevent this from happening, you need to wait until it happens like this
When making coffee drinks, the counter is triggered and I had an idea how to run the recipe, but I can’t write the code correctly. ChatGPT is trying to help me, but it doesn’t work well and it offers a bunch of options, and most of the options are wrong, compilation goes wrong. ChatGPT simply offers codes by brute force and there is zero sense from this.
The point is that we extract bytes from the Message 91 sensor and insert it as a variable to send a command, thus simulating the operation of the counter
For the test, I created a button and it works correctly. This is not sending a cooking command, but just checking to see how bytes are being sent. I extract bytes from the Message 91 sensor and send the Message Send button 91 to the sensor and the sensor displays exactly the same as in Message3 91
[0xAA, 0xAA, 0xAA, 0x91, 0x08, 0x01, 0x08, 0x16, 0xB1, 0x6B, 0x3D, 0x55]
- platform: template
name: "Message Button 91"
icon: mdi:coffee
on_press:
- text_sensor.template.publish:
id: idMessageButton
state: !lambda 'return id(id91message).state;'
To send the command, I first tried this option, but it doesn’t work, because when compiling I get an error
button
- platform: template
name: "Coffee"
icon: mdi:coffee
on_press:
- uart.write:
id: uart_mainboard
data: [0xAA, 0xAA, 0xAA, 0x90, 0x06, 0x0A, 0x00, 0x03, 0x00, 0x02, 0x03, 0x00, 0x1E, 0x00, 0x00, 0x00, 0xC5, 0x47, 0xCB, 0x8E, 0x55]
- uart.write:
id: uart_mainboard
data: return 'id(id91message).state;'
And I got this code from ChatGPT, the compilation was successful, but it doesn’t work and I don’t see how bytes are being sent
button
- platform: template
name: "Coffee"
icon: mdi:coffee
on_press:
- uart.write:
id: uart_mainboard
data: [0xAA, 0xAA, 0xAA, 0x90, 0x06, 0x0A, 0x00, 0x03, 0x00, 0x02, 0x03, 0x00, 0x1E, 0x00, 0x00, 0x00, 0xC5, 0x47, 0xCB, 0x8E, 0x55]
- uart.write:
id: uart_mainboard
data: !lambda |-
std::string message = id(id91message).state.c_str();
std::vector<uint8_t> bytes;
for (std::size_t i = 0; i < message.size(); i += 4) {
std::string byte_str = message.substr(i, 4);
uint8_t byte = std::stoi(byte_str, nullptr, 16);
bytes.push_back(byte);
}
return bytes;
Table of analysis of the protocol AA AA AA 90 which is responsible for accounting. The last 4 bytes are the checksum. If you change one byte, the recipe will not work.