dmitry-cherkas / esphome-danfoss-eco

Extend Danfoss Eco eTRV BLE range over WiFi with ESPHome.
MIT License
21 stars 11 forks source link

Unable to compile with esphome version: 2022.9.4 - [Not Solved] diff in comment that compiles, but does not run stable #11

Closed hcjehg closed 1 year ago

hcjehg commented 1 year ago

Hello Dimitry

I am getting the following when compiling in esphome 2022.9.4. I'm guessing changes has been made in the ble_client :-)

Perhaps I'm doing something wrong? Any input will be received with thanks :-)

Do you have anywhere it is possible to donate coffe or beer? :-)

HC

Compiling with

esphome version

Version: 2022.9.4

gives me the folowing:

(esphome_py) [esphome@HomeAssistant esphome_py]# esphome version Version: 2022.9.4 (esphome_py) [esphome@HomeAssistant esphome_py]# esphome compile esp32-eco2-01.yaml INFO Reading configuration esp32-eco2-01.yaml... INFO Generating C++ source... INFO Compiling app... Processing esp32-eco2-01 (board: esp32-poe-iso; framework: arduino; platform: platformio/espressif32 @ 3.5.0)

HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf Dependency Graph |-- xxtea-iot-crypt @ 2.0.1 |-- WiFi @ 1.0 |-- ESPmDNS @ 1.0 |-- Update @ 1.0 Compiling .pioenvs/esp32-eco2-01/src/esphome/components/danfoss_eco/device.cpp.o Compiling .pioenvs/esp32-eco2-01/src/esphome/components/danfoss_eco/properties.cpp.o Compiling .pioenvs/esp32-eco2-01/src/esphome/components/esp32/core.cpp.o Compiling .pioenvs/esp32-eco2-01/src/esphome/components/esp32/gpio_arduino.cpp.o Compiling .pioenvs/esp32-eco2-01/src/esphome/components/esp32/gpio_idf.cpp.o Compiling .pioenvs/esp32-eco2-01/src/esphome/components/esp32/preferences.cpp.o Compiling .pioenvs/esp32-eco2-01/src/esphome/components/esp32_ble_client/ble_characteristic.cpp.o src/esphome/components/danfoss_eco/properties.cpp: In member function 'bool esphome::danfoss_eco::DeviceProperty::read_request(esphome::ble_client::BLEClient)': src/esphome/components/danfoss_eco/properties.cpp:29:59: error: 'class esphome::ble_client::BLEClient' has no member named 'gattc_if' auto status = esp_ble_gattc_read_char(client->gattc_if, ^ src/esphome/components/danfoss_eco/properties.cpp:30:59: error: 'class esphome::ble_client::BLEClient' has no member named 'conn_id' client->conn_id, ^ In file included from src/esphome/components/climate/climate.h:7:0, from src/esphome/components/danfoss_eco/properties.cpp:1: src/esphome/components/danfoss_eco/properties.cpp: In member function 'bool esphome::danfoss_eco::WritableProperty::write_request(esphome::ble_client::BLEClient, uint8_t, uint16_t)': src/esphome/components/danfoss_eco/properties.cpp:41:148: warning: 'std::__cxx11::string esphome::hexencode(const uint8_t, uint32_t)' is deprecated: hexencode() is deprecated, use format_hex_pretty() instead. [-Wdeprecated-declarations] ESP_LOGD(TAG, "[%s] writerequest: handle=%#04x, data=%s", this->component->get_name().c_str(), this->handle, hexencode(data, data_len).c_str()); ^ src/esphome/core/log.h:92:89: note: in definition of macro 'esph_log_d' esp_logprintf(ESPHOME_LOG_LEVEL_DEBUG, tag, LINE, ESPHOME_LOG_FORMAT(format), ##VA_ARGS) ^ src/esphome/components/danfoss_eco/properties.cpp:41:13: note: in expansion of macro 'ESP_LOGD' ESP_LOGD(TAG, "[%s] writerequest: handle=%#04x, data=%s", this->component->get_name().c_str(), this->handle, hexencode(data, data_len).c_str()); ^ In file included from src/esphome/components/climate/climate.h:5:0, from src/esphome/components/danfoss_eco/properties.cpp:1: src/esphome/core/helpers.h:654:20: note: declared here inline std::string hexencode(const uint8_t data, uint32_t len) { return format_hex_pretty(data, len); } ^ src/esphome/components/danfoss_eco/properties.cpp:43:60: error: 'class esphome::ble_client::BLEClient' has no member named 'gattc_if' auto status = esp_ble_gattc_write_char(client->gattc_if, ^ src/esphome/components/danfoss_eco/properties.cpp:44:60: error: 'class esphome::ble_client::BLEClient' has no member named 'conn_id' client->conn_id, ^ src/esphome/components/danfoss_eco/device.cpp: In member function 'virtual void esphome::danfoss_eco::Device::setup()': src/esphome/components/danfoss_eco/device.cpp:22:36: error: 'class esphome::ble_client::BLEClient' has no member named 'address' copy_address(this->parent()->address, this->parent()->remote_bda); ^ src/esphome/components/danfoss_eco/device.cpp:22:61: error: 'class esphome::ble_client::BLEClient' has no member named 'remote_bda' copy_address(this->parent()->address, this->parent()->remote_bda); ^ src/esphome/components/danfoss_eco/device.cpp: In member function 'virtual void esphome::danfoss_eco::Device::gattc_event_handler(esp_gattc_cb_event_t, esp_gatt_if_t, esp_ble_gattc_cb_param_t)': src/esphome/components/danfoss_eco/device.cpp:99:63: error: 'class esphome::ble_client::BLEClient' has no member named 'remote_bda' if (memcmp(param->connect.remote_bda, this->parent()->remote_bda, 6) != 0) ^ In file included from src/esphome/components/climate/climate.h:7:0, from src/esphome/components/danfoss_eco/device.h:4, from src/esphome/components/danfoss_eco/device.cpp:1: src/esphome/components/danfoss_eco/device.cpp: In member function 'virtual void esphome::danfoss_eco::Device::set_secret_key(uint8_t*, bool)': src/esphome/components/danfoss_eco/device.cpp:268:108: warning: 'std::cxx11::string esphome::hexencode(const uint8_t*, uint32_t)' is deprecated: hexencode() is deprecated, use format_hex_pretty() instead. [-Wdeprecated-declarations] ESP_LOGD(TAG, "[%s] secret_key bytes: %s", this->get_name().c_str(), hexencode(key, SECRET_KEY_LENGTH).c_str()); ^ src/esphome/core/log.h:92:89: note: in definition of macro 'esph_log_d' esp_logprintf(ESPHOME_LOG_LEVEL_DEBUG, tag, LINE, ESPHOME_LOG_FORMAT(format), ##VA_ARGS__) ^ src/esphome/components/danfoss_eco/device.cpp:268:7: note: in expansion of macro 'ESP_LOGD' ESP_LOGD(TAG, "[%s] secret_key bytes: %s", this->get_name().c_str(), hexencode(key, SECRET_KEY_LENGTH).c_str()); ^ In file included from src/esphome/core/automation.h:5:0, from src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h:4, from src/esphome/components/esp32_ble_client/ble_client_base.h:5, from src/esphome/components/ble_client/ble_client.h:3, from src/esphome/components/danfoss_eco/device.h:3, from src/esphome/components/danfoss_eco/device.cpp:1: src/esphome/core/helpers.h:654:20: note: declared here inline std::string hexencode(const uint8_t *data, uint32_t len) { return format_hex_pretty(data, len); } ^ [.pioenvs/esp32-eco2-01/src/esphome/components/danfoss_eco/properties.cpp.o] Error 1 [.pioenvs/esp32-eco2-01/src/esphome/components/danfoss_eco/device.cpp.o] Error 1 ====== [FAILED] Took 9.92 seconds ======

for the following conf (redacted):


esphome: name: esp32-eco2-01 platform: ESP32 board: esp32-poe-iso libraries:

wifi: ssid: "IoT" password: "secretpassword"

logger:

ota: password: "otasecret" id: my_ota

api: reboot_timeout: 1h

external_components:

esp32_ble_tracker:

sensor:

ble_client:

climate:

It seems to be the danfoss_eco platform that bugs, danfoss_eco_scanner compiles perfectly.

hcjehg commented 1 year ago

Solution:


(esphome_py) [esphome@HomeAssistant esphome_py]# diff ./.esphome/external_components/5a2d24b6/components/danfoss_eco ./.esphome/external_components/5a2d24b6.a/components/danfoss_eco
diff ./.esphome/external_components/5a2d24b6/components/danfoss_eco/device.cpp ./.esphome/external_components/5a2d24b6.a/components/danfoss_eco/device.cpp
22c22
<       copy_address(this->parent()->address, this->parent()->remote_bda);
---
>       copy_address(this->parent()->get_address(), this->parent()->get_remote_bda());
99c99
<         if (memcmp(param->connect.remote_bda, this->parent()->remote_bda, 6) != 0)
---
>         if (memcmp(param->connect.remote_bda, this->parent()->get_remote_bda(), 6) != 0)
268c268
<       ESP_LOGD(TAG, "[%s] secret_key bytes: %s", this->get_name().c_str(), hexencode(key, SECRET_KEY_LENGTH).c_str());
---
>       ESP_LOGD(TAG, "[%s] secret_key bytes: %s", this->get_name().c_str(), format_hex_pretty(key, SECRET_KEY_LENGTH).c_str());
diff ./.esphome/external_components/5a2d24b6/components/danfoss_eco/properties.cpp ./.esphome/external_components/5a2d24b6.a/components/danfoss_eco/properties.cpp
29,30c29,30
<             auto status = esp_ble_gattc_read_char(client->gattc_if,
<                                                   client->conn_id,
---
>             auto status = esp_ble_gattc_read_char(client->get_gattc_if(),
>                                                   client->get_conn_id(),
41c41
<             ESP_LOGD(TAG, "[%s] write_request: handle=%#04x, data=%s", this->component_->get_name().c_str(), this->handle, hexencode(data, data_len).c_str());
---
>             ESP_LOGD(TAG, "[%s] write_request: handle=%#04x, data=%s", this->component_->get_name().c_str(), this->handle, format_hex_pretty(data, data_len).c_str());
43,44c43,44
<             auto status = esp_ble_gattc_write_char(client->gattc_if,
<                                                    client->conn_id,
---
>             auto status = esp_ble_gattc_write_char(client->get_gattc_if(),
>                                                    client->get_conn_id(),
172c172
< #endif // USE_ESP32
\ No newline at end of file
---
> #endif // USE_ESP32
ryssel commented 1 year ago

I tried your fix, it compiles but temperatures, Mode: HEAT, Action: HEATING is wrong [14:44:47][D][danfoss_eco:095]: [Bryggers radiator] adaptable_regulation: 1 [14:44:47][D][danfoss_eco:096]: [Bryggers radiator] vertical_intallation: 0 [14:44:47][D][danfoss_eco:097]: [Bryggers radiator] display_flip: 0 [14:44:47][D][danfoss_eco:098]: [Bryggers radiator] slow_regulation: 1 [14:44:47][D][danfoss_eco:099]: [Bryggers radiator] valve_installed: 0 [14:44:47][D][danfoss_eco:100]: [Bryggers radiator] lock_control: 0 [14:44:47][D][danfoss_eco:101]: [Bryggers radiator] temperature_min: 94.5°C [14:44:47][D][danfoss_eco:102]: [Bryggers radiator] temperature_max: 71.5°C [14:44:48][D][danfoss_eco:103]: [Bryggers radiator] frost_protection_temperature: 72.0°C [14:44:48][D][danfoss_eco:104]: [Bryggers radiator] schedule_mode: 3 [14:44:48][D][danfoss_eco:105]: [Bryggers radiator] vacation_temperature: 32.5°C [14:44:48][D][danfoss_eco:106]: [Bryggers radiator] vacation_from: 1846236094 [14:44:48][D][danfoss_eco:107]: [Bryggers radiator] vacation_to: -1200965335 [14:44:48][D][climate:385]: 'Bryggers radiator' - Sending state: [14:44:48][D][climate:388]: Mode: HEAT [14:44:48][D][climate:390]: Action: HEATING [14:44:48][D][climate:408]: Current Temperature: 26.50°C [14:44:48][D][climate:414]: Target Temperature: 97.00°C

trunkenbold71 commented 1 year ago

Same problem here. Compiles, but read values are wrong.

hcjehg commented 1 year ago

For me too, I think the problem is

copy_address(this->parent()->get_address(), this->parent()->get_remote_bda());

Which will of course not work as intended after the change indicated above... (dooh)

Now, how to obtain the same thing...

There is no set_remote_bda in /site-packages/esphome/components/esp32_ble_client/ble_client_base.h

hcjehg commented 1 year ago

It seems the answer might be in using

bool BLEClientBase::parse_device(const espbt::ESPBTDevice &device) { if (device.addressuint64() != this->address) return false; if (this->state_ != espbt::ClientState::IDLE) return false;

ESP_LOGD(TAG, "Found device at MAC address [%s]", device.address_str().c_str()); this->set_state(espbt::ClientState::DISCOVERED);

auto addr = device.address_uint64(); this->remotebda[0] = (addr >> 40) & 0xFF; this->remotebda[1] = (addr >> 32) & 0xFF; this->remotebda[2] = (addr >> 24) & 0xFF; this->remotebda[3] = (addr >> 16) & 0xFF; this->remotebda[4] = (addr >> 8) & 0xFF; this->remotebda[5] = (addr >> 0) & 0xFF; this->remote_addrtype = device.get_address_type(); return true; } found in /src/esphome/components/esp32_ble_client/ble_client_base.cpp

ryssel commented 1 year ago

Are you suggesting there is a bug in /src/esphome/components/esp32_ble_client/ble_client_base.cpp ad if so how do we get on from here?

hcjehg commented 1 year ago

No, I'm suggesting that perhaps danfoss_eco is doing a shortcut (in Device::setup() Copying the address to remote_bda ) that is now no loger possible because ble_client_base has moved members into protected(->remotebda) that were public before(->remote_bda), note that ->remotebda seems to need initialization along with remote_addrtype which makes it sensible to fill in the two with a method instead of via direct access...

hcjehg commented 1 year ago

@ryssel If you do not touch the schedule and mode functions in Home-Assistant, does it then also give messed up results?

I've made a new solution, but i think I was on a wrong lead... Perhaps the function above does actually work... and the messed up results came from somewhere else...

...but mine tilts whenever I touch the schedule function in Home-Assistant (the calendar in the Thermiostat gizmo)... ...and the Mode function too (the flame).

I can change setpoint OK, no problems, that seems to work. It also works if I change the setpoint on the physical thermostat, that will be reflected at the next scan...

When the thermostat tilts I need to go back in with the Danfoss app to get the settings fixed up again... ...and while doing that I need to kill my esphome, or it will try to connect all the time...

@ryssel Does yours run OK if you dont touch the Calendar and Flame ?

It has been running well for 8h now....

I'll try the calendar and flame later on...

hcjehg commented 1 year ago

This works better, but still get's hung up sometimes...

(esphome_py) [esphome@HomeAssistant esphome_py]# ( cd ./.esphome/external_components/ ; diff -x '*.pyc' -x '*.git' -x '*.rej' -r ./5a2d24b6 ./5a2d24b6.b )
diff -x '*.pyc' -x '*.git' -x '*.rej' -r ./5a2d24b6/components/danfoss_eco/device.cpp ./5a2d24b6.b/components/danfoss_eco/device.cpp
3a4,6
> #include "esphome/core/component.h"
> #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
> #include "esphome/core/automation.h"
5,7c8,29
< namespace esphome
< {
<   namespace danfoss_eco
---
>
> namespace esphome {
> namespace esp32_ble_tracker {
>
>     class ESPBTDevice;
>
>     class ESPBTDevice1: public ESPBTDevice
>     {
>         public:
>         void set_address(esp_bd_addr_t address) {
>       this->address_[0]=(unsigned char) (address[0]);
>       this->address_[1]=(unsigned char) (address[1]);
>       this->address_[2]=(unsigned char) (address[2]);
>       this->address_[3]=(unsigned char) (address[3]);
>       this->address_[4]=(unsigned char) (address[4]);
>       this->address_[5]=(unsigned char) (address[5]);
>         };
>
>     };
> } // End of namespace esp32_ble_tracker
>
> namespace danfoss_eco
8a31,32
>     namespace espbt = esphome::esp32_ble_tracker;
>
22c46,50
<       copy_address(this->parent()->address, this->parent()->remote_bda);
---
>       esp_bd_addr_t address;
>       copy_address(this->parent()->get_address(), address);
>       ESPBTDevice1 device;
>       device.set_address(address);
>       this->parent()->parse_device((esphome::esp32_ble_tracker::ESPBTDevice) device);
99c127
<         if (memcmp(param->connect.remote_bda, this->parent()->remote_bda, 6) != 0)
---
>         if (memcmp(param->connect.remote_bda, this->parent()->get_remote_bda(), 6) != 0)
Only in ./5a2d24b6.b/components/danfoss_eco: device.cpp.orig
diff -x '*.pyc' -x '*.git' -x '*.rej' -r ./5a2d24b6/components/danfoss_eco/properties.cpp ./5a2d24b6.b/components/danfoss_eco/properties.cpp
29,30c29,30
<             auto status = esp_ble_gattc_read_char(client->gattc_if,
<                                                   client->conn_id,
---
>             auto status = esp_ble_gattc_read_char(client->get_gattc_if(),
>                                                   client->get_conn_id(),
41c41
<             ESP_LOGD(TAG, "[%s] write_request: handle=%#04x, data=%s", this->component_->get_name().c_str(), this->handle, hexencode(data, data_len).c_str());
---
>             ESP_LOGD(TAG, "[%s] write_request: handle=%#04x, data=%s", this->component_->get_name().c_str(), this->handle, format_hex_pretty(data, data_len).c_str());
43,44c43,44
<             auto status = esp_ble_gattc_write_char(client->gattc_if,
<                                                    client->conn_id,
---
>             auto status = esp_ble_gattc_write_char(client->get_gattc_if(),
>                                                    client->get_conn_id(),
172c172
< #endif // USE_ESP32
\ No newline at end of file
---
> #endif // USE_ESP32
Only in ./5a2d24b6.b/components/danfoss_eco: properties.cpp.orig
hcjehg commented 1 year ago

OK, sometimes the above does not get to disconnect the ble...

trunkenbold71 commented 1 year ago

Anything new on this topic? Is your modification running @hcjehg ? Could you please share the changed file(s)? I tried to change it myself but struggled with the right positions to change the code.

davidtornquist commented 1 year ago

Hi! I was able to solve this as was suggested by previous users The members in class BLEClient are only availble through get/set functions, see documentation: https://esphome.io/api/classesphome_1_1esp32__ble__client_1_1_b_l_e_client_base.html

I replaced the failing members with the corresponding get function ad it worked.

torbensp commented 1 year ago

Hi @davidtornquist!

Can you share the modified files or link to GitHub if you forked the project?. I have similar issues but are no expert in C++ and need a bit of guidance!

Thanks a lot!

davidtornquist commented 1 year ago

Yes @torbensp, certainly! I did not create a fork but downloaded files to run a local component in esphome, see documentation on local folder here: https://esphome.io/components/external_components.html

Attached you have a zip file with the corrected files to replace the existing ones in the "danfoss_eco" folder once you unpacked and copied all the files of the lib to a folder of your choice.

Best Reagards David danfoss_eco.zip

marcin7d commented 1 year ago

@davidtornquist I made your amendment to my esp. If I use one valve everything works fine, but if I use 2 or 3, the system goes crazy. The readings from the thermostats are incorrect and the connection freezes and the thermostats glow red. Do you have any idea?

torbensp commented 1 year ago

@davidtornquist , Thanks a lot! Much appreciated.

Best regards,

Torben

davidtornquist commented 1 year ago

@marcin7d That sounds strange. Unfortunately I don't have any deeper knowledge about the logic of this library, I only did some troubleshooting on the compilation errors. I am only using one thermostat so it works for me. I suggest that you contact the author of te library.

Thanks.

marcin7d commented 1 year ago

@davidtornquist Thank you for your response. Do all the functions work for you? Schedule switch?

davidtornquist commented 1 year ago

@marcin7d I am using home assistant automation to change target temperature and it works fine. What do you mean by schedule switch, scheduling i danfoss eco app?

marcin7d commented 1 year ago

@davidtornquist I mean setting the schedule mode or heating in manual mode

NdS-Research-Facilities commented 1 year ago

Working now

FransOv commented 1 year ago

@marcin7d I also had the situation where the temperatures of two of my thermostats gave wrong very strange results. After much experimenting I found that I had switched the secret keys of those two devices. It turns out that you can communicate with the wrong keys, but of course you do not get the results you expect. I still do have the problem that whenever I change the setting from 'auto' to 'heat' (should be called 'manual' really) in Home Assistant, the thermostat turns the display 180 degrees and switches its mode to not 'installed'. Also changing the set temperature in home assistant is not working correctly.

@davidtornquist Thanks for your changes. Works OK. Only now need to set the reference to never refresh, so the changes are not undone when I recompile.

reinisb commented 1 year ago

@FransOv I'm planning to hook up my two Danfoss Eco valve's to my ESP32 running ESPHome. Before I do that, could you please confirm if esphome-danfoss-eco is not working correctly?

reinisb commented 1 year ago

@dmitry-cherkas could you please comment on the current state of esphome-danfoss-eco? Is it considered working/broken with the latest ESPHome version?

FransOv commented 1 year ago

@reinisb I have 5 Danfoss eco valves connected to two esp32's with this software. You need the changes suggested by @davidtornquist to compile with the latest version of esphome. It works, but the bluetooth connection is critical. Keep distance to 5 meters or less and free of obstructions especially active electronics. Even then it can take several minutes to establish communication. Switching the mode (auto<>heating) does not work, resets the valve. Increasing and decreasing set temperature does work. Program change of the valve is not possible. It is adequate for monitoring but less so for control. Take care in entering the secret key. A typo will not prevent communication but the results will be garbled.

reinisb commented 1 year ago

@FransOv Thanks a lot for the detailed response! Unfortunately, it seems that this will not work for me. My only requirement is to be able to shut down the valve (i.e. set to vacation mode) and turn on the valve (i.e. set to regular schedule mode). I would shut it down when leaving home or when opening window.

reinisb commented 1 year ago

I gave this a shot (forked @davidtornquist change), but compiling fails.

Log

INFO Reading configuration /config/esphome/esp32-devkitc-v4.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing esp32-devkitc-v4 (board: nodemcu-32s; framework: arduino; platform: platformio/espressif32 @ 5.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- xxtea-iot-crypt @ 2.0.1
|-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- Update @ 2.0.0
|-- noise-c @ 0.1.4
|   |-- libsodium @ 1.10018.1
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/api/api_connection.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/api/api_frame_helper.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/api/api_pb2.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/api/api_pb2_service.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/api/api_server.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/api/list_entities.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/api/proto.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/api/subscribe_state.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/api/user_services.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/binary_sensor/automation.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/binary_sensor/binary_sensor.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/ble_client/automation.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/ble_client/ble_client.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/climate/climate.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/climate/climate_mode.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/climate/climate_traits.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/danfoss_eco/device.cpp.o
In file included from src/esphome/components/climate/climate.h:7,
                 from src/esphome/components/danfoss_eco/device.h:4,
                 from src/esphome/components/danfoss_eco/device.cpp:1:
src/esphome/components/danfoss_eco/device.cpp: In member function 'virtual void esphome::danfoss_eco::Device::set_secret_key(uint8_t*, bool)':
src/esphome/components/danfoss_eco/device.cpp:268:108: warning: 'std::__cxx11::string esphome::hexencode(const uint8_t*, uint32_t)' is deprecated: hexencode() is deprecated, use format_hex_pretty() instead. [-Wdeprecated-declarations]
       ESP_LOGD(TAG, "[%s] secret_key bytes: %s", this->get_name().c_str(), hexencode(key, SECRET_KEY_LENGTH).c_str());
                                                                                                            ^
src/esphome/core/log.h:92:89: note: in definition of macro 'esph_log_d'
   esp_log_printf_(ESPHOME_LOG_LEVEL_DEBUG, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
                                                                                         ^~~~~~~~~~~
src/esphome/components/danfoss_eco/device.cpp:268:7: note: in expansion of macro 'ESP_LOGD'
       ESP_LOGD(TAG, "[%s] secret_key bytes: %s", this->get_name().c_str(), hexencode(key, SECRET_KEY_LENGTH).c_str());
       ^~~~~~~~
In file included from src/esphome/core/automation.h:5,
                 from src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h:4,
                 from src/esphome/components/esp32_ble_client/ble_client_base.h:5,
                 from src/esphome/components/ble_client/ble_client.h:3,
                 from src/esphome/components/danfoss_eco/device.h:3,
                 from src/esphome/components/danfoss_eco/device.cpp:1:
src/esphome/core/helpers.h:654:20: note: declared here
 inline std::string hexencode(const uint8_t *data, uint32_t len) { return format_hex_pretty(data, len); }
                    ^~~~~~~~~
In file included from src/esphome/components/climate/climate.h:7,
                 from src/esphome/components/danfoss_eco/device.h:4,
                 from src/esphome/components/danfoss_eco/device.cpp:1:
src/esphome/components/danfoss_eco/device.cpp:268:108: warning: 'std::__cxx11::string esphome::hexencode(const uint8_t*, uint32_t)' is deprecated: hexencode() is deprecated, use format_hex_pretty() instead. [-Wdeprecated-declarations]
       ESP_LOGD(TAG, "[%s] secret_key bytes: %s", this->get_name().c_str(), hexencode(key, SECRET_KEY_LENGTH).c_str());
                                                                                                            ^
src/esphome/core/log.h:92:89: note: in definition of macro 'esph_log_d'
   esp_log_printf_(ESPHOME_LOG_LEVEL_DEBUG, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
                                                                                         ^~~~~~~~~~~
src/esphome/components/danfoss_eco/device.cpp:268:7: note: in expansion of macro 'ESP_LOGD'
       ESP_LOGD(TAG, "[%s] secret_key bytes: %s", this->get_name().c_str(), hexencode(key, SECRET_KEY_LENGTH).c_str());
       ^~~~~~~~
In file included from src/esphome/core/automation.h:5,
                 from src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h:4,
                 from src/esphome/components/esp32_ble_client/ble_client_base.h:5,
                 from src/esphome/components/ble_client/ble_client.h:3,
                 from src/esphome/components/danfoss_eco/device.h:3,
                 from src/esphome/components/danfoss_eco/device.cpp:1:
src/esphome/core/helpers.h:654:20: note: declared here
 inline std::string hexencode(const uint8_t *data, uint32_t len) { return format_hex_pretty(data, len); }
                    ^~~~~~~~~
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/danfoss_eco/helpers.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/danfoss_eco/properties.cpp.o
In file included from src/esphome/components/climate/climate.h:7,
                 from src/esphome/components/danfoss_eco/properties.cpp:1:
src/esphome/components/danfoss_eco/properties.cpp: In member function 'bool esphome::danfoss_eco::WritableProperty::write_request(esphome::ble_client::BLEClient*, uint8_t*, uint16_t)':
src/esphome/components/danfoss_eco/properties.cpp:41:148: warning: 'std::__cxx11::string esphome::hexencode(const uint8_t*, uint32_t)' is deprecated: hexencode() is deprecated, use format_hex_pretty() instead. [-Wdeprecated-declarations]
             ESP_LOGD(TAG, "[%s] write_request: handle=%#04x, data=%s", this->component_->get_name().c_str(), this->handle, hexencode(data, data_len).c_str());
                                                                                                                                                    ^
src/esphome/core/log.h:92:89: note: in definition of macro 'esph_log_d'
   esp_log_printf_(ESPHOME_LOG_LEVEL_DEBUG, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
                                                                                         ^~~~~~~~~~~
src/esphome/components/danfoss_eco/properties.cpp:41:13: note: in expansion of macro 'ESP_LOGD'
             ESP_LOGD(TAG, "[%s] write_request: handle=%#04x, data=%s", this->component_->get_name().c_str(), this->handle, hexencode(data, data_len).c_str());
             ^~~~~~~~
In file included from src/esphome/components/climate/climate.h:5,
                 from src/esphome/components/danfoss_eco/properties.cpp:1:
src/esphome/core/helpers.h:654:20: note: declared here
 inline std::string hexencode(const uint8_t *data, uint32_t len) { return format_hex_pretty(data, len); }
                    ^~~~~~~~~
In file included from src/esphome/components/climate/climate.h:7,
                 from src/esphome/components/danfoss_eco/properties.cpp:1:
src/esphome/components/danfoss_eco/properties.cpp:41:148: warning: 'std::__cxx11::string esphome::hexencode(const uint8_t*, uint32_t)' is deprecated: hexencode() is deprecated, use format_hex_pretty() instead. [-Wdeprecated-declarations]
             ESP_LOGD(TAG, "[%s] write_request: handle=%#04x, data=%s", this->component_->get_name().c_str(), this->handle, hexencode(data, data_len).c_str());
                                                                                                                                                    ^
src/esphome/core/log.h:92:89: note: in definition of macro 'esph_log_d'
   esp_log_printf_(ESPHOME_LOG_LEVEL_DEBUG, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
                                                                                         ^~~~~~~~~~~
src/esphome/components/danfoss_eco/properties.cpp:41:13: note: in expansion of macro 'ESP_LOGD'
             ESP_LOGD(TAG, "[%s] write_request: handle=%#04x, data=%s", this->component_->get_name().c_str(), this->handle, hexencode(data, data_len).c_str());
             ^~~~~~~~
In file included from src/esphome/components/climate/climate.h:5,
                 from src/esphome/components/danfoss_eco/properties.cpp:1:
src/esphome/core/helpers.h:654:20: note: declared here
 inline std::string hexencode(const uint8_t *data, uint32_t len) { return format_hex_pretty(data, len); }
                    ^~~~~~~~~
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/esp32/gpio.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/esp32/preferences.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/esp32_ble_client/ble_characteristic.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/esp32_ble_client/ble_client_base.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/esp32_ble_client/ble_service.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/logger/logger.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/md5/md5.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/mdns/mdns_component.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/mdns/mdns_esp32_arduino.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/mdns/mdns_esp8266.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/mdns/mdns_esp_idf.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/mdns/mdns_rp2040.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/network/util.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/ota/ota_backend_arduino_esp32.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/ota/ota_backend_arduino_esp8266.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/ota/ota_backend_arduino_rp2040.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/ota/ota_backend_esp_idf.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/ota/ota_component.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/sensor/automation.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/sensor/filter.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/sensor/sensor.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/socket/bsd_sockets_impl.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/socket/lwip_raw_tcp_impl.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/socket/socket.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/wifi/wifi_component.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/wifi/wifi_component_esp32_arduino.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/wifi/wifi_component_esp8266.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/wifi/wifi_component_esp_idf.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/components/wifi/wifi_component_pico_w.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/core/application.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/core/component.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/core/component_iterator.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/core/controller.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/core/helpers.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/core/log.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/core/scheduler.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/esphome/core/util.cpp.o
Compiling /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/src/main.cpp.o
Linking /data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/firmware.elf
collect2: fatal error: ld terminated with signal 9 [Killed]
compilation terminated.
*** [/data/esp32-devkitc-v4/.pioenvs/esp32-devkitc-v4/firmware.elf] Error 1
========================= [FAILED] Took 607.45 seconds =========================

Config

esphome:
  name: esp32-devkitc-v4
  libraries:
    - xxtea-iot-crypt@2.0.1

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "ZgYLnUNijfBr6/18vWAgQSuoMUvq/D8VUBAU7XMlnHY="

ota:
  password: "1e189d2f435a4bd37da5a2c7653ba459"

wifi:
  ssid: "Starlink"
  password: "ropazuiela14b16"

# Nodefineju output un fan iekartu prieksh mana Noctua PWM ventilatora    
#output:
#  - platform: ledc
#    pin: 25
#    frequency: 25000 Hz
#    id: pwm_noctua_fan_5v

#fan:
#  - platform: speed
#    output: pwm_noctua_fan_5v
#    name: "Noctua Fan"

external_components:
  - source: github://reinisb/esphome-danfoss-eco-mod@v1.0.0
ble_client:
  - mac_address: 00:04:2f:06:32:18
    id: living_room_danfoss
climate:
  - platform: danfoss_eco
    name: "Living room Danfoss"
    ble_client_id: living_room_danfoss
    battery_level:
      name: "Living room Danfoss Battery Level"
    temperature:
      name: "Living room Danfoss Temperature"
    update_interval: 30min
reinisb commented 1 year ago

Alright, needed to add one more line to config since I'm running HA on Rpi3

https://esphome.io/changelog/2022.11.0.html#running-esphome-on-lower-powered-machines

reinisb commented 1 year ago

@FransOv I'm failing to get the secret key. When I plug my esp32 into power and watch the ESPHome logs it never asks me to press the button on the Eco. Instead, it just connects to Eco and reads its values every 5 minutes as configured. I tried resetting Eco 5 times as well as unplugging/plugging my esp32 into power 100 more times, but I never see the line in the real-time log asking me to press the button.

Any ideas?

[14:42:35][D][danfoss_eco:102]: [Bedroom Danfoss] connect, conn_id=0
[14:42:37][D][danfoss_eco:137]: [Bedroom Danfoss] xxtea is initialized, will not request a read of secret_key
[14:42:37][D][danfoss_eco:149]: [Bedroom Danfoss] writing pin
[14:42:37][D][danfoss_eco:041]: [Bedroom Danfoss] write_request: handle=0x24, data=00.00.00.00
[14:42:37][D][esp32_ble_tracker:327]: Starting scan...
[14:42:37][D][danfoss_eco:196]: [Bedroom Danfoss] pin OK
[14:42:37][D][danfoss_eco:067]: [Bedroom Danfoss] battery level: 27 %
[14:42:37][D][sensor:127]: 'Bedroom Danfoss Battery Level': Sending state 27.00000 % with 0 decimals of accuracy
[14:42:38][D][danfoss_eco:077]: [Bedroom Danfoss] Current room temperature: 23.0°C, Set point temperature: 21.0°C
[14:42:38][D][sensor:127]: 'Bedroom Danfoss Temperature': Sending state 23.00000 °C with 1 decimals of accuracy
[14:42:38][D][climate:385]: 'Bedroom Danfoss' - Sending state:
[14:42:38][D][climate:388]:   Mode: HEAT
[14:42:38][D][climate:390]:   Action: IDLE
[14:42:38][D][climate:408]:   Current Temperature: 23.00°C
[14:42:38][D][climate:414]:   Target Temperature: 21.00°C
[14:42:38][D][danfoss_eco:095]: [Bedroom Danfoss] adaptable_regulation: 0
[14:42:38][D][danfoss_eco:096]: [Bedroom Danfoss] vertical_intallation: 0
[14:42:38][D][danfoss_eco:097]: [Bedroom Danfoss] display_flip: 0
[14:42:38][D][danfoss_eco:098]: [Bedroom Danfoss] slow_regulation: 0
[14:42:38][D][danfoss_eco:099]: [Bedroom Danfoss] valve_installed: 1
[14:42:38][D][danfoss_eco:100]: [Bedroom Danfoss] lock_control: 0
[14:42:38][D][danfoss_eco:101]: [Bedroom Danfoss] temperature_min: 37.5°C
[14:42:39][D][danfoss_eco:102]: [Bedroom Danfoss] temperature_max: 55.0°C
[14:42:39][D][danfoss_eco:103]: [Bedroom Danfoss] frost_protection_temperature: 53.0°C
[14:42:39][D][danfoss_eco:104]: [Bedroom Danfoss] schedule_mode: 3
[14:42:39][D][danfoss_eco:105]: [Bedroom Danfoss] vacation_temperature: 53.5°C
[14:42:39][D][danfoss_eco:106]: [Bedroom Danfoss] vacation_from: 0
[14:42:39][D][danfoss_eco:107]: [Bedroom Danfoss] vacation_to: 0
[14:42:39][D][climate:385]: 'Bedroom Danfoss' - Sending state:
[14:42:39][D][climate:388]:   Mode: HEAT
[14:42:39][D][climate:390]:   Action: IDLE
[14:42:39][D][climate:408]:   Current Temperature: 23.00°C
[14:42:39][D][climate:414]:   Target Temperature: 21.00°C
[14:42:39][D][danfoss_eco:123]: [Bedroom Danfoss] E9_VALVE_DOES_NOT_CLOSE: 0
[14:42:39][D][danfoss_eco:124]: [Bedroom Danfoss] E10_INVALID_TIME: 1
[14:42:39][D][danfoss_eco:125]: [Bedroom Danfoss] E14_LOW_BATTERY: 0
[14:42:40][D][danfoss_eco:126]: [Bedroom Danfoss] E15_VERY_LOW_BATTERY: 0
[14:42:40][I][ble_client:041]: [00:04:2F:06:32:1F] Disabling BLE client.
FransOv commented 1 year ago

@reinisb I had some trouble too not seeing the press button message. Eventually I connected the esp to my pc and checked the log in the output of the serial port of the esp32. The message shows very soon after startup, before the log showed in the browser. I presume it will try again after the update interval has expired, but as you have set this at 30 minutes, that will take a while. Problem is, you have tot take the esp and the valve to your pc or your pc to the valve. The log output of the bedroom Danfoss seems OK though. Were you able to read the secret key from that valve?

reinisb commented 1 year ago

That worked - thank you! That being said - this really messes up the Eco - it is not possible to set temperature on the physical Eco thermostat any longer, and frequently it would suddenly start heating to 60 C degrees.

FransOv commented 1 year ago

That is not my experience. You can set the temperature either manually or via Home Assistant, only not while the esp is communicating with the valve. Via HA it is a bit tedious as you have to increase the temp by half a degree, wait until the valve is updated and the updated value is returned and only then increase the temp by half a degree again. Manually adjusting the temp is no problem. If the problem persists it might help to reset the eco back to factory settings (keep the button pressed while you insert the batteries). You of course then have to enter the day/week program again in the Danfoss app. Your problem could also be caused by poor bluetooth connectivity.

dmitry-cherkas commented 1 year ago

Hey @FransOv, @reinisb, @davidtornquist, as pointed out in https://github.com/dmitry-cherkas/esphome-danfoss-eco/issues/12, it seem the xxtea-iot-crypt is no longer publicly available and I can't seem to find anywhere. Do you have it in your local build cache by any chance?

this really messes up the Eco

Seems like there is a bug with the component, intermittently it looses the internal state and writes garbage to the Eco, resulting in the behavior you've described. Unfortunately I no longer hold the device, so won't be able to investigate/troubleshoot. Contributions are welcome!

dmitry-cherkas commented 1 year ago

it seem the xxtea-iot-crypt is no longer publicly available and I can't seem to find anywhere

hm.. let me take it back, I was actually able to fetch it from PlatformIO, once I've updated to the latest version.

dmitry-cherkas commented 1 year ago

I've incorporated your changes into a v1.1.3 release of the component. Thanks for the contribution!

FransOv commented 1 year ago

I tested the new version. Compiles without errors and first impression is that it works OK. Thanks.

reinisb commented 1 year ago

Same here - the new version compiled without any errors and seems to work fine. Thank you @dmitry-cherkas

dmitry-cherkas commented 1 year ago

thanks for the feedback! looks like we can consider this one closed