Closed drogfild closed 3 years ago
The HA Esphome api will disconnect if any invalid states are send through, you can check this by increasing the logging
logs:
aioesphomeapi: debug
It will show something like
2021-04-27 06:38:44 DEBUG (MainThread) [aioesphomeapi.connection] heatpump.local: Got message of type <class 'api_pb2.ClimateStateResponse'>: key: 4281390649
current_temperature: nan
target_temperature: -1.6947395e+38
fan_mode: 254
swing_mode: 254
2021-04-27 06:38:44 INFO (MainThread) [aioesphomeapi.connection] heatpump.local: Unexpected error while reading incoming messages: 254 is not a valid ClimateFanMode
2021-04-27 06:38:44 DEBUG (MainThread) [aioesphomeapi.connection] heatpump.local: Closed socket
I resolved this by initialising those on setup. It is trying to publish the state before the first SwiCago/HeatPump callback.
diff --git a/espmhp.cpp b/espmhp.cpp
index e3a217d..0ba46bb 100644
--- a/espmhp.cpp
+++ b/espmhp.cpp
@@ -412,6 +412,10 @@ void MitsubishiHeatPump::setup() {
ESP_LOGCONFIG(TAG, "Intializing new HeatPump object.");
this->hp = new HeatPump();
+ this->current_temperature = 16;
+ this->target_temperature = 16;
+ this->fan_mode = climate::CLIMATE_FAN_OFF;
+ this->swing_mode = climate::CLIMATE_SWING_OFF;
#ifdef USE_CALLBACKS
hp->setSettingsChangedCallback(
@thompsa, how do you go about making the above change? I am new to HA and ESPHOME, only discovering them by reference from this repo. I am using ESP32 D1 mini clones from Aliexpress for my 4 new aircon units. I thought I would practice generating my ESP32 boards before I get them connected as I am waiting for delivery of the CN105 connectors. Esphome seems to build and install fine but I get constant immediate disconnects/connects to HA, probably due to the issue you point out just above. If I change the source file in my build dir then it gets regenerated when I do a compile. If I git clone
this repo to my machine and change the external_components/source
line to point to that then I get Platform not found: 'climate.mitsubishi_heatpump'
error. How can I make esphome use my own source? [I guess I could fork this repo and point to that, but there has to be a simpler way].
Also, @geoffdavis, this seems a simple fix. Any reason you don't want to add it? BTW, thanks for superb project. I leaned back in amused shock when I typed the esphome run command and everything downloaded, built, uploaded by USB to the device, then it appeared on my wifi network and automatically in HA.
OK, so I went ahead and forked this repo, made the change, pointed the component to my forked repo, then rebuilt and uploaded where it is now working fine, i.e. it stays connected (and showing 16 degrees in HA of course now). Still interested in knowing how to do a change locally though?
For me this turned out to be a symptom of the serial connection to the heatpump not working, I was using Serial2 on the ESP32 which worked fine for TX (I could control the heatpump mode, etc) but RX did not work. As the esp was not receiving any data from the heatpump the above state variables were uninitialised. Switching back to Serial0 resolved it.
While initialising them does stop HA from repeatedly disconnecting the sensor, you will want to fix the communication issue. You don't want it to say 16 degrees forever.
@thompsa, please understand, I certainly don't want my HA to report 16 degrees forever!? It won't once I eventually get it connected to my aircon unit but that is not the issue here.
@geoffdavis, the issue is that if the CN105 connection is down (i.e. unplugged, wrongly configured, etc), then the ESP device goes into a hard thrash loop where it is disconnecting and reconnecting to the HA server at least 4 times per second forever, i.e. it smashes the server ad-infinitum. Clearly this is undesirable and I am simply stating that the 4 line patch above fixes that issue.
I worked out how to make source changes locally. You have to point to the actual components dir when specifying a path.
Also, a better patch is:
diff --git a/components/mitsubishi_heatpump/espmhp.cpp b/components/mitsubishi_heatpump/espmhp.cpp
index e1cb942..5bceea9 100644
--- a/components/mitsubishi_heatpump/espmhp.cpp
+++ b/components/mitsubishi_heatpump/espmhp.cpp
@@ -428,6 +428,10 @@ void MitsubishiHeatPump::setup() {
ESP_LOGCONFIG(TAG, "Intializing new HeatPump object.");
this->hp = new HeatPump();
+ this->current_temperature = NAN;
+ this->target_temperature = NAN;
+ this->fan_mode = climate::CLIMATE_FAN_OFF;
+ this->swing_mode = climate::CLIMATE_SWING_OFF;
#ifdef USE_CALLBACKS
hp->setSettingsChangedCallback(
I like the NAN values better than dummy valid values, as it signifies to the user that something is wrong. I wish there were something similar for the climate modes. It might be worth adding a binary sensor that signifies a working connection to the equipment.
Fixed in GH-34
Hi,
First thanks for all the great work you have put into this! But for some reason I'm unable to get this running properly. I get repeated Home Assistant disconnections and I don't find a reason for it. It's connecting, updating other values to HA (but client component is missing details) but then it disconnects. After few seconds it reconnects and same happens again.
I have now tried two different ESP32 boards connected to CN105 and also without connection to heatpump. It builds up just fine without problems. First I was with beta version of ESPHome 1.15.x and now with official release 1.15.2.
Could you check and advice how to troubleshoot this? Is there something missing in my configuration? Or how to find the real issue in this?
Log:
Short part of Very Verbose log:
Notice how target_temperature is weird value at least in the log. And disconnection happens right after that. I didn't find any interesting logs from Home Assistant side that would correlate with these.
My code:
I have also tried &Serial1 and &Serial2 but those didn't have any effect on the issue.