geoffdavis / esphome-mitsubishiheatpump

ESPHome Climate Component for Mitsubishi Heatpumps using direct serial connection
BSD 2-Clause "Simplified" License
582 stars 157 forks source link

how to set control over fan speed from web server? #138

Open Grappa2020 opened 9 months ago

BenJamesAndo commented 9 months ago

I got it working by using code from the Midea ESPHome YAML.

sensor:
  - platform: template
    name: ${friendly_node_name} fan mode
    id: ${node_id}_fan_mode
    internal: true
    update_interval: 10s
    lambda: !lambda |-
      if (id(${node_id}_my_climate).fan_mode == 2)
      {
        if (id(${node_id}_select_fan_mode).state != "Auto")
        {
          auto call = id(${node_id}_select_fan_mode).make_call();
          call.set_option("Auto");
          call.perform();
        }
      }
      else if (id(${node_id}_my_climate).fan_mode == 3)
      {
        if (id(${node_id}_select_fan_mode).state != "Low")
        {
          auto call = id(${node_id}_select_fan_mode).make_call();
          call.set_option("Low");
          call.perform();
        }
      }
      else if (id(${node_id}_my_climate).fan_mode == 4)
      {
        if (id(${node_id}_select_fan_mode).state != "Medium")
        {
          auto call = id(${node_id}_select_fan_mode).make_call();
          call.set_option("Medium");
          call.perform();
        }
      }
      else if (id(${node_id}_my_climate).fan_mode == 5)
      {
        if (id(${node_id}_select_fan_mode).state != "High")
        {
          auto call = id(${node_id}_select_fan_mode).make_call();
          call.set_option("High");
          call.perform();
        }
      }
      return id(${node_id}_my_climate).fan_mode;

# Select
select:
  - platform: template
    name: "Fan mode"
    id: ${node_id}_select_fan_mode
    icon: mdi:fan
    optimistic: true
    options:
      - Auto
      - Low
      - Medium
      - High
    on_value:
      then:
        - lambda: |-
            auto call = id(${node_id}_my_climate).make_call();
            call.set_fan_mode(x.c_str());
            call.perform();

I need to tidy it up first as I had to also add/change the following to get it to work.

substitutions:
  node_name: mideahvac # Use a unique name.
  node_id: midea_ac    # Use a unique id.
  friendly_node_name: "Midea AC"
climate:
    id: ${node_id}_my_climate   # Use a unique id
    name: ${node_name}  
RikBast commented 8 months ago

I tried this, but no luck. A whole lot of messages when flashing to the board. There is no error in the config. but running the flash generates this error:

Leaving... Hard resetting via RTS pin... INFO Successfully uploaded program. INFO Starting log output from /dev/cu.usbserial-02M3J84W with baud rate 115200 [19:29:41][I][logger:351]: Log initialized [19:29:41][C][ota:473]: There have been 0 suspected unsuccessful boot attempts. [19:29:41][D][esp32.preferences:114]: Saving 1 preferences to flash... [19:29:41][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed [19:29:41][D][MitsubishiHeatPump:620]: Ping request received [19:29:41][I][app:029]: Running through setup()... [19:29:41][D][template.select:014]: Setting up Template Select [19:29:41][D][template.select:017]: State from initial: Auto [19:29:41][D][select:015]: 'Fan mode': Sending state Auto (index 0) [19:29:41][D][climate:011]: 'mideahvac' - Setting [19:29:41][D][climate:024]: Fan: AUTO [19:29:41]Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. [19:29:41] [19:29:41]Core 1 register dump: [19:29:41]PC : 0x400f0835 PS : 0x00060e30 A0 : 0x800f08b9 A1 : 0x3ffb2220
WARNING Decoded 0x400f0835: HeatPump::lookupByteMapIndex(char const*, int, char const) at /Users/rikbastiaens/Documents/ESPHome/.esphome/build/mitsubishi-slaapkamer/.piolibdeps/mitsubishi-slaapkamer/HeatPump/src/HeatPump.cpp:455 [19:29:41]A2 : 0x00000000 A3 : 0x9f31c0cd A4 : 0x00000006 A5 : 0x3f408a76
[19:29:41]A6 : 0x00000000 A7 : 0x00000000 A8 : 0x9f31c0cd A9 : 0x3ffb21a0
[19:29:41]A10 : 0x0003ad10 A11 : 0x00000028 A12 : 0x0000006d A13 : 0x00000028
[19:29:41]A14 : 0x3f4035ca A15 : 0x00000010 SAR : 0x00000004 EXCCAUSE: 0x0000001c
[19:29:41]EXCVADDR: 0x9f31c0cd LBEG : 0x40089965 LEND : 0x40089975 LCOUNT : 0xfffffff5
[19:29:41] [19:29:41] [19:29:41]Backtrace:0x400f0832:0x3ffb22200x400f08b6:0x3ffb2240 0x400dc681:0x3ffb2260 0x400dc76c:0x3ffb2280 0x400d9e51:0x3ffb22a0 0x400e7e0b:0x3ffb22c0 0x400e7984:0x3ffb2380 0x400e7889:0x3ffb23c0 0x400e7830:0x3ffb2420 0x400de6bc:0x3ffb24b0 0x400df571:0x3ffb2530 0x400df5b6:0x3ffb2590 0x400e63c4:0x3ffb25b0 0x4017019d:0x3ffb25d0 0x400e5fe4:0x3ffb25f0 0x400e8a7a:0x3ffb2620 0x400f3ada:0x3ffb2820

sebi5361 commented 2 months ago

I had the same experience with that config file... I have narrowed the problem down to that specific command line: call.set_fan_mode(x.c_str()); When added in the config file, my ESP8266 crashes. Here is the log:

[17:33:40][V][control:345]: Requested fan mode is AUTO
[17:33:40]Fatal exception 28(LoadProhibitedCause):
[17:33:41]epc1=0x4023aff6, epc2=0x00000000, epc3=0x00000000, excvaddr=0x000000c0, depc=0x00000000
WARNING Decoded 0x4023aff6: HeatPump::lookupByteMapIndex(char const**, int, char const*)
[17:33:41]
[17:33:41]--------------- CUT HERE FOR EXCEPTION DECODER ---------------
[17:33:41]
[17:33:41]Exception (28):
WARNING Exception type: Access to invalid address: LOAD (wild pointer?)
[17:33:41]epc1=0x4023aff6 epc2=0x00000000 epc3=0x00000000 excvaddr=0x000000c0 depc=0x00000000
WARNING Decoded 0x4023aff6: HeatPump::lookupByteMapIndex(char const**, int, char const*)
[17:33:42]
[17:33:42]>>>stack>>>
WARNING Found stack trace! Trying to decode it
[17:33:42]
[17:33:42]ctx: cont
[17:33:42]sp: 3ffffb40 end: 3fffffd0 offset: 0150
[17:33:42]3ffffc90:  00000000 3ffeb9fb 3ffffd00 00000001  
[17:33:42]3ffffca0:  00000000 3ffffd00 00000000 4023b0a8  
WARNING Decoded 0x4023b0a8: HeatPump::setFanSpeed(char const*)
[17:33:42]3ffffcb0:  3ffffcd0 3ffffcc0 3fff4df4 4021dc89  
WARNING Decoded 0x4021dc89: MitsubishiHeatPump::control(esphome::climate::ClimateCall const&)
[17:33:43]3ffffcc0:  00000000 3ffffd68 3ffffd00 40218ee3  
WARNING Decoded 0x40218ee3: esphome::climate::ClimateCall::set_fan_mode(std::__cxx11::basic_string<char, std::char_    _traits<char>, std::allocator<char> > const&)
[17:33:43]3ffffcd0:  00000000 00000074 00004e4f 3fff3aff  
[17:33:43]3ffffce0:  00000000 3ffeb9fb 3ffffd00 4022d23c  
WARNING Decoded 0x4022d23c: esphome::LambdaAction<std::__cxx11::basic_string<char, std::char_traits<char>, std::all    locator<char> >, unsigned int>::play(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)
[17:33:43]3ffffcf0:  3ffffe30 00000000 3fff598c 4022d386  
WARNING Decoded 0x4022d386: std::_Function_handler<void (std::__cxx11::basic_string<char, std::char_traits<char>, s    std::allocator<char> >, unsigned int), setup::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)#1}>::_M_invoke(std::_Any_data const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned int&&) at main.cpp
[17:33:43]3ffffd00:  3fff4e08 3ffffe00 00000000 4024b6e1  
WARNING Decoded 0x4024b6e1: _vsnprintf_r at /workdir/repo/newlib/newlib/libc/stdio/vsnprintf.c:71 (discriminator 4)    )
[17:33:44]3ffffd10:  3ffffe00 3ffffe70 00000000 00000001  
[17:33:44]3ffffd20:  00000000 000001dc 00000201 ffffff00  
[17:33:44]3ffffd30:  3ffffd38 00000000 00000000 3ffeb1af  
[17:33:44]3ffffd40:  00000005 3ffe83c4 00000100 4024b600  
WARNING Decoded 0x4024b600: __utoa at /workdir/repo/newlib/newlib/libc/stdlib/utoa.c:42
[17:33:44]3ffffd50:  3ffffd58 00000000 00000100 ffff0208  
[17:33:45]3ffffd60:  3fff3ad7 000001c4 3ffffd70 00000004 <
[17:33:45]3ffffd70:  6f747541 00000000 3ffe867c 00000002  
[17:33:45]3ffffd80:  3ffffd88 00000004 6f747541 3ffeb100  
[17:33:45]3ffffd90:  00000004 00000044 3ffebce3 40241764  
WARNING Decoded 0x40241764: uart_write
[17:33:46]3ffffda0:  3ffffe30 00000000 3fff598c 4022d268  
WARNING Decoded 0x4022d268: esphome::LambdaAction<std::__cxx11::basic_string<char, std::char_traits<char>, std::all    locator<char> >, unsigned int>::play(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)
[17:33:46]3ffffdb0:  3ffffdb8 00000000 6f747500 3ffeb100  
[17:33:46]3ffffdc0:  00000004 00000044 00000000 4023dc90  
WARNING Decoded 0x4023dc90: Print::println(char const*)
[17:33:46]3ffffdd0:  3ffffe30 00000000 3fff598c 4022d1ad  
WARNING Decoded 0x4022d1ad: esphome::Action<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator    r<char> >, unsigned int>::play_complex(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)
[17:33:46]3ffffde0:  3ffffde8 00000004 6f747541 40101000  
WARNING Decoded 0x40101000: check_poison$constprop$0 at umm_malloc.cpp
[17:33:47]3ffffdf0:  3ffeb1af 3fff4198 3ffeaf2b 4021b924  
WARNING Decoded 0x4021b924: esphome::logger::Logger::vprintf_to_buffer_(char const*, __va_list_tag)
[17:33:47]3ffffe00:  3ffffe80 3ffffe70 00000010 3ffeb1af  
[17:33:47]3ffffe10:  00000004 00000000 3fff3a44 3ffeb1af  
[17:33:47]3ffffe20:  00000000 4022d17c 3fff598c 4022d150  
WARNING Decoded 0x4022d17c: esphome::Action<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator    r<char> >, unsigned int>::play_complex(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)
WARNING Decoded 0x4022d150: std::_Function_handler<void (std::__cxx11::basic_string<char, std::char_traits<char>, s    std::allocator<char> >, unsigned int), esphome::select::SelectStateTrigger::SelectStateTrigger(esphome::select::Select*)::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)#1}>::_M_invoke(std::_Any_data const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned int&&)
[17:33:47]3ffffe30:  3ffffe38 00000004 6f747541 3ffeb100  
[17:33:48]3ffffe40:  00000L\xf8\xe8\xb2\xaf

Any idea on how to solve this?


EDIT: I switched to Eric Chavet's MitsubishiCN105ESPHome integration and controlling the fan speed works out of the box with no additional line of code.