matthias882 / some_esphome_components

My own collection of ESPHOME components
GNU General Public License v3.0
5 stars 1 forks source link

samsung_ac_f1f2com: received datablock to long #1

Open lanwin opened 1 year ago

lanwin commented 1 year ago

Hi, ive tried the ac stuff with my indoor units and get the following log:

[08:50:42][W][samsung_ac_f1f2com:128]: received datablock to long (> 14): 32 92 93 7A 1F 5C 33 D0 D0 16 C9 98 72 43

I am using a nodeMCU device. Instead of D1 and D2 I configured TX and RX directly and switched logger from UART0 to UART1.

What can I do to help here?

matthias882 commented 1 year ago

You can add the following code to your UART-config to get al full log of the received uart data. The Data-Message you posted don't look like a Message I saw on my System. There should be something wrong. Please post some of the Lines the raw uart data you get with the log enabled. An try to switch the A and the B-line (F1 / F2) of your RS485-converter.

uart:
  tx_pin: D1
  rx_pin: D2
  baud_rate: 2400
  parity: EVEN
  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      timeout: 200ms
    sequence:
      - lambda: UARTDebug::log_hex(direction, bytes, ' ');
lanwin commented 1 year ago

Hmm. I am not sure what I wrong but the only log I see is:

[15:34:26][D][sensor:126]: 'Sleepingroom set temperature': Sending state 0.00000 °C with 0 decimals of accuracy
[15:34:26][D][sensor:126]: 'Sleepingroom room temperature': Sending state 0.00000 °C with 0 decimals of accuracy
[15:34:26][D][sensor:126]: 'Sleepingroom temperature EVA in': Sending state 0.00000 °C with 0 decimals of accuracy
[15:34:26][D][sensor:126]: 'Sleepingroom temperature EVA out': Sending state 0.00000 °C with 0 decimals of accuracy
[15:34:26][D][sensor:126]: 'Sleepingroom fanspeed': Sending state 0.00000  with 0 decimals of accuracy
[15:34:26][D][sensor:126]: 'Sleepingroom mode': Sending state 0.00000  with 0 decimals of accuracy
[15:34:26][D][sensor:126]: 'Sleepingroom thermal capacity': Sending state 0.00000 kW with 1 decimals of accuracy
[15:34:26][D][sensor:126]: 'Sleepingroom delta Q': Sending state 0.00000  with 0 decimals of accuracy
[15:34:26][D][sensor:126]: 'Livingroom set temperature': Sending state 0.00000 °C with 0 decimals of accuracy
[15:34:26][D][sensor:126]: 'Livingroom room temperature': Sending state 0.00000 °C with 0 decimals of accuracy
[15:34:27][D][sensor:126]: 'Livingroom temperature EVA in': Sending state 0.00000 °C with 0 decimals of accuracy
[15:34:27][D][sensor:126]: 'Livingroom temperature EVA out': Sending state 0.00000 °C with 0 decimals of accuracy
[15:34:27][D][sensor:126]: 'Livingroom fanspeed': Sending state 0.00000  with 0 decimals of accuracy
[15:34:27][D][sensor:126]: 'Livingroom mode': Sending state 0.00000  with 0 decimals of accuracy
[15:34:27][D][sensor:126]: 'Livingroom thermal capacity': Sending state 0.00000 kW with 1 decimals of accuracy
[15:34:27][D][sensor:126]: 'Livingroom delta Q': Sending state 0.00000  with 0 decimals of accuracy

The only line I saw was:

[15:35:23][D][uart_debug:114]: <<< 28 9C 19 DC FF

The RXD Light on the RS485 converter ist blink. TXD nearly not.

matthias882 commented 1 year ago

there should be more traffic on the lines when the RXD led is blinking. The TXD led should not blink because the device is sending no data at this time.

lanwin commented 1 year ago

Hmm. If I understand you correctly the blinking RXD means the converter get's data over the bus but since I have no output within the log it seems no data is received by the ESP. Right?

Btw I use this converter: https://amzn.eu/d/6xIBAHt

I tried different esphome settings and different GPIO but did not had any luck jet. Also no luck with the second converter.

matthias882 commented 1 year ago

Correct. The converter only listen to the bus-communication between indoor and outdoo unit. The RXD led is blinking if he receives some data. Have you tried to switch the A and B wire? and please show the yaml-file

lanwin commented 1 year ago

I changed A and B. This mad the RXD Light Turn nearly turn on in a line. But still no log.

I also created an empty new image to test that. But still now luck.

esphome:
  name: samsung-ac
  friendly_name: samsung_ac

esp8266:
  board: nodemcuv2

logger:

captive_portal:

uart:
  tx_pin: TX
  rx_pin: RX
  baud_rate: 2400
  parity: EVEN
  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      timeout: 200ms
    sequence:
      - lambda: UARTDebug::log_hex(direction, bytes, ' ');
lanwin commented 1 year ago

I connect that nodeMCU via USB to power it up. Could that be a problem cause it redirects also the serial port via USB.

lanwin commented 1 year ago

The converter seems to work. I attached it to an USB UARD Adapter and this logs incoming data.

matthias882 commented 1 year ago

You can try the piece of code without any other component. but then you have to set the "dummy_receiver" in the uart-settings to "true" to get some data received.

esphome:
  name: samsung-ac
  friendly_name: samsung_ac

esp8266:
  board: nodemcuv2

logger:

captive_portal:

uart:
  tx_pin: TX
  rx_pin: RX
  baud_rate: 2400
  parity: EVEN
  debug:
    direction: BOTH
    dummy_receiver: true
    after:
      timeout: 200ms
    sequence:
      - lambda: UARTDebug::log_hex(direction, bytes, ' ');
lanwin commented 1 year ago

That did it. Thank you. I also noticed that there is a loose connection. I have to reconnect everything tomorrow.

Here is some data I got: https://gist.github.com/lanwin/44b54736a88f079846c0c38b6e8a213b

matthias882 commented 1 year ago

Ok, yes, its received Data. But i don't see data-packages that look like the protocol I know. please switch the A and B wire and try it again.

lanwin commented 1 year ago

Ok here is some data with A-B revesed

https://gist.github.com/lanwin/13f7084359b5f46fa677c9a5b0ab1aa8

Whats interesting is that the RXD LED is now nearly constantly on with some minor flickering.

lanwin commented 1 year ago

How did you got the SNET Pro 2 Service Software working? I tried to use my USB-TTL Stick with the converter and can see that communication is happening but I see no data within the software. On the controller button I see empty textbox with three buttons in Korean letters. When I press them I get an "Fail To read status. Please verify Connection !!"

lanwin commented 1 year ago

Btw my devices are: 4x Indoor Unit TN1DKG 1x Outdoor Unit TXJ4KG

lanwin commented 1 year ago

@matthias882 I got it. The SNET didnt work cause I used the loose wiring from before. After I replaced it, it starts to show data.

I noticed that SNET is a dotnet Application so I looked into its code. It sets there baud rate to 9600 not 2400. Maybe that is one difference in NASA vs NON NASA.

After changing that I now get data packages. 👯

https://gist.github.com/lanwin/7baaaf444d44e9e5c036b400ac18b27c

lanwin commented 1 year ago

I am now able to decode the packages. The NASA protocol has version 2 and seems to be a lot more complicated.

Example Message: 32001e200002b000ffc014bc044202010e42030101420500fd420600fa3e0a34

Decoded:

{
  sa: { class: 32, channel: 0, address: 2 },
  da: { class: 176, channel: 0, address: 255 },
  command: {
    packetInformation: true,
    retryCount: 0,
    packetType: 'Normal',
    dataType: 'Notification',
    packetNumber: 188
  },
  messages: [
    {
      deviceType: 'IndoorUnit',
      type: 'Variable',
      msgIndex: 2,
      messageNumber: '4202',
      MsgValue: 270
    },
    {
      deviceType: 'IndoorUnit',
      type: 'Variable',
      msgIndex: 3,
      messageNumber: '4203',
      MsgValue: 257
    },
    {
      deviceType: 'IndoorUnit',
      type: 'Variable',
      msgIndex: 5,
      messageNumber: '4205',
      MsgValue: 253
    },
    {
      deviceType: 'IndoorUnit',
      type: 'Variable',
      msgIndex: 6,
      messageNumber: '4206',
      MsgValue: 250
    }
  ]
}

There is a mapping XML called NASA.ptc within the SNET directory.

In example messageNumber 4203 means room temperature in celsius and needs to be deviced by 10. Here 25.7°

matthias882 commented 1 year ago

Hey, thats great. Yes, the message looks al little different. 32 byte long but with 0x32 as start and 0x34 as end-marker. That should be also no big problem to decode. And what a great job you did wiht finding the .ptc config-files for all the Messages! At this time I am fighting to put the code from a sensor-component into a climate-component. This will make it possible to controll the Values from ESPHome. When I have a little bit more time in the next day I think I will get it....

lanwin commented 1 year ago

I would suggest that we extract the package decoding/encoding out of the samsung_ac_f1f2com.cpp into extra files. non_nasa.cpp and nasa.cpp. This way it would be possible to add unit tests based on real package data.

It should be possible to distinguish both based on its packet size. NonNASA Package Size 14 - NASA Min Package Size 16 (extracted from code).

I would also suggest to switch to a dynamic device list instead of a static.

We should keep a list of all devices witch are messages received for. Then log each devices with sends messages but have not yaml mapping out.

Maybe I could help you code. But my C++ is a little bit rusty (last time I used it was 20 years ago)

lanwin commented 1 year ago

Yeha. I was able to power on and power of one of my units via bus.

lanwin commented 1 year ago

So I ported my prototype code over to C++. I will be able to integrate it into this repo this week.

lanwin commented 1 year ago

@matthias882 I currently get my code running on the ESP but have the strange behavior that after some minutes the TX led on the converter lights up for a long time and the ESP did not response any longer. But I did not yet send any data via TX.

Did you ever had that problem? I can only imagine that this could be an out of memory error.

lanwin commented 1 year ago

Got it working. Indeed it was a memory leak.

Not sure if this is possible, but I would suggest that we try to use such an configuration schema.

  - platform: samsung_ac
    address: 20.00.00
    temp:
      name: "Sleepingroom temperature"
    room_temp:
      name: "Sleepingroom room temperature"
    pipe_in_temp:
      name: "Sleepingroom temperature EVA in"
    pipe_out_temp:
      name: "Sleepingroom temperature EVA out"
    fanspeed:
      name: "Sleepingroom fanspeed"
    mode:
      name: "Sleepingroom mode"
    capacity:
      name: "Sleepingroom thermal capacity"
    delta_q:
      name: "Sleepingroom delta Q"

We than can choose the protocol based on the address size. NonNasa 20, Nasa 20.00.00

lanwin commented 1 year ago

It took me a while to fiddle with the esphome code generator but now I have a working version with the schema:

samsung_ac:
  dataline_debug: false
  devices:
  - address: "10.00.00"
    room_temperature:
      name: Test1_temp
    power:
      name: Test1_power
  - address: "10.00.01"
    room_temperature:
      name: Test2_temp
    power:
      name: Test2_power
  - address: "20.00.02"
    room_temperature:
      name: Test3_power
    power:
      name: Test3_power
  - address: "20.00.03"
    room_temperature:
      name: Test3_temp
    power:
      name: Test3_power

Looks like this

grafik

lanwin commented 1 year ago

Turning the indoor units on and off via esphome works now.

I put my code temporary here https://github.com/lanwin/esphome_samsung_ac