Daikin Madoka BRC1H bluetooth custom component

4 Madoka connected and functional - It has been very difficult (More than 5 hours with all type of issues)
I recommend the following
0 - Once Devices are Paired, before Integration with Custom component
1 - All Madoka are using the same alias, hence it is disconnected. It is useful to rename the device via
bluetoothctl , (power off, power on, devices)
connect <mac>
set-alias <alias>

TIPS 1 - Using Putty better than Terminal H ( possible to Copy/paste of MAC address with Putty )
TIPS 2 - Prepare a note with all MAC and Alias + sequence with bluetoothctl, power on, off, scan off, trust, pair

Hi all,
after 2 or 3 hours or good functioning, the Bluetoothctl is no longer responding.
Error Message :
“Waiting to connect to bluetoothd…dbus[207]: arguments to dbus_connection_get_object_path_data() were incorrect, assertion “connection != NULL” failed in file dbus-connection.c line 5921.
This is normally a bug in some application using the D-Bus library.”

Any advice ? Thank you guys

Has anyone successfully used an ESP32, bluetooth proxy and a component to control a Madoka unit?

From BLE Client — ESPHome

This component does not (yet) support devices that require security settings (eg connecting with a PIN).

I suspect this rules out using esphome and bluetooth proxying to pair to and control the Madoka BRC1H. If anyone’s found a workaround, please let me know.

I think the only workaround could be using esp32 as a ble2mqtt bridge, and then manually defining a climate device in home assistant.

Hello everyone.
I finally wrote a madoka component for ESPHome. It’s still in a pre-early stage (code has to be re-styled and organized), but it works. If anybody wants to try it out, here’s a sample ESPHome configuration to make it work.

...

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

esp32_ble_tracker:

ble_client:
  - mac_address: <mac_address>
    id: madoka_climate

climate:
  - platform: madoka
    name: "Madoka Climate"
    ble_client_id: madoka_climate
    update_interval: 15s

...

Any feedback and contribution is greatly appreciated.

3 Likes

Hi, just started to use the custom component. But which one is the most updated now, it seems this one, right?

GitHub - mduran80/daikin_madoka: Home Assistant custom component integration for the BRC1H thermostat (madoka)

Now, the component is working and I was able to connect to my thermostat. But after some time, I’m losing connection and then the home-asisstant console is flooded with these messages:

homeassistant | 2023-03-17 15:38:17.653 ERROR (MainThread) [pymadoka.connection] [org.bluez.Error.Failed] br-connection-canceled
homeassistant | 2023-03-17 15:38:19.660 ERROR (MainThread) [pymadoka.connection] [org.bluez.Error.Failed] Operation already in progress

At this point, if I restart home-assistant, connection is restored.

Is this expected or am I hitting a bug due to maybe bluetooth connection instability?

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.