Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delonghi Coffee Machine Example #22

Open
bubez81 opened this issue Feb 16, 2023 · 9 comments
Open

Delonghi Coffee Machine Example #22

bubez81 opened this issue Feb 16, 2023 · 9 comments

Comments

@bubez81
Copy link

bubez81 commented Feb 16, 2023

Hi, I noticed your example for the delonghi.
I compiled the code without problems adapting it to my machine and it seems to connect correctly. None of the switches seem to work though:
Screenshot 2023-02-16 alle 19 47 10

logs_cucina_logs.txt

Could it be a machine setting? Or did something change with a firmware update?
Does it work without problems for you?

and thus is my configuration:
`substitutions:
name: "cucina"
delonghi_mac: !secret delonghi_mac
delonghi_name_prefix: Coffee Machine
delonghi_id_prefix: coffee_machine
delonghi_service_uuid: 00035b03-58e6-07dd-021a-08123a000300
delonghi_characteristic_uuid: 00035b03-58e6-07dd-021a-08123a000301
delonghi_update_interval: '5000'

packages:
esphome.bluetooth-proxy: github://esphome/bluetooth-proxies/esp32-generic.yaml@main

globals:

  • id: delonghi_millis
    type: uint32_t
    restore_value: false
    initial_value: '0'

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

esphome:
name: ${name}
name_add_mac_suffix: false
on_loop:
then:
- lambda: |-
if (!id(delonghi_millis)) {
id(binary_sensor_${delonghi_id_prefix}connected).publish_initial_state(false);
id(binary_sensor
${delonghi_id_prefix}).publish_initial_state(false);
id(delonghi_millis) = millis();
}
static unsigned char CMD_HEALTH_CHECK[] = {0x0d, 0x05, 0x75, 0x0f, 0xda, 0x25};
if (id(binary_sensor_${delonghi_id_prefix}connected).state && (millis() - id(delonghi_millis) > ${delonghi_update_interval})) {
auto chr = id(ble_client
${delonghi_id_prefix}).get_characteristic(
esp32_ble_tracker::ESPBTUUID::from_raw("${delonghi_service_uuid}"),
esp32_ble_tracker::ESPBTUUID::from_raw("${delonghi_characteristic_uuid}"));
if (chr) {
ESP_LOGD("${delonghi_id_prefix}", ">>> %s", format_hex_pretty(CMD_HEALTH_CHECK, sizeof(CMD_HEALTH_CHECK)).c_str());
chr->write_value(CMD_HEALTH_CHECK, sizeof(CMD_HEALTH_CHECK));
}
id(delonghi_millis) = millis();
}
esp32_ble_tracker:

mqtt:
topic_prefix: dinamica
discovery: false
broker: 192.168.1.2
port: 1883
username: michele
password: hd0806681

ble_client:

  • mac_address: ${delonghi_mac}
    id: ble_client_${delonghi_id_prefix}
    on_connect: [lambda: "id(binary_sensor_${delonghi_id_prefix}connected).publish_state(true);"]
    on_disconnect: [lambda: "id(binary_sensor
    ${delonghi_id_prefix}_connected).publish_state(false);"]

binary_sensor:

  • platform: template
    id: binary_sensor_${delonghi_id_prefix}_connected
    name: ${delonghi_name_prefix}
    device_class: connectivity
    entity_category: diagnostic

  • platform: template
    id: binary_sensor_${delonghi_id_prefix}
    internal: true

sensor:

  • platform: template
    id: sensor_${delonghi_id_prefix}_alarm
    name: ${delonghi_name_prefix} Alarm
    icon: mdi:alert
    state_class: measurement
    accuracy_decimals: 0

switch:

  • platform: ble_client
    id: switch_${delonghi_id_prefix}enable
    name: ${delonghi_name_prefix} Enable
    ble_client_id: ble_client
    ${delonghi_id_prefix}
    disabled_by_default: true
    entity_category: config

  • platform: template
    id: switch_${delonghi_id_prefix}
    name: ${delonghi_name_prefix}
    icon: mdi:coffee
    lambda: return id(binary_sensor_${delonghi_id_prefix}).state;
    turn_on_action:

    • lambda: |-
      if (!id(binary_sensor_${delonghi_id_prefix}connected).state)
      return;
      static unsigned char CMD_POWER_ON[] = {0x0d, 0x07, 0x84, 0x0f, 0x02, 0x01, 0x55, 0x12};
      auto chr = id(ble_client
      ${delonghi_id_prefix}).get_characteristic(
      esp32_ble_tracker::ESPBTUUID::from_raw("${delonghi_service_uuid}"),
      esp32_ble_tracker::ESPBTUUID::from_raw("${delonghi_characteristic_uuid}"));
      if (chr)
      chr->write_value(CMD_POWER_ON, sizeof(CMD_POWER_ON));
      button:
  • platform: template
    id: button_${delonghi_id_prefix}americano
    name: ${delonghi_name_prefix} Americano
    icon: mdi:coffee-to-go-outline
    on_press:
    then:
    - lambda: |-
    if (!id(binary_sensor
    ${delonghi_id_prefix}connected).state)
    return;
    static unsigned char CMD_AMERICANO_ON[] = {0x0d, 0x12, 0x83, 0xf0, 0x06, 0x01, 0x01, 0x00, 0x28, 0x02, 0x03, 0x0f, 0x00, 0x6e, 0x00, 0x00, 0x06, 0x47, 0x8b};
    static unsigned char CMD_AMERICANO_OFF[] = {0x0d, 0x08, 0x83, 0xf0, 0x06, 0x02, 0x06, 0x18, 0x71};
    auto chr = id(ble_client
    ${delonghi_id_prefix}).get_characteristic(
    esp32_ble_tracker::ESPBTUUID::from_raw("${delonghi_service_uuid}"),
    esp32_ble_tracker::ESPBTUUID::from_raw("${delonghi_characteristic_uuid}"));
    if (chr)
    chr->write_value(CMD_AMERICANO_ON, sizeof(CMD_AMERICANO_ON));

  • platform: template
    id: button_${delonghi_id_prefix}coffe
    name: ${delonghi_name_prefix} Coffe
    icon: mdi:coffee-to-go-outline
    on_press:
    then:
    - lambda: |-
    if (!id(binary_sensor
    ${delonghi_id_prefix}connected).state)
    return;
    static unsigned char COFFE_ON[] = {0x0d, 0x0f, 0x83, 0xf0, 0x02, 0x01, 0x01, 0x00, 0x67, 0x02, 0x02, 0x00, 0x00, 0x06, 0x77, 0xff};
    static unsigned char COFFE_OFF[] = {0x0d, 0x08, 0x83, 0xf0, 0x02, 0x02, 0x06, 0xc4, 0xb1};
    auto chr = id(ble_client
    ${delonghi_id_prefix}).get_characteristic(
    esp32_ble_tracker::ESPBTUUID::from_raw("${delonghi_service_uuid}"),
    esp32_ble_tracker::ESPBTUUID::from_raw("${delonghi_characteristic_uuid}"));
    if (chr)
    chr->write_value(COFFE_ON, sizeof(COFFE_ON));

  • platform: template
    id: button_${delonghi_id_prefix}espresso
    name: ${delonghi_name_prefix} Espresso
    icon: mdi:coffee-to-go-outline
    on_press:
    then:
    - lambda: |-
    if (!id(binary_sensor
    ${delonghi_id_prefix}connected).state)
    return;
    static unsigned char ESPRESSO_ON[] = {0x0d, 0x11, 0x83, 0xf0, 0x01, 0x01, 0x01, 0x00, 0x28, 0x02, 0x03, 0x08, 0x00, 0x00, 0x00, 0x06, 0x8f, 0xfc};
    static unsigned char ESPRESSO_OFF[] = {0x0d, 0x08, 0x83, 0xf0, 0x01, 0x02, 0x06, 0x9d, 0xe1};
    auto chr = id(ble_client
    ${delonghi_id_prefix}).get_characteristic(
    esp32_ble_tracker::ESPBTUUID::from_raw("${delonghi_service_uuid}"),
    esp32_ble_tracker::ESPBTUUID::from_raw("${delonghi_characteristic_uuid}"));
    if (chr)
    chr->write_value(ESPRESSO_ON, sizeof(ESPRESSO_ON));
    text_sensor:

  • platform: ble_client
    id: text_sensor_${delonghi_id_prefix}
    internal: true
    ble_client_id: ble_client_${delonghi_id_prefix}
    service_uuid: ${delonghi_service_uuid}
    characteristic_uuid: ${delonghi_characteristic_uuid}
    notify: true
    update_interval: never
    on_notify:
    then:
    lambda: |-
    static unsigned char packet[19];
    static uint8_t index = 0;
    id(delonghi_millis) = millis();
    ESP_LOGD("${delonghi_id_prefix}", "%s", format_hex_pretty((uint8_t *) x.c_str(), x.size()).c_str());
    if (index + x.size() > sizeof(packet))
    ESP_LOGE("${delonghi_id_prefix}", "Packet longer than (%d) bytes", sizeof(packet));
    else {
    memcpy(&packet[index], x.c_str(), x.size());
    index += x.size();
    if (index > 0 && packet[0] != 0xD0)
    ESP_LOGE("${delonghi_id_prefix}", "Packet has wrong signature (0x%02X)", packet[0]);
    else if (index >= 2 && index >= packet[1] + 1) {
    ESP_LOGD("${delonghi_id_prefix}", "<<< %s", format_hex_pretty(packet, index).c_str());
    uint16_t deviser = 0x1D0F, i3, i4, i5, crc = packet[index - 2] << 8 | packet[index - 1];
    for (int i = 0; i < index - 2; i++) {
    i3 = (((deviser << 8) | (deviser >> 8)) & 0x0000FFFF) ^ packet[i];
    i4 = i3 ^ ((i3 & 0xFF) >> 4);
    i5 = i4 ^ ((i4 << 12) & 0x0000FFFF);
    deviser = i5 ^ (((i5 & 0xFF) << 5) & 0x0000FFFF);
    }
    if (deviser != crc)
    ESP_LOGE("${delonghi_id_prefix}", "CRC error, expected (0x%04X) received (0x%04X)", deviser, crc);
    else {
    switch (packet[2]) {
    case 0x75:
    id(binary_sensor_${delonghi_id_prefix}).publish_state(packet[9] != 0);
    id(sensor_${delonghi_id_prefix}_alarm).publish_state((int32_t) packet[7] +
    (int32_t)(packet[8] << 8) + (int32_t)(packet[12] << 16) + (int32_t)(packet[13] << 24));
    break;
    default:
    ESP_LOGW("${delonghi_id_prefix}", "Unknown packet type (0x%02X)", packet[2]);
    }
    }
    }
    else
    return;
    }
    index = 0;`

@myhomeiot
Copy link
Owner

myhomeiot commented Feb 17, 2023

Hello, it's doesn't work with latest versions of ESPHome, something was changed with ble_client text_sensor. Last working version of ESPHome was 2022.11.5.
If you know how to compile it in ESPHome 2022.11.5, you can try.

You can check if it's communicate with machine if in the log you see >>> requests and <<< replies.
Sometimes machine BT is stuck, you can try to fully power off machine (unplug the cable) and power on it again. BT module of machine working even it's powered off. If communication is OK, you should also see BT sign on the screen of machine sure if it's exists.

Update: After I back to 2022.11.5 it's start working, then I update again to 2023.2.2 it's keep working, so probably the problem was with machine itself and complete powering off/on helps.

[13:13:25][D][coffee_machine:048]: >>> 0D.05.75.0F.DA.25 (6)
[13:13:25][D][text_sensor:067]: 'text_sensor_coffee_machine': Sending state '\xd0'
[13:13:25][D][coffee_machine:162]: D0
[13:13:25][D][text_sensor:067]: 'text_sensor_coffee_machine': Sending state '�u�'
[13:13:25][D][coffee_machine:162]: 12.75.0F
[13:13:25][D][text_sensor:067]: 'text_sensor_coffee_machine': Sending state '��'
[13:13:25][D][coffee_machine:162]: 01.01.00.00.00.00 (6)
[13:13:25][D][text_sensor:067]: 'text_sensor_coffee_machine': Sending state '�'
[13:13:25][D][coffee_machine:162]: 02.00.00.00.00.00 (6)
[13:13:25][D][text_sensor:067]: 'text_sensor_coffee_machine': Sending state ''
[13:13:25][D][coffee_machine:162]: 00.37.4E
[13:13:25][D][coffee_machine:171]: <<< D0.12.75.0F.01.01.00.00.00.00.02.00.00.00.00.00.00.37.4E (19)

@bubez81
Copy link
Author

bubez81 commented Feb 17, 2023

Hello! Yes I can see the BT sign on the screen...let's try to downgrade and see

@bubez81
Copy link
Author

bubez81 commented Feb 17, 2023

nothing, not even changing the version seems to work:
Screenshot 2023-02-17 alle 17 29 35
I also unplugged the power but nothing to do
not even with the plugin in hacs for homeassistant it works even if it used to work

It's like something has changed lately....

@myhomeiot
Copy link
Owner

myhomeiot commented Feb 17, 2023

Which model of Delonghi do you have?
Can you try to turn off machine and turn it on using switch?

@bubez81
Copy link
Author

bubez81 commented Feb 17, 2023

The Dinamica Plus
Sure..:
Screenshot 2023-02-17 alle 19 01 24
I used the hacs plugin for a while https://github.com/Arbuzov/home_assistant_delonghi_primadonna
it worked for months then suddenly stopped working and that's why i tried this system

@myhomeiot
Copy link
Owner

This HACS plugin works same way, so probably something was changed in machine side :(

@bubez81
Copy link
Author

bubez81 commented Feb 17, 2023

Yes, I think so too, I was hoping it was something common to all models but I'm starting to think it's only on my model

@bubez81
Copy link
Author

bubez81 commented Feb 24, 2023

the very strange thing is that with this https://github.com/mmastrac/longshot the machine works...can't understand

@bubez81
Copy link
Author

bubez81 commented Feb 24, 2023

ok i think i understand the problem. The machine doesn't accept more than one command simultaneously so if I monitor the status I can't launch the command to make a coffee so I can't connect to the machine continuously but only when I start the command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants