Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Wired" connection support? #310

Open
voed opened this issue Dec 9, 2024 · 55 comments
Open

"Wired" connection support? #310

voed opened this issue Dec 9, 2024 · 55 comments
Labels
enhancement New feature or request

Comments

@voed
Copy link

voed commented Dec 9, 2024

Is your feature request related to a problem?

I have some issues with grabbing data from the stick, so i decided to connect the inverter via rs485 port. I am not sure if HA provides access to the serial port for the integrations, but maybe at least we can make it work via mbusd?
For now i am getting this error, seems like the integration completely ignores ip and obtaining logger's ip by serial number (.101 is TCP to Modbus gateway's ip which i am trying to use, .65 is inverter's ip).
image
image

Describe the solution you'd like

Provide ability to connect by TCP to Modbus Gateway

Describe alternatives you've considered

Dunno

@voed voed added the enhancement New feature or request label Dec 9, 2024
@davidrapan
Copy link
Owner

Hi @voed, comment:

self.host = device["ip"]

to test if your use case even works and let me know.

@voed
Copy link
Author

voed commented Dec 9, 2024

Did not helped much, now i am getting "Device loading failed [TimeoutError]".
I see that it tries to connect to the gateway, so looks like there are some protocol issues. Maybe you can learn further how kellerza's addon works? As it's using pysolarman too i think there's should be a way to make it work.

@davidrapan
Copy link
Owner

Show me the debug log. 😉

As it's using pysolarman too

No, it does not use pysolarmanv5.

@voed
Copy link
Author

voed commented Dec 9, 2024

Oh, my bad, i guess it is using pysolarman only for connection via stick, not modbus.

Logger: homeassistant
Source: runner.py:147
First occurred: 22:37:27 (13 occurrences)
Last logged: 22:57:38

Error doing job: Task was destroyed but it is pending! (<Task pending name='ConnKeeper' coro=<PySolarmanV5Async._conn_keeper() running at /usr/local/lib/python3.12/site-packages/pysolarmanv5/pysolarmanv5_async.py:172> wait_for=<Future pending cb=[Task.task_wakeup()]>>)

That's all what i have in the logs.

@davidrapan
Copy link
Owner

You need to enable debug logging.

@voed
Copy link
Author

voed commented Dec 9, 2024

2024-12-09 23:17:27.233 DEBUG (MainThread) [custom_components.solarman.api] [<id>] Auto reconnect enabled. Will try to restart the socket reader
2024-12-09 23:17:27.234 DEBUG (MainThread) [custom_components.solarman.api] [<id>] Successful reconnect
2024-12-09 23:17:27.234 DEBUG (MainThread) [custom_components.solarman.api] [<id>] Data expected. Will retry the last request
2024-12-09 23:17:27.235 DEBUG (MainThread) [custom_components.solarman.api] [<id>] Connection reset. Closing the socket reader.
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/pysolarmanv5/pysolarmanv5_async.py", line 172, in _conn_keeper
    data = await self.reader.read(1024)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/streams.py", line 713, in read
    await self._wait_for_data('read')
  File "/usr/local/lib/python3.12/asyncio/streams.py", line 545, in _wait_for_data
    await self._waiter
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1003, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ConnectionResetError: [Errno 104] Connection reset by peer

Oh, and if forgot to mention that addon is using inverter SN for connection, not the stick SN

@davidrapan
Copy link
Owner

That's all? If so then you are not listening on the port. 😉

Oh, and if forgot to mention that addon is using inverter SN for connection, not the stick SN

Does not matter if it talks modbus tcp... it does not use serial at all.

@voed
Copy link
Author

voed commented Dec 9, 2024

But i am, it connects fine from the addon.
Here's what i see in the mbusd logs:

09 Dec 2024 23:43:12 conn_open(): accepting connection from 192.168.1.101
09 Dec 2024 23:43:17 conn[192.168.1.101]: timeout, closing connection
09 Dec 2024 23:43:17 conn_close(): closing connection from 192.168.1.101

@davidrapan
Copy link
Owner

Try:

self._passthrough = False

switch it to True.

And give me whole log file, because if it listen it has to at least connect and send some data. And I can't see that it is doing just from log snippets. 😉

@voed
Copy link
Author

voed commented Dec 9, 2024

Here, check please.
home-assistant_solarman_2024-12-09T22-19-48.020Z.log

@davidrapan
Copy link
Owner

davidrapan commented Dec 9, 2024

So there is communication... you did not see it? It even successfully reads registers 0 - 22. It fails afterwards when it requests registers 0 - 112. Doesn't have that gateway or anything along the way some limitation how big the request can be?

Edit: It replies w/ GatewayTargetDeviceFailedToRespondError that is problem between gateway and rs485.

@davidrapan
Copy link
Owner

davidrapan commented Dec 9, 2024

  • Don't put serial number of the stick into config, when you don't want to talk with the stick.
    • This will also disable that ip enforce, because no one will respond.
  • Show me if it also works w/ (set to False)

Then find out if the requests are not too big. Copy deye_string.yaml under custom folder and add to default section:

default:
    max_size: 20

then configure device with that file and serial number set to inverter serial number.

@davidrapan
Copy link
Owner

More info about the exception from mbusd:
GATEWAY TARGET DEVICE FAILED TO RESPOND:

  • Specialized use in conjunction with gateways indicates that no response was obtained from the target device. This usually means that the device is not present on the network.

@voed
Copy link
Author

voed commented Dec 9, 2024

image
But the SN field is required. I am used serial number of the inverter.

@davidrapan
Copy link
Owner

No you used serial of stick. If you use serial of stick = discovery works and it gets IP from discovery.

@voed
Copy link
Author

voed commented Dec 9, 2024

Oh, yes, initially i forgot about that and used SN of stick.
I will check the rest tomorrow, thanks for help.

@davidrapan
Copy link
Owner

Anyway, it looks like there won't be any changes necessary for it to work.

@voed
Copy link
Author

voed commented Dec 10, 2024

Hi. Tested with passthrough = true and max_size: 20 and it works! With passthrough = false does not work.
For some reason Device sensor shows "String inverter" instead of hybrid, but everything else seems fine.
Also with passthrough = true i am not able to connect via stick anymore, but i guess its normal.

@davidrapan
Copy link
Owner

davidrapan commented Dec 10, 2024

max_size: 20

So I was right about the limited quantity which can be used through that mbusd and rs485. 😉

For some reason Device sensor shows "String inverter"

Maybe because you have string inverter?

Also with passthrough = true i am not able to connect via stick anymore, but i guess its normal.

Yes it forces the integration to use modbus tcp only which is incompatible w/ solarman protocol.

@davidrapan
Copy link
Owner

Anyway can you show me debug log file with passthrough = False? Maybe I could make it work through autodetection. Depends on how it responds.

@voed
Copy link
Author

voed commented Dec 10, 2024

Maybe because you have string inverter?

No, i have SG05LP01 6kw 😁
With connection by stick it shows correctly. But via modbus it shows string inverter. Also battery temperature is incorrect(-85 °C)
image

@voed
Copy link
Author

voed commented Dec 10, 2024

Uploading home-assistant_solarman_2024-12-10T19-10-54.701Z.log…
Here's the log with passthrough=false

@davidrapan
Copy link
Owner

davidrapan commented Dec 10, 2024

Can you then show me your log when you do connection via stick normally so I can compare it?

Uploading home-assistant_solarman_2024-12-10T19-10-54.701Z.log…

You did not wait long enough for the file to upload. 😉

@voed
Copy link
Author

voed commented Dec 10, 2024

I will check it again tomorrow.

@davidrapan
Copy link
Owner

Here's the log with passthrough=false

Will you upload the file?

@voed
Copy link
Author

voed commented Dec 10, 2024

Yes, i will do that tomorrow, too sleepy already:)

@rtripon
Copy link

rtripon commented Dec 11, 2024

Hello, sorry for busting here :), but I`m interested in this topic also.
I have an ESPHome board that talks with inverter via RS485, your work here means its possible to integrate that IP into solarman?.
Currently Solarman is getting data from wifi dongle sticked into inverter, but it would be nice if it could get data from my ESPHome board also.

@voed
Copy link
Author

voed commented Dec 11, 2024

Hi. As far as i know ESPHome does not have RTU to TCP proxy. But you should be able to do that by something like this

@neofral
Copy link

neofral commented Dec 11, 2024

@voed
are you talking about this type of device?
https://esphome.io/components/modbus_controller.html

@rtripon
Copy link

rtripon commented Dec 11, 2024

Yes, that's it.
I already have the data comming in via modbus_controller from my ESPHome board into HA, but in Solarman Application, there are custom sensors that I like, and those are missing from my ESPHome board.

@neofral
Copy link

neofral commented Dec 11, 2024

you can add custom sensors in your configuration.yaml.
can use the sensors provided by the board as input sensor.
or, you can also use HA UI to create helpers to help you create many types of custom sensors

@voed
Copy link
Author

voed commented Dec 11, 2024

No, i mean a gateway that will relay modbus to the lan network so solarman can read it.

@rtripon
Copy link

rtripon commented Dec 11, 2024

you can add custom sensors in your configuration.yaml. can use the sensors provided by the board as input sensor. or, you can also use HA UI to create helpers to help you create many types of custom sensors

I would like/do that, but I`m a bit worried I might break something into my ESPHome board.
For example PV Input on my ESPHome board looks like this ::

  • platform: modbus_controller
    modbus_controller_id: ${modbus_controller_id}
    name: "${device_type}-PV1 Power"
    id: ${device_type}_PV1_Power
    register_type: holding
    address: 672
    unit_of_measurement: "W"
    state_class: "measurement"
    accuracy_decimals: 0
    value_type: U_WORD

And on Solarman it looks a bit different ::

  • name: PV Power
    description: Combined power of all inputs
    realtime:
    class: power
    state_class: measurement
    uom: W
    rule: 1
    digits: 0
    registers: [0x02A0, 0x02A1, 0x02A2, 0x02A3]
    sensors:
    • registers: [0x02A0]
    • registers: [0x02A1]
    • registers: [0x02A2]
    • registers: [0x02A3]

The registers part i`m confused a bit : this means PV1 address 672(I have all the addresses in a document, all are numbers)
its translated into hex 0x02A0 ?
672 = 2A0 hex.
So if I want to make a custom sensor that combines PV1+PV2 in my ESPhome, it should look like this? :

  • platform: modbus_controller
    modbus_controller_id: ${modbus_controller_id}
    name: "${device_type}-PV Total Power"
    id: ${device_type}_PV_Total_Power
    register_type: holding
    address: [672,673] ?? This is where I'm confused.
    unit_of_measurement: "W"
    state_class: "measurement"
    accuracy_decimals: 0
    value_type: U_WORD

@neofral
Copy link

neofral commented Dec 11, 2024

the simplest way i know is to make that sensor in configuration.yaml.
something like this:

template:

  • sensor:
    • name: Total PV Power
      unit_of_measurement: "W"
      state_class: measurement
      device_class: energy
      icon: mdi:solar-power
      state: >-
      {{ (states('${device_type}-PV1 Power')) |float |round(2) + (states('${device_type}-PV1 Power')) |float |round(2) }}

in this case i don't really know how the substitutes will work, you want to use actually sensor name.
give it a try and you'll figure it out. check for logs for any errors in your configuration.

@voed
Copy link
Author

voed commented Dec 11, 2024

Guys it's not related to this isue:)

@voed
Copy link
Author

voed commented Dec 11, 2024

@davidrapan mbusd gateway connection with passthrough = False
https://drive.google.com/file/d/18hIEncrcsFu34PlnbKFCkNGBSuEVAef7/view

Stick connection with passthrough = False
home-assistant_solarman_2024-12-11T12-00-38.589Z.log

@davidrapan
Copy link
Owner

davidrapan commented Dec 11, 2024

Unfortunately there isn't successful connection logged in any of the files.

@voed
Copy link
Author

voed commented Dec 11, 2024

Not sure what do you mean, the first one was unable to connect because it needs passthrough i guess, and the second one is a successful connection and still receiving data from the inverter.

@davidrapan
Copy link
Owner

davidrapan commented Dec 11, 2024

because it needs passthrough i guess

No, this can't affect initialization of the connection. This switch affects later sending of the data.

and the second one is a successful connection and still receiving data from the inverter.

You are right I accidentally overwrite the file ;)

@davidrapan
Copy link
Owner

Anyway, this is really strange, reading of register 0 in standard mode results in device type detection as 0x3, which is hybrid inverter. And reding over that gateway results in 0x0200, which is string inverter. 😆 Someone is lying here! 😆

@voed
Copy link
Author

voed commented Dec 11, 2024

You did not wait long enough for the file to upload. 😉

Just now realized it lol. I thought you are saying that i am colleted not much enough data. Already deleted that log but i am sure it was the same that i have posted today: "Connection reset by peer" and nothing else

@davidrapan
Copy link
Owner

davidrapan commented Dec 11, 2024

With "Connection reset by peer" it means that it did not even get to the point where it should use that passthrough switch.

Edit: In other words there is no SENT: message. That is the first occasion in the standard flow where it utilizes that bool switch and not in establishing of the connection.

@voed
Copy link
Author

voed commented Dec 11, 2024

I got it. No idea how passthrough affects that, but it is what it is:)

@davidrapan
Copy link
Owner

davidrapan commented Dec 11, 2024

Just copy over deye_hybrid.yaml under custom folder and configure device using that copy of the file (when connecting through that gateway).

Edit: Don't forget to set max_size, you can by trial and error find out which max value it allows you to set (it will be proly some bigger value than 20).

@voed
Copy link
Author

voed commented Dec 11, 2024

Um, but i am using copy of deye_hybrid profile now🤔

@davidrapan
Copy link
Owner

davidrapan commented Dec 11, 2024

So set the max_size and use it also for conn through that gateway.

@voed
Copy link
Author

voed commented Dec 11, 2024

Looks like 39 is a maximum.

@voed
Copy link
Author

voed commented Dec 13, 2024

Also seems like the battery temperature register provides valid data, but without offset. Removed offset:1000 and values looks valid:
image

@davidrapan
Copy link
Owner

You should ask the author of that gateway bc it looks like it is changing a lot of things. 😉

@voed
Copy link
Author

voed commented Dec 13, 2024

It's fine, just saying.
So, are you going to implement that passthrough option or auto-detect for this purpose?

@davidrapan
Copy link
Owner

I would argue that changing device type from hybrid to string is not really fine. 😆

@voed
Copy link
Author

voed commented Dec 13, 2024

In kellerza's addon this value refers to "inverter", so maybe it just means any inverter, not string inverter:)
image

Everything else including SN, rated power etc is okay. So yes, i think it's fine
image

@davidrapan
Copy link
Owner

davidrapan commented Dec 13, 2024

That means string inverter, every non-hybrid inverter is string inverter.

But the most important part is that it does not even report 2 but 512.

@voed
Copy link
Author

voed commented Dec 13, 2024

Which is 0x200 in hexadecimal
image

@davidrapan
Copy link
Owner

davidrapan commented Dec 13, 2024

Yes, and? I know why I have it there but I was referring to your example from that addon. Meaning you used as an example something what does not even match the value returned... 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants