Daikin Madoka BRC1H bluetooth custom component

hi @Petapton , I will try your sample ESPHome configuration. Just got one sample unit to play with during weekend. Sorry for the dumb question, but dont we need to pair the esp32 with the madoka controller first? How do we do that?

Yes, I set the integration to display the pairing code, but it basically trusts anything (it could be improved, but for a first proof of concept it is enough). You just have to confirm pairing from the madoka unit and it should go.
Please note that I had some troubles in testing with the device reporting successful pairing but being unable to communicate. This seems to be due to the fact that ESP32 saves past pairing info into flash and they survive firmware flashing. So if you get such an error, please try esptool.py erase_flash before flashing the firmware.

1 Like

yes it worked, but I get crash loop. I sent you a direct message to debug.

Your project of an esphome component for Madoka remotes is very interesting. What are you able to manage at the moment with it?

UPDATE: Iā€™ve tested it on a ESP32 and it works very well! The only missing feature is the fan speed management. Great work!

It went in bootloop trying to build under esp-ids framework. It worked switching on arduino one.

Where is this repo? For some reason I cant find it on github.

Mine is still crashing. :frowning: Maybe itā€™s got to do with my Madoka, it seems somehow I have two setpoints while I shall have only one (or vice versa). My AC is cooling only.

[22:28:26][D][madoka:147]: Got update requestā€¦
[22:28:27][D][climate:392]: ā€˜Living Room ACā€™ - Sending state:
[22:28:27][D][climate:395]: Mode: FAN_ONLY
[22:28:27][D][climate:415]: Current Temperature: nanĀ°C
[22:28:27][D][climate:419]: Target Temperature: Low: 0.00Ā°C High: 0.00Ā°C
[22:28:27]Guru Meditation Error: Core 1 panicā€™ed (LoadProhibited). Exception was unhandled.

This line 318 in madoka.cpp is making it crash:
this->target_temperature_low = (float) (val[0] << 8 | val[1]) / 128;

This chunk also seems to be related:

  if (validate_buffer(msg)) {
    this->chunks.clear();
    this->parse_cb(msg);
  }

and this:

      chunk chk = chunk(param->notify.value, param->notify.value + param->notify.value_len);
      // ESP_LOGD(TAG, "Start process_incoming_chunk");
      this->process_incoming_chunk(chk);

Anyway, full output for the crash is here:

[22:28:26][D][madoka:147]: Got update requestā€¦
[22:28:27][D][climate:392]: ā€˜Living Room ACā€™ - Sending state:
[22:28:27][D][climate:395]: Mode: FAN_ONLY
[22:28:27][D][climate:415]: Current Temperature: nanĀ°C
[22:28:27][D][climate:419]: Target Temperature: Low: 0.00Ā°C High: 0.00Ā°C
[22:28:27]Guru Meditation Error: Core 1 panicā€™ed (LoadProhibited). Exception was unhandled.
[22:28:27]
[22:28:27]Core 1 register dump:
[22:28:27]PC : 0x400dc4ea PS : 0x00060730 A0 : 0x800dc75f A1 : 0x3ffcd250
WARNING Decoded 0x400dc4ea: esphome::madoka::Madoka::parse_cb(std::vector<unsigned char, std::allocator >) at /home/emre/Apps/esphome/.esphome/build/livingroom/src/esphome/components/madoka/madoka.cpp:318
[22:28:27]A2 : 0x3ffbca28 A3 : 0x3ffcd2c4 A4 : 0x00000021 A5 : 0x00000084
[22:28:27]A6 : 0x00000013 A7 : 0x00000000 A8 : 0x800dc4e7 A9 : 0x00000000
[22:28:27]A10 : 0x3ffcd264 A11 : 0x3fff3eb7 A12 : 0x3fff3eb7 A13 : 0x00000000
[22:28:27]A14 : 0x3fff22a0 A15 : 0x3fff228e SAR : 0x0000001c EXCCAUSE: 0x0000001c
[22:28:27]EXCVADDR: 0x00000001 LBEG : 0x4009094c LEND : 0x40090957 LCOUNT : 0x00000000
[22:28:27]
[22:28:27]
[22:28:27]Backtrace:0x400dc4e7:0x3ffcd2500x400dc75c:0x3ffcd290 0x400dc837:0x3ffcd2f0 0x400dc85a:0x3ffcd330 0x4
00d7b8e:0x3ffcd350 0x401ee891:0x3ffcd380 0x400da6a5:0x3ffcd3a0 0x401ee859:0x3ffcd3c0 0x400d96b1:0x3ffcd3e0 0x4
01eeb21:0x3ffcd400 0x401eebe1:0x3ffcd420 0x400e1484:0x3ffcd440 0x400e360e:0x3ffcd470 0x400e7cb1:0x3ffcd490
WARNING Found stack trace! Trying to decode it
WARNING Decoded 0x400dc4e7: esphome::madoka::Madoka::parse_cb(std::vector<unsigned char, std::allocator >) at /home/emre/Apps/esphome/.esphome/build/livingroom/src/esphome/components/madoka/madoka.cpp:318
WARNING Decoded 0x400dc75c: esphome::madoka::Madoka::process_incoming_chunk(std::vector<unsigned char, std::al
locator >) at /home/emre/Apps/esphome/.esphome/build/livingroom/src/esphome/components/madoka/m
adoka.cpp:191
WARNING Decoded 0x400dc837: esphome::madoka::Madoka::gattc_event_handler(esp_gattc_cb_event_t, unsigned char,
esp_ble_gattc_cb_param_t*) at /home/emre/Apps/esphome/.esphome/build/livingroom/src/esphome/components/madoka/
madoka.cpp:137
WARNING Decoded 0x400dc85a: non-virtual thunk to esphome::madoka::Madoka::gattc_event_handler(esp_gattc_cb_eve
nt_t, unsigned char, esp_ble_gattc_cb_param_t*)
WARNING Decoded 0x400d7b8e: esphome::ble_client::BLEClient::gattc_event_handler(esp_gattc_cb_event_t, unsigned
char, esp_ble_gattc_cb_param_t*) at /home/emre/Apps/esphome/.esphome/build/livingroom/src/esphome/components/
ble_client/ble_client.cpp:58 (discriminator 2)
WARNING Decoded 0x401ee891: esphome::esp32_ble_tracker::ESP32BLETracker::gattc_event_handler(esp_gattc_cb_even
t_t, unsigned char, esp_ble_gattc_cb_param_t*) at /home/emre/Apps/esphome/.esphome/build/livingroom/src/esphom
e/components/esp32_ble_tracker/esp32_ble_tracker.cpp:346 (discriminator 2)
WARNING Decoded 0x400da6a5: non-virtual thunk to esphome::esp32_ble_tracker::ESP32BLETracker::gattc_event_hand
ler(esp_gattc_cb_event_t, unsigned char, esp_ble_gattc_cb_param_t*)
WARNING Decoded 0x401ee859: esphome::esp32_ble::ESP32BLE::real_gattc_event_handler_(esp_gattc_cb_event_t, unsi
gned char, esp_ble_gattc_cb_param_t*) at /home/emre/Apps/esphome/.esphome/build/livingroom/src/esphome/compone
nts/esp32_ble/ble.cpp:208 (discriminator 2)
WARNING Decoded 0x400d96b1: esphome::esp32_ble::ESP32BLE::loop() at /home/emre/Apps/esphome/.esphome/build/liv
ingroom/src/esphome/components/esp32_ble/ble.cpp:158
WARNING Decoded 0x401eeb21: esphome::Component::call_loop() at /home/emre/Apps/esphome/.esphome/build/livingro
om/src/esphome/core/component.cpp:76
WARNING Decoded 0x401eebe1: esphome::Component::call() at /home/emre/Apps/esphome/.esphome/build/livingroom/sr
c/esphome/core/component.cpp:98
WARNING Decoded 0x400e1484: esphome::Application::loop() at /home/emre/Apps/esphome/.esphome/build/livingroom/
src/esphome/core/application.cpp:74 (discriminator 2)
WARNING Decoded 0x400e360e: loop() at /home/emre/Apps/esphome/.esphome/build/livingroom/src/main.cpp:205
WARNING Decoded 0x400e7cb1: loopTask(void*) at /home/emre/.platformio/packages/framework-arduinoespressif32/co
res/esp32/main.cpp:50

The repo is here: GitHub - Petapton/esphome at madoka but it can be automatically included in the build using the suggested stanza:

external_components:
  - source: github://Petapton/esphome@madoka
    components: [ madoka, esp32_ble ]

You could try to alter the climate component declaration (see Add Daikin Madoka Component. Ā· esphome/esphome@64b05d8 Ā· GitHub). It probably fails trying to get the two setpoints of your Madoka remote (as it provides just one). You could also try to revert the Madoka remote to use two setpoints by means of the advanced settings in the mobile app (pairing the app again): I know it is necessary to switch on ā€œone setpoint modeā€ if you want to use the daikin wifi adapter; I guess it is possible to do the opposite.

Iā€™m wondering if @Petapton is still interested in working on his own componentā€¦ :frowning:

Its amazing! I tried it and it works well with 1 Madoka unit. If i add second one it was like very unstable.
I used ESP32-WROVER 240 MHz 328 kB (small ram?) for that. I have also noticed that after some time it stops sending information about state and in HA it looks like disconnected, but if i switching the state on HA component wakes up. But after night it disconnect completely and switch the state on component doesnā€™t help

I tested the component on an OLIMEX ESP32-POE with just one remote: it is perfectly stable. HA never looses the connection. Iā€™ve not tried with multiple remotes (but I will do as I got 4 remotes). It could be related to some kind of race-condition but I would start using another unit.

I ordered also Olimex Poe. Maybe this will solve my issue with connection. I found out that the Bluetooth on my board has problem to connect via closed door on 3m distance. Interesting due other devices are able to communicate on much bigger range. Maybe itā€™s standard Iam newbie in esp32

Hello, you could try to switch to the esp-idf framework. As for this page (red box), it should be much more stable.

The ESP32 Platform component should be configured to use the esp-idf framework, as the arduino framework uses significantly more memory and performs poorly with the Bluetooth proxy enabled. When switching from arduino to esp-idf, make sure to update the device with a serial cable as the partition table is different between the two frameworks as OTA Update Component updates will not change the partition table.

Iā€™ve been unable to get this to work, either from pymadoka or the custom_component. I can get the controller and thermostat to pair, and connect (the light ring turns green), but then things hang. Iā€™ve tried with multiple controllers, and bluetooth dongles, but no luck. The most specific thing Iā€™ve seen, trying to run pymadoka-mqtt, is that there doesnā€™t appear to be a response querying characteristics (see logs below). I also get hangs just trying to query specific values using pymadoka cli. Does anyone have any tips on how/where to debug this further?

2023-04-24 12:23:54,818 - pymadoka.connection:153 - DEBUG - Starting connection manager on C8:D8:84:F1:D3:BF
2023-04-24 12:23:54,819 - bleak.backends.bluezdbus.client:95 - DEBUG - Connecting to device @ C8:D8:84:F1:D3:BF
2023-04-24 12:23:54,831 - bleak.backends.bluezdbus.client:170 - DEBUG - Connecting to BlueZ path /org/bluez/hci1/dev_C8_D8_84_F1_D3_BF
2023-04-24 12:23:54,992 - bleak.backends.bluezdbus.manager:716 - DEBUG - received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci1/dev_C8_D8_84_F1_D3_BF): ['org.bluez.Device1', {'Connected': <dbus_fast.signature.Variant ('b', True)>}, []]
2023-04-24 12:23:55,749 - bleak.backends.bluezdbus.manager:716 - DEBUG - received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci1/dev_C8_D8_84_F1_D3_BF): ['org.bluez.Device1', {'Name': <dbus_fast.signature.Variant ('s', UE878 RF MODULE)>, 'Alias': <dbus_fast.signature.Variant ('s', UE878 RF MODULE)>}, []]
2023-04-24 12:23:56,309 - bleak.backends.bluezdbus.manager:716 - DEBUG - received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci1/dev_C8_D8_84_F1_D3_BF): ['org.bluez.Device1', {'ServicesResolved': <dbus_fast.signature.Variant ('b', True)>}, []]
2023-04-24 12:23:56,311 - pymadoka.connection:174 - INFO - Connected to C8:D8:84:F1:D3:BF
2023-04-24 12:23:56,450 - bleak.backends.bluezdbus.manager:716 - DEBUG - received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci1/dev_C8_D8_84_F1_D3_BF/service0200/char0201): ['org.bluez.GattCharacteristic1', {'Notifying': <dbus_fast.signature.Variant ('b', True)>}, []]
2023-04-24 12:23:58,454 - pymadoka.controller:74 - INFO - Calling controller.update
2023-04-24 12:23:58,756 - pymadoka.controller:80 - INFO - Getting FanSpeed
2023-04-24 12:23:58,756 - pymadoka.feature:178 - INFO - Querying Feature 
2023-04-24 12:23:58,757 - pymadoka.connection:245 - DEBUG - Sending cmd: 80 payload: 0a000050200100210100
2023-04-24 12:23:58,761 - bleak.backends.bluezdbus.client:823 - DEBUG - Write Characteristic 2141e112-213a-11e6-b67b-9e71128cae77 | /org/bluez/hci1/dev_C8_D8_84_F1_D3_BF/service0200/char0204: bytearray(b'\x00\n\x00\x00P \x01\x00!\x01\x00')
2023-04-24 12:23:58,761 - pymadoka.connection:259 - DEBUG - CMD 80. Chunk #1/1 sent with size 11 bytes
2023-04-24 12:25:14,251 - __main__:351 - DEBUG - Disconnected from MQTT broker (7)
2023-04-24 12:25:14,252 - __main__:360 - DEBUG - Reconnecting in 60s...
2023-04-24 12:26:14,320 - __main__:345 - DEBUG - Connected to MQTT broker

@mduran80 Hi. After I have disconnected the Madoka from my iPhone app and paried it with the bluetooth in HA, can I then connect it again with the app on my phone? I mean, can I both have the app on my phone and in HA?

Works great!
thanks for this.
One thing i couldnt get working - temp change only works for lowering (e.g. setting a lower temp the current), not for raising the temp

10x

Thanks @Petapton for your work.

With the Release 2023.6.1 of ESPhome there is an error during compiling. But if you remove esp32_ble from the components it work again.

How it is possible to integrate that in the official ESPhome?

2 Likes

Do we know if this would work with the ERV (Daikin VAM) that is connected to a BRC1H Madoka?

Does that mean that the customization in esp_ble is not required anymoreā€¦ this would be a good newsā€¦

Hello, I just found this new way to add Madoka to HA, great, but I receive this error message when compiling:

INFO ESPHome 2023.6.2
INFO Reading configuration /config/esphome/ttgo.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing ttgo (board: esp32dev; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 1.2.2
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 2.1.0
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- noise-c @ 0.1.4
|-- ArduinoJson @ 6.18.5
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/api/api_connection.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/api/api_frame_helper.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/api/api_pb2.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/api/api_pb2_service.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/api/api_server.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/api/list_entities.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/api/proto.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/api/subscribe_state.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/api/user_services.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/binary_sensor/automation.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/binary_sensor/binary_sensor.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/binary_sensor/filter.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/ble_client/automation.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/ble_client/ble_client.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/ble_presence/ble_presence_device.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/captive_portal/captive_portal.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/climate/climate.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/climate/climate_mode.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/climate/climate_traits.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/esp32/gpio.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/esp32/preferences.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/esp32_ble/ble.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/esp32_ble/ble_advertising.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/esp32_ble/ble_uuid.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/esp32_ble_client/ble_characteristic.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/esp32_ble_client/ble_client_base.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/esp32_ble_client/ble_service.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/json/json_util.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/logger/logger.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/madoka/madoka.cpp.o
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/md5/md5.cpp.o
src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp: In member function 'uint64_t esphome::esp32_ble_tracker::ESPBTDevice::address_uint64() const':
src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp:587:66: error: 'ble_addr_to_uint64' is not a member of 'esphome::esp32_ble'
 uint64_t ESPBTDevice::address_uint64() const { return esp32_ble::ble_addr_to_uint64(this->address_); }
                                                                  ^~~~~~~~~~~~~~~~~~
Compiling /data/ttgo/.pioenvs/ttgo/src/esphome/components/mdns/mdns_component.cpp.o
*** [/data/ttgo/.pioenvs/ttgo/src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp.o] Error 1
========================= [FAILED] Took 21.21 seconds =========================

Any help will be appreciated.