syssi / esphome-apc-ups

ESPHome component to monitor and control a APC UPS via RS232
Apache License 2.0
32 stars 7 forks source link

`protocol_version` text sensor can cause a API connection reset #1

Open ananyevgv opened 11 months ago

ananyevgv commented 11 months ago

Screenshot_2023-10-10-23-09-09-627_io.homeassistant.companion.android.jpg

ananyevgv commented 11 months ago

After connecting the UPS (Smart-UPS RT 1000 XL), the connection with the home assistant disappears.

syssi commented 11 months ago

That's strange. Does the WiFi connection drop out too or the API connection only? How do you power the ESP?

ananyevgv commented 11 months ago

API connection only, and it disappears when I connect UPS. While UPS is not connected API connection is normal

syssi commented 11 months ago

How do you power the ESP?

ananyevgv commented 11 months ago

I tried from a separate source, connected from the server, the result is the same. TTL uart converter (https://aliexpress.ru/item/1005003696077889.html ) enabled according to your scheme, today I will try with different framework. ESP Wemos D1 Mini ESP32

syssi commented 11 months ago

Which ESPHome version do you use?

ananyevgv commented 11 months ago

version: 2023.9.3

ananyevgv commented 11 months ago

I added the output to the log, I'll see what's going on in the evening logger: level: VERBOSE logs: api.component: DEBUG api.client: ERROR

ananyevgv commented 11 months ago

The problem is: text_sensor: protocol_info: name: "protocol info"

ananyevgv commented 11 months ago

firmware revision 411.7.I

syssi commented 11 months ago

Without this sensor the API connection gets stable?

ananyevgv commented 11 months ago

Yes

ananyevgv commented 11 months ago

[22:03:51][VV][api.service:174]: send_text_sensor_state_response: TextSensorStateResponse { key: 3214027428 state: 'L' missing_state: NO } [22:03:51][VV][api.service:174]: send_text_sensor_state_response: TextSensorStateResponse { key: 3503450107 ' missing_state: NO } [22:03:51][VV][api.socket:813]: Home Assistant 2023.10.3 (192.168.88.9): Connection closed

syssi commented 11 months ago

Good catch and still strange. I don't know what's going on here.

ananyevgv commented 11 months ago

The main thing works, you can do without this sensor

syssi commented 10 months ago

Could you do me a favor? Please flash this test YAML to your ESP (temporary -> for testing only):

https://github.com/syssi/esphome-apc-ups/blob/main/tests/esp8266-apc-protocol.yaml

and provide the a complete log which provides all responses of your UPS. Could you tell me the model of your UPS?

ananyevgv commented 10 months ago

Ok, I'll check it out tonight

ananyevgv commented 10 months ago

[16:32:08][I][main:655]: Protocol info

ananyevgv commented 10 months ago
[16:36:10][D][uart_debug:158]: >>> "V"
[16:36:10][D][uart_debug:158]: <<< "5YI\r\n"
[16:36:11][C][mdns:112]: mDNS:
[16:36:11][C][mdns:113]:   Hostname: apc-protocol
[16:36:11][C][ota:093]: Over-The-Air Updates:
[16:36:11][C][ota:094]:   Address: apc-protocol.local:8266
[16:36:11][C][api:138]: API Server:
[16:36:11][C][api:139]:   Address: apc-protocol.local:6053
[16:36:11][C][api:143]:   Using noise encryption: NO
[16:36:11][I][main:655]: Protocol info
[16:36:11][D][uart_debug:158]: >>> "a"
[16:36:12][D][uart_debug:158]: <<< "4.!$%+?=*#|\x04.\x01\x05\t\f\x0E\x14\x16\x1A\')+-/789<>@ABCDEFGKLMNOPQRSUVWXYZ\\^abcdefgjklmnopqrsuwxyz~.\x81:\xD0\xE2\xF0\xFD\xFE\xFF\r\n"
[16:36:12][I][main:665]: Firmware revision
[16:36:12][D][uart_debug:158]: >>> "b"
[16:36:12][D][uart_debug:158]: <<< "411.7.I\r\n"
[16:36:13][I][main:675]: UPS local id
[16:36:13][D][uart_debug:158]: >>> "c"
[16:36:13][D][uart_debug:158]: <<< "UPS_IDEN\r\n"
[16:36:14][I][main:685]: Return threshold
[16:36:14][D][uart_debug:158]: >>> "e"
[16:36:14][D][uart_debug:158]: <<< "00\r\n"
[16:36:15][I][main:695]: Battery level
[16:36:15][D][uart_debug:158]: >>> "f"
[16:36:15][D][uart_debug:158]: <<< "100.0\r\n"
[16:36:16][I][main:705]: Nominal battery voltage
[16:36:16][D][uart_debug:158]: >>> "g"
[16:36:16][D][uart_debug:158]: <<< "048\r\n"
[16:36:18][I][main:715]: Measure-UPS ambient humidity
[16:36:18][D][uart_debug:158]: >>> "h"
[16:36:18][D][uart_debug:158]: <<< "NA\r\n"
[16:36:18][I][main:725]: Measure-UPS dry contacts
[16:36:18][D][uart_debug:158]: >>> "i"
[16:36:18][D][uart_debug:158]: <<< "NA\r\n"
[16:36:19][I][main:735]: Estimated runtime
[16:36:19][D][uart_debug:158]: >>> "j"
[16:36:19][D][uart_debug:158]: <<< "0064:\r\n"
[16:36:20][I][main:745]: Alarm delay
[16:36:20][D][uart_debug:158]: >>> "k"
[16:36:20][D][uart_debug:158]: <<< "0\r\n"
[16:36:21][I][main:755]: Low transfer voltage
[16:36:21][D][uart_debug:158]: >>> "l"
[16:36:22][D][uart_debug:158]: <<< "161\r\n"
[16:36:22][I][main:765]: Manufacture date
[16:36:22][D][uart_debug:158]: >>> "m"
[16:36:23][D][uart_debug:158]: <<< "01/06/07\r\n"
[16:36:23][I][main:775]: Serial number
[16:36:23][D][uart_debug:158]: >>> "n"
[16:36:24][D][uart_debug:158]: <<< "JS1501113445  \r\n"
[16:36:24][I][main:785]: Nominal Output Voltage
[16:36:24][D][uart_debug:158]: >>> "o"
[16:36:24][D][uart_debug:158]: <<< "230\r\n"
[16:36:25][I][main:795]: Shutdown grace delay
[16:36:25][D][uart_debug:158]: >>> "p"
[16:36:26][D][uart_debug:158]: <<< "020\r\n"
[16:36:26][I][main:805]: Low battery warning
[16:36:26][D][uart_debug:158]: >>> "q"
[16:36:27][D][uart_debug:158]: <<< "02\r\n"
[16:36:27][I][main:815]: Wakeup delay
[16:36:27][D][uart_debug:158]: >>> "r"
[16:36:28][D][uart_debug:158]: <<< "000\r\n"
[16:36:28][I][main:825]: Sensitivity
[16:36:28][D][uart_debug:158]: >>> "s"
[16:36:29][D][uart_debug:158]: <<< "A\r\n"
[16:36:29][I][main:835]: Measure-UPS ambient temperature
[16:36:30][D][uart_debug:158]: >>> "t"
[16:36:30][D][uart_debug:158]: <<< "NA\r\n"
[16:36:30][I][main:845]: Upper transfer voltage
[16:36:31][D][uart_debug:158]: >>> "u"
[16:36:31][D][uart_debug:158]: <<< "253\r\n"
[16:36:31][I][main:855]: Measure-UPS firmware
[16:36:32][D][uart_debug:158]: >>> "v"
[16:36:32][D][uart_debug:158]: <<< "NA\r\n"
[16:36:33][I][main:865]: Last battery change date
[16:36:33][D][uart_debug:158]: >>> "x"
[16:36:33][D][uart_debug:158]: <<< "01/06/21\r\n"
[16:36:34][I][main:875]: Copyright notice
[16:36:34][D][uart_debug:158]: >>> "y"
[16:36:34][D][uart_debug:158]: <<< "(C) APCC\r\n"
[16:36:35][I][main:885]: Line quality
[16:36:35][D][uart_debug:158]: >>> "9"
[16:36:35][D][uart_debug:158]: <<< "FF\r\n"
syssi commented 10 months ago

Could you make sure to provide a response example for every command? Most of the uppercase commands are missing at the moment.

syssi commented 10 months ago

What's the name / model of your UPS?

ananyevgv commented 10 months ago

APC Smart-UPS RT 1000 XL

ananyevgv commented 10 months ago

[16:44:12][I][main:635]: Status flags

[16:44:13][I][main:645]: Old firmware version

ananyevgv commented 10 months ago

I haven't seen it yet at the beginning of the log

syssi commented 10 months ago
      - uart.write: "Y"
      - uart.write: "B"
      - uart.write: "C"
      - uart.write: "E"
      - uart.write: "F"
      - uart.write: "G"
      - uart.write: "L"
      - uart.write: "M"
      - uart.write: "N"
      - uart.write: "O"
      - uart.write: "P"
      - uart.write: "Q"
      - uart.write: "V"
      - uart.write: "a"
      - uart.write: "b"
      - uart.write: "c"
      - uart.write: "e"
      - uart.write: "f"
      - uart.write: "g"
      - uart.write: "h"
      - uart.write: "i"
      - uart.write: "j"
      - uart.write: "k"
      - uart.write: "l"
      - uart.write: "m"
      - uart.write: "n"
      - uart.write: "o"
      - uart.write: "p"
      - uart.write: "q"
      - uart.write: "r"
      - uart.write: "s"
      - uart.write: "t"
      - uart.write: "u"
      - uart.write: "v"
      - uart.write: "x"
      - uart.write: "y"
      - uart.write: "9"

The sequence of commands will be repeated every 80 seconds.

ananyevgv commented 10 months ago

Yes it is

ananyevgv commented 10 months ago
[16:51:35][D][uart_debug:158]: >>> "Y"
[16:51:35][D][uart_debug:158]: <<< "SM\r\n"
[16:51:36][I][main:535]: Battery voltage
[16:51:36][D][uart_debug:158]: >>> "B"
[16:51:36][D][uart_debug:158]: <<< "54.27\r\n"
[16:51:37][I][main:545]: Internal temperature
[16:51:37][D][uart_debug:158]: >>> "C"
[16:51:37][D][uart_debug:158]: <<< "027.4\r\n"
[16:51:38][I][main:555]: Automatic self test interval
[16:51:38][D][uart_debug:158]: >>> "E"
[16:51:38][D][uart_debug:158]: <<< "OFF\r\n"
[16:51:39][I][main:565]: Line frequency
[16:51:39][D][uart_debug:158]: >>> "F"
[16:51:39][D][uart_debug:158]: <<< "50.03\r\n"
[16:51:40][I][main:575]: Cause of last transfer to battery
[16:51:40][D][uart_debug:158]: >>> "G"
[16:51:40][D][uart_debug:158]: <<< "S\r\n"
[16:51:41][I][main:585]: Input line voltage
[16:51:41][D][uart_debug:158]: >>> "L"
[16:51:41][D][uart_debug:158]: <<< "216.0\r\n"
[16:51:42][I][main:595]: Maximum line voltage
[16:51:42][D][uart_debug:158]: >>> "M"
[16:51:42][D][uart_debug:158]: <<< "217.4\r\n"
[16:51:43][I][main:605]: Minimum line voltage
[16:51:43][D][uart_debug:158]: >>> "N"
[16:51:43][D][uart_debug:158]: <<< "214.5\r\n"
[16:51:44][I][main:615]: Output voltage
[16:51:44][D][uart_debug:158]: >>> "O"
[16:51:44][D][uart_debug:158]: <<< "229.3\r\n"
[16:51:45][I][main:625]: Power load in %
[16:51:45][D][uart_debug:158]: >>> "P"
[16:51:45][D][uart_debug:158]: <<< "027.0\r\n"
[16:51:46][I][main:635]: Status flags
[16:51:46][D][uart_debug:158]: >>> "Q"
[16:51:46][D][uart_debug:158]: <<< "08\r\n"
[16:51:47][I][main:645]: Old firmware version
[16:51:47][D][uart_debug:158]: >>> "V"
[16:51:47][D][uart_debug:158]: <<< "5YI\r\n"
[16:51:48][I][main:655]: Protocol info
[16:51:48][D][uart_debug:158]: >>> "a"
[16:51:49][D][uart_debug:158]: <<< "4.!$%+?=*#|\x04.\x01\x05\t\f\x0E\x14\x16\x1A')+-/789<>@ABCDEFGKLMNOPQRSUVWXYZ\^abcdefgjklmnopqrsuwxyz~�.\x81:\xD0\xE2\xF0\xFD\xFE\xFF\r\n"
[16:51:49][I][main:665]: Firmware revision
[16:51:49][D][uart_debug:158]: >>> "b"
[16:51:49][D][uart_debug:158]: <<< "411.7.I\r\n"
[16:51:50][I][main:675]: UPS local id
[16:51:50][D][uart_debug:158]: >>> "c"
[16:51:50][D][uart_debug:158]: <<< "UPS_IDEN\r\n"
[16:51:51][I][main:685]: Return threshold
[16:51:51][D][uart_debug:158]: >>> "e"
[16:51:51][D][uart_debug:158]: <<< "00\r\n"
[16:51:52][I][main:695]: Battery level
[16:51:52][D][uart_debug:158]: >>> "f"
[16:51:52][D][uart_debug:158]: <<< "100.0\r\n"
[16:51:53][I][main:705]: Nominal battery voltage
[16:51:53][D][uart_debug:158]: >>> "g"
[16:51:53][D][uart_debug:158]: <<< "048\r\n"
[16:51:54][I][main:715]: Measure-UPS ambient humidity
[16:51:54][D][uart_debug:158]: >>> "h"
[16:51:54][D][uart_debug:158]: <<< "NA\r\n"
[16:51:55][I][main:725]: Measure-UPS dry contacts
[16:51:55][D][uart_debug:158]: >>> "i"
[16:51:55][D][uart_debug:158]: <<< "NA\r\n"
[16:51:56][I][main:735]: Estimated runtime
[16:51:56][D][uart_debug:158]: >>> "j"
[16:51:56][D][uart_debug:158]: <<< "0064:\r\n"
[16:51:57][I][main:745]: Alarm delay
[16:51:57][D][uart_debug:158]: >>> "k"
[16:51:57][D][uart_debug:158]: <<< "0\r\n"
[16:51:58][I][main:755]: Low transfer voltage
[16:51:58][D][uart_debug:158]: >>> "l"
[16:51:58][D][uart_debug:158]: <<< "161\r\n"
[16:51:59][I][main:765]: Manufacture date
[16:51:59][D][uart_debug:158]: >>> "m"
[16:51:59][D][uart_debug:158]: <<< "01/06/07\r\n"
[16:52:00][I][main:775]: Serial number
[16:52:00][D][uart_debug:158]: >>> "n"
[16:52:00][D][uart_debug:158]: <<< "JS1501113445 \r\n"
[16:52:01][I][main:785]: Nominal Output Voltage
[16:52:01][D][uart_debug:158]: >>> "o"
[16:52:01][D][uart_debug:158]: <<< "230\r\n"
[16:52:02][I][main:795]: Shutdown grace delay
[16:52:02][D][uart_debug:158]: >>> "p"
[16:52:02][D][uart_debug:158]: <<< "020\r\n"
[16:52:03][I][main:805]: Low battery warning
[16:52:03][D][uart_debug:158]: >>> "q"
[16:52:03][D][uart_debug:158]: <<< "02\r\n"
[16:52:04][I][main:815]: Wakeup delay
[16:52:04][D][uart_debug:158]: >>> "r"
[16:52:04][D][uart_debug:158]: <<< "000\r\n"
[16:52:05][I][main:825]: Sensitivity
[16:52:05][D][uart_debug:158]: >>> "s"
[16:52:05][D][uart_debug:158]: <<< "A\r\n"
[16:52:06][I][main:835]: Measure-UPS ambient temperature
[16:52:06][D][uart_debug:158]: >>> "t"
[16:52:06][D][uart_debug:158]: <<< "NA\r\n"
[16:52:07][I][main:845]: Upper transfer voltage
[16:52:07][D][uart_debug:158]: >>> "u"
[16:52:07][D][uart_debug:158]: <<< "253\r\n"
[16:52:08][I][main:855]: Measure-UPS firmware
[16:52:08][D][uart_debug:158]: >>> "v"
[16:52:08][D][uart_debug:158]: <<< "NA\r\n"
[16:52:09][I][main:865]: Last battery change date
[16:52:10][D][uart_debug:158]: >>> "x"
[16:52:10][D][uart_debug:158]: <<< "01/06/21\r\n"
[16:52:10][I][main:875]: Copyright notice
[16:52:10][D][uart_debug:158]: >>> "y"
[16:52:10][D][uart_debug:158]: <<< "(C) APCC\r\n"
[16:52:11][I][main:885]: Line quality
[16:52:11][D][uart_debug:158]: >>> "9"
[16:52:11][D][uart_debug:158]: <<< "FF\r\n"
ananyevgv commented 10 months ago

Maybe it's the number of characters in the string? It is possible that there are restrictions on the length, or prohibited characters.

syssi commented 10 months ago

Yes. You are on the right track. I will prepare a test setup soon and will reduce this reponse char by char:

https://github.com/syssi/esphome-apc-ups/pull/6/files#diff-e5d6fcd2ac8196ef5ec1e734319ff650aa106f8e5b219904e7ab489e82429186R91

The input buffer is limited to 110 chars at the moment:

https://github.com/syssi/esphome-apc-ups/blob/main/components/apc_ups/apc_ups.h#L134

If the response doesn't fit this limit should be lifted.

ananyevgv commented 10 months ago

image image

ananyevgv commented 10 months ago

image

ananyevgv commented 10 months ago

I tried to make a filter and got an error, maybe something will help

ananyevgv commented 10 months ago

it looks like this symbol: ^