Bunicutz / ESP32_Midea_RS485

MIT License
19 stars 6 forks source link

adjust the data #7

Open Cosmicbase opened 1 year ago

Cosmicbase commented 1 year ago

Do I have to adjust the data here? Unlike what is normal in yaml, here are the parameters in the bunicutz_AC.h.

midea_AC.h#include "esphome.h"

include

define DI_PIN 16 define RO_PIN 17 define DE_PIN 4 define RE_PIN 4

define SERIAL_COM_BUS &Serial2

define SERIAL_COM_CONTROL_PIN DE_PIN

define SERIAL_COM_MASTER_ID 0

define SERIAL_COM_SLAVE_ID 0

define SERIAL_COM_MASTER_SEND_TIME 40 define SERIAL_COM_SLAVE_TIMEOUT_TIME 100

Bunicutz commented 1 year ago

The values here depend on the wiring you create for the esp32. If you connect the wires to tjose pins then the file should remain untouched otherwise you should modify it acording to the schematic you implement.

Cosmicbase commented 1 year ago

Can you write an example yaml that works? I would then like to adjust it. I will use the standard pins which are also provided as an example.

Bunicutz commented 1 year ago

The one I am using is in the example folder https://github.com/Bunicutz/ESP32_Midea_RS485/blob/main/example/esp32_midea_RS485_HA_sample/aer-conditionat.yaml

Cosmicbase commented 1 year ago

esphome: name: salon-ac friendly_name: Salon AC

esp32: board: esp32dev framework: type: arduino

Enable logging

logger:

Enable Home Assistant API

api: encryption: key: "B2gKcvD3IL+n68y20EPk9QrsZDrIWsUbVTOe0lRHc5o="

ota: password: "e6b73dd2b92010079064f8630df6197e"

wifi: ssid: !secret wifi_ssid password: !secret wifi_password

Enable fallback hotspot (captive portal) in case wifi connection fails

ap: ssid: "Salon-Ac Fallback Hotspot" password: "GIUWS1FzMcMA"

........................................................

includes:

..............................................

sensor:

select:

number:

switch:

Cosmicbase commented 1 year ago

INFO Reading configuration /config/esphome/salon-ac.yaml... Failed config

wifi: [source /config/esphome/salon-ac.yaml:22] ssid: !secret wifi_ssid password: !secret wifi_password ap: ssid: Salon-Ac Fallback Hotspot password: GIUWS1FzMcMA

[includes] is an invalid option for [wifi]. Please check the indentation. includes:

Cosmicbase commented 1 year ago

I can`t install.

Cosmicbase commented 1 year ago

When i take your yaml. The following error ist coming.

INFO Reading configuration /config/esphome/salon-ac.yaml... ERROR Error while reading config: Invalid YAML syntax:

expected '', but found '' in "/config/esphome/salon-ac.yaml", line 11, column 1: sensor: ^

Bunicutz commented 1 year ago

Do you have esp home installed in the HA? If yes in the copy ghe first chunk of code in the esphome: section and the rest after mqtt: section in the template generated by esphome for the device. The sections are delimited by #........... in the example yaml file.

Flachzange commented 1 year ago

Hi @Cosmicbase , I guess I understand where you are coming from and why you are asking those question. I feel to be in a similiar position. It is actually my first ESPhome and ESP project at all and the learning curve is quite steep jumping directly into this project here.

Let's start with some basics, which I think I understood so far:

I was able to to do the hardware wiring and the deployment of the firmware to an ESP32.

However, I am still missing something which I don't get due to lack of understanding. I have an Olimex ESP32-POE-ISO (which is probably at bit overkill) I connected three available GPIO ports to the MAX485 and defined those GPIO ports in the bunicutz_AC.h.

What else Do i need to adjust from these parameters

begin:
   hwSerial - ESP32 HW serial unit connected to the bus
   ro_pin - RI pin
   di_pin - RO pin
   re_de_pin - RE/DE pin
   master_id - id of the master
   slave_id - id of the slave
   command_time - time in ms needed for command: ~40ms (you can play with it untill no message is lost anymore)
   response_timeout - time after which the response is read: ~100ms

It is a bit trial and error at the moment for me. What role does hwSerial play? What is the correct setting for master and slave ids?

It would be really great if @Bunicutz could shade some light here. Thanks a lot.

Bunicutz commented 1 year ago

Hi guys @Cosmicbase @Flachzange Sorry but I did not get any feedback on the thread so I just forgot about it.

I am not an expert in ESP home nor in AC units :) and I will try to layout my understanding on it and how it works:

SW side:

  1. install ESP home in your HA: https://esphome.io/guides/getting_started_hassio.html
  2. you get a ESP dev board and "pair" it with ESP home by clicking the "add new device" button This will create the yaml file for your dev board.
  3. In the created yaml file you insert the snippets from the example yaml file https://github.com/Bunicutz/ESP32_Midea_RS485/blob/main/example/esp32_midea_RS485_HA_sample/aer-conditionat.yaml The #.............................................. from the file is a placeholder for the lines of the file already generated by ESPHome
  4. do not forget step 1 from the https://github.com/Bunicutz/ESP32_Midea_RS485/tree/main#home-assistant-integration (this is later detailed in the HW side below)

HW side:

  1. communication between the ESP device and AC is a serial one (RS485 https://en.wikipedia.org/wiki/RS-485 )
  2. It is also a Master-Slave communication which means that the ESP controls the communication i.e. the ESP sends commands and the AC responds. The AC will never respond if not asked. Also if the ESP asks the AC might not respond and thus you need the command time and the response timeout to identify the com errors. If you have an oscilloscope you can measure them on the bus otherwise trial an error is a good cheaper choice :)
  3. @Flachzange you need to connect the pins which have HW serial capability in my case pins 16 and 17 are connected internally in the ESP to the HW serial unit no 2. DE/RE can be any pins with digital output capability. This tutorial was very good for me to create the schematic https://microcontrollerslab.com/rs485-serial-communication-esp32-esp8266-tutorial/ image
  4. @Flachzange please make sure you have the GND of the ESP connected to the GND of the AC (otherwise something might get toasted)
  5. @Flachzange HWSerial means that the com protocol is implemented by a dedicated HW unit in the ESP and not by a SW library.
  6. @Flachzange Master and Slave IDs are determined by the settings on the devices. (ESP by default 0 if you do not use more than one on the bus and for the AC you need to read the jumper configuration in your unit which is 0 by default - my understanding - if you do not have more than one unit connected to the outdoor unit - my understanding)

I tried to give out in the examples the values that worked for me. You can start from those and then joggle with them until it works.

@Flachzange @Cosmicbase I hope this helps you guys.

Flachzange commented 1 year ago

Thanks @Bunicutz . That helped a lot to confirm my understanding. My issue: I can conly see the messages being sent by the ESP but I am not getting a response. I played a little with the timings but that's a bit frustrating trial & error. Can I see whether there are com errors without having an oscilloscope? Some kind of debug output on the ESP itself?

I had a look at the terminal board for the indoor unit and it indeed it seems I can set an ID here, but it is not documented somehwere.

Available documentation: https://shop.systemair.com/upload/assets/IOM_TERMINAL_BARD_GB_210621.PDF?d17ebad7

2023-07-12_09-38-13_IMG_4569

Just to be explicit. My output is the following:

[09:52:50][D][custom:209]: SentData: aa c0 0 0 80 0 0 0 0 0 0 0 0 3f 81 55 
[09:52:50][D][custom:250]: ReceivedData: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[09:52:50][D][select:015]: 'AC Mode': Sending state Off (index 0)
[09:52:50][D][select:015]: 'AC Fan Mode': Sending state Auto (index 0)
[09:52:50][D][number:012]: 'AC Set Temp': Sending state 18.000000
[09:52:50][D][sensor:094]: 'AC In Air Temp': Sending state 0.00000 °C with 0 decimals of accuracy
[09:52:50][D][sensor:094]: 'AC Coil A Temp': Sending state 0.00000 °C with 0 decimals of accuracy
[09:52:50][D][sensor:094]: 'AC Coil B Temp': Sending state 0.00000 °C with 0 decimals of accuracy
[09:52:50][D][sensor:094]: 'AC Outdoor Temp': Sending state 0.00000 °C with 0 decimals of accuracy
[09:52:50][D][sensor:094]: 'AC Com State': Sending state 0.00000 bool with 0 decimals of accuracy
Bunicutz commented 1 year ago

Hi @Flachzange it seems that the AC is not responding. How long is the wire you are using? Can you also send a picture with the ESP wiring? Please try to identify what does the jumper from the documentation. Other debug method would be to buy a usb to rs485 converter and try to sniff the bus with that( connect it in paralal to the bus) using a serial terminal pc application. This will show if the AC is responding at all or not and if the esp is sending something on the bus.

Flachzange commented 1 year ago

Really appreciate your support. The length of the cable is ~1,20m. I quickly draw a schema of the wiring:

grafik

A little bit unexpected, I also found a documentation of the switch: grafik

Therefore, everything is correctly set at the indoor unit. ID is 0

Bunicutz commented 1 year ago

@Flachzange I sue the same cable length. I think I may have a clue about the issue: please use other pin than GPIO 0 and 2 it is used for bootloader for reflashing and might do something unexpected during boot also if I am not mistaken they might have some pullups/downs connected. Please revert timing values to default an try it out like that. Sorry but it is time for trial an error again... :)

Bunicutz commented 1 year ago

@Flachzange also try to disable usage of UART by the ESP Home code by setting the debug level to NONE or try to set the baud rate for the logger to 4800 : https://esphome.io/components/logger.html image

https://esphome.io/components/uart.html

If this still does not work the I would suggest to get a simpler ESP32 dev board with serial 2 available just to have exclusivity with the AC on the bus. I am not sure how the AC reacts to higher baud rates on the bus and it might enter some weird state.

Flachzange commented 1 year ago

Thanks @Bunicutz. I am completely puzzled.

please use other pin than GPIO 0 and 2 it is used for bootloader for reflashing and might do something unexpected during boot also if I am not mistaken they might have some pullups/downs connected.

I tried various other ports. Without success.

also try to disable usage of UART by the ESP Home code by setting the debug level to NONE or try to set the baud rate for the logger to 4800 : https://esphome.io/components/logger.html

I cannot see any console output once disabled ;) But I moved the logger to UART2. Without success.

If this still does not work the I would suggest to get a simpler ESP32 dev board with serial 2 available just to have exclusivity with the AC on the bu

I already ordered a standard ESP32 dev kit yesterday which I could try today. I used the following pins:

#define DI_PIN 16
#define RO_PIN 17
#define DE_PIN 5
#define RE_PIN 5

#define SERIAL_COM_BUS &Serial2
#define SERIAL_COM_CONTROL_PIN DE_PIN
#define SERIAL_COM_MASTER_ID 0
#define SERIAL_COM_SLAVE_ID 0
#define SERIAL_COM_MASTER_SEND_TIME  40
#define SERIAL_COM_SLAVE_TIMEOUT_TIME 100

This makes use of the dedicated serial 2.

grafik

Let me know if you have any idea left and sorry for bothering!

Bunicutz commented 1 year ago

Hi @Flachzange no worries. That devkit is exactly the one I have so it should work directly with the example. If that does also not work perhaps the port on the AC is not enabled somehow... but that is leaving my competence area... :) I would look for jumpers or missing(unpopulated) components on the board... but out of my league... sorry...

Flachzange commented 1 year ago

It seems I am doing something fundamentally wrong. Due the lack of an oscilloscope and a ready-to-use RS485-USB-Converter, I tried to use the second ESP as a sniffer on the bus. Similar to https://jheyman.github.io/blog/pages/RS485Sniffer/

Obviously, I removed the termination resistor on the MAX485 and configured then the UART in debug mode with 4800 baud:

uart:
  tx_pin: 1
  rx_pin: 3
  baud_rate: 4800
  data_bits: 8
  parity: NONE
  stop_bits: 1
  debug:

But in the end I do not see anything on the bus...

Bunicutz commented 1 year ago

Sorry but this leaves me puzzled. Could you try with a small led in the data lines between ESP and MAX and see if there is some activity there. Other ideas I don't have.... sorry.

Flachzange commented 1 year ago

Why do it simple when you can do it super complicated :) I have an "official" KNX bus coupler for the midea ACs with XYE. So I created the most simple KNX setup and the good thing is: I can receive the values. The bad thing is, I still don't know why the other solution is not working. I will do a small summer break now, but I will keep you posted on my efforts.

Edit: And with the sniffer I can see the traffic from the KNX device

Again, thanks for the help

golya87 commented 1 year ago

Hello Bunicutz,

If I want to change the mentioned send time and slave timeout values, is it enough if I change them in the bunicutz_AC.h file?

Thank you in advance!

Bunicutz commented 1 year ago

Hi golya87, Yes.

golya87 commented 1 year ago

Sadly no luck, from 20 to 60. How can I check if the ESP really uses the 16-17 ports for the MAX485 module? I've connected a led to the X and E ports but haven't seen any blinking.

Bunicutz commented 1 year ago

I would highly recommend either a rs485 to usb converter or an osciloscope. There are some low price solutions on the market.

Flachzange commented 1 year ago

Hi @golya87, you may want to contact me via discord (Flachzange31). Maybe we can figure this out together and come back here with the results.

Bunicutz commented 1 year ago

@Flachzange @golya87 just had an issue with my device after a thunderstorm and some lightning on the powe grid. The P4 was damaged in the process. Without it on high (3.3V) there is no transmission happening. Perhaps this info can help in identifying your issue.

Flachzange commented 1 year ago

Hi @Bunicutz , just to be sure: you are talking about

define DE_PIN 4 define RE_PIN 4

Correct?

Bunicutz commented 1 year ago

Hello @Flachzange, yes.

Flachzange commented 1 year ago

omg...as expected...something trivial: switchting DI and RO did the trick

My understanding was: The pin connecting DI is defined as DI_PIN. That understanding was wrong. The oscilloscope showed me the sending signal on the pin defined as RO_PIN. Looking at your code it then became obvious:

ESP32_Midea_RS485Class::ESP32_Midea_RS485Class(HardwareSerial *hwSerial, uint8_t ro_pin, uint8_t di_pin, uint8_t re_de_pin, uint8_t master_id, uint8_t slave_id, uint8_t command_time, uint8_t response_timeout): ComControlPin(re_de_pin), SerialBus(hwSerial), datain_pin(di_pin), dataout_pin(ro_pin),

https://github.com/Bunicutz/ESP32_Midea_RS485/blob/21579f4515279e2b8ccfcecfbe9678ba397f59e7/src/esp32_midea_RS485.cpp#L92C1-L93C21

The wires need to be crossed: RO_PIN needs to go to the DI input of the MAX485 and DI_PIN to RO.

Now I receive an answer from the AC and can control it.

P.S. There was no need for me to feed the 3.3V to DE_PIN/RE_PIN

golya87 commented 1 year ago

I had the same problem. After swapping the tx and rx cables the controlling worked.

klugev303 commented 1 year ago

Please tell me what is wrong, why I can not compile this project? 485

do I need to remove the "#" in the file bunicutz_AC.h ? 485_2

Flachzange commented 1 year ago

Hi @klugev303 , a new issue ticket would have probably been the better choice.

The "#" must not be removed. But something else seems to be wrong based on the path and the compilation output. I suggest: create a new issue and post your yaml and bunicutz_AC.h.

Thanks