ElD4n1 / home-assistant-renogy-rover-integration

Integrates Renogy Rover Solar Charge Controllers connected via USB/UART into Home Assistant
MIT License
2 stars 1 forks source link

Add support for different device addresses #2

Closed madninjaskillz closed 2 years ago

madninjaskillz commented 2 years ago

Firstly, thanks for creating this. I'm having issues setting it up however and having no joy getting up and running so far. What I've done:

At this point I get an error:

Config flow could not be loaded

Am I doing something wrong, missing a step or is there just a problem on my end?

madninjaskillz commented 2 years ago

Randomly, pure persistence resolved that... but this has lead me to this:

image

doesn't matter what one I pick (even though the ttyUSB0 is the correct one) this screen pops up.

i get the following in logs:

Logger: custom_components.renogy_rover.config_flow
Source: custom_components/renogy_rover/renogy_rover.py:70
Integration: Renogy Rover
First occurred: 2:23:23 AM (3 occurrences)
Last logged: 2:23:38 AM

Could not connect to device=/dev/ttyUSB0
Could not connect to device=/dev/serial/by-id/usb-9710_7715-if00-port0
Traceback (most recent call last):
  File "/config/custom_components/renogy_rover/config_flow.py", line 37, in connect_and_read_device_info
    device_info[ATTR_SERIAL_NUMBER] = client.serial_number()
  File "/config/custom_components/renogy_rover/renogy_rover.py", line 70, in serial_number
    registers = self.read_registers(24, 2)
  File "/usr/local/lib/python3.9/site-packages/minimalmodbus.py", line 904, in read_registers
    returnvalue = self._generic_command(
  File "/usr/local/lib/python3.9/site-packages/minimalmodbus.py", line 1245, in _generic_command
    payload_from_slave = self._perform_command(functioncode, payload_to_slave)
  File "/usr/local/lib/python3.9/site-packages/minimalmodbus.py", line 1322, in _perform_command
    response_bytes = self._communicate(request_bytes, number_of_bytes_to_read)
  File "/usr/local/lib/python3.9/site-packages/minimalmodbus.py", line 1490, in _communicate
    raise NoResponseError("No communication with the instrument (no answer)")
minimalmodbus.NoResponseError: No communication with the instrument (no answer)

Is this likely to be a cable issue or something software related?

ColoradoBills commented 2 years ago

I’ll second the request for detailed instructions.

markjsmith commented 2 years ago

Instructions would be great. I can see the integration in HACS but it won't load, keeps just showing as a newly available integration. Rebooting makes no difference. Update: I momentarily get a red flash stating "string index out of range" before it stops the install.

philjmaier commented 2 years ago

@ElD4n1 please help! Having issues connecting like some of the others here. I have HACS installed, added the custom repo from your github, now I have the Renogy Rover integration listed, but that's it.

I checked the Pi and 'ls /dev' shows my Rover 40A on ttyUSB2. I updated the renogy_rover.py file in the VS Code utility to change the ttyUSB0 to ttyUSB2. I also checked the host log file (system-logs-host) and you can see the ttyusb connections there.

Restarted and even rebooted the Pi.

The only thing I see is the Renogy Rover integration under HACS and a Renogy Rover Update card on the main dashboard.

Like others have said, what steps need to be taken after the integration is added to start reading the data from the Rover? Does something need to be added to configuration.yaml?

PS, I also have a Renogy DCC30 and a pair of 100AH Renogy heated Batts (daisy chained) so these are showing up as ttyUSB0, and ttyUSB1, fyi..

Thanks Daniel, Phil

philjmaier commented 2 years ago

@madninjaskillz , James, how did you get the logs to show even that? So far as I can tell, nothing of the renogy integration is being loaded. Did you add something to the configuration.yaml? I don't get that screen where it lets you choose the port either btw. Phil.

ElD4n1 commented 2 years ago

Hi guys, first of all, sorry for the late answer...It seems like my notification settings are wrong, because I did not get anything until I was mentioned directly by @philjmaier. I will check that!

minimalmodbus.NoResponseError: No communication with the instrument (no answer)

This seems like an issue with the cable. Probably the USB<->UART chip is recognized correctly but the connection is broken on the UART side. I am using the official cable and a DIY one. I know that they don't include it anymore unfortunately. Will post a picture of my DIY one later and then you can check against yours.

In general I would recommend choosing the entry that starts with /dev/serial/by-id, because the ttyUSB0 and ttyUSB1 are not deterministic and sometimes get swapped after a reboot if you have multiple devices attached.

ElD4n1 commented 2 years ago

I checked the Pi and 'ls /dev' shows my Rover 40A on ttyUSB2. I updated the renogy_rover.py file in the VS Code utility to change the ttyUSB0 to ttyUSB2. I also checked the host log file (system-logs-host) and you can see the ttyusb connections there.

Are you using a DIY cable or the official one from Renogy?

philjmaier commented 2 years ago

@ElD4n1 - For the rover I am using a USB-to-DB9 cable with a DB9 breakout, then the RJ12 wired to pins 1,2,3 like in the diagrams. I do have the stock Renogy USB-485 cables for the DCC30 and Batteries. Not for the Rover though.

philjmaier commented 2 years ago

These are my USB ports using the by-id: Screen Shot 2022-08-17 at 12 30 44 PM

So I should put this in the renogy_rover.py file instead of ttyUSB2?

if name == "main": rover = RenogyRover("/dev/ttyUSB2", 1)

to this: if name == "main": rover = RenogyRover("/dev/serial/by-id/usb-Prolific_Technology_Inc._Dtech_USB_Serial_Controller_EGA@e108Y20-if00-port0", 1) print("Model: ", rover.model())

ElD4n1 commented 2 years ago

@philjmaier Actually you should not need to change anything in the source code. The if __name__ == "__main__": section is only executed when starting the Python interpreter directly with the renogy_rover.py file and is only used for testing, i.e. it won't have any effect within Home Assistant.

Instead, please try the following: After you added the integration via HACS and restarted Home Assistant, go to "Settings" -> "Devices & Services" -> "Add integration" and search for "Renogy Rover". Then you should be asked for the COM port of your charge controller (choose the by-id entry here).

philjmaier commented 2 years ago

Ah, I see. Didn't realize that step. Screen Shot 2022-08-17 at 1 24 13 PM

So I did that but it doesn't take it: Screen Shot 2022-08-17 at 1 25 12 PM

Home Assistant log: This error originated from a custom integration.

Logger: custom_components.renogy_rover.config_flow Source: custom_components/renogy_rover/renogy_rover.py:70 Integration: Renogy Rover First occurred: 1:24:27 PM (4 occurrences) Last logged: 1:25:03 PM

Could not connect to device=/dev/serial/by-id/usb-Prolific_Technology_Inc._Dtech_USB_Serial_Controller_EGA@e108Y20-if00-port0 Could not connect to device=/dev/ttyUSB2 Traceback (most recent call last): File "/config/custom_components/renogy_rover/config_flow.py", line 37, in connect_and_read_device_info device_info[ATTR_SERIAL_NUMBER] = client.serial_number() File "/config/custom_components/renogy_rover/renogy_rover.py", line 70, in serial_number registers = self.read_registers(24, 2) File "/usr/local/lib/python3.10/site-packages/minimalmodbus.py", line 904, in read_registers returnvalue = self._generic_command( File "/usr/local/lib/python3.10/site-packages/minimalmodbus.py", line 1245, in _generic_command payload_from_slave = self._perform_command(functioncode, payload_to_slave) File "/usr/local/lib/python3.10/site-packages/minimalmodbus.py", line 1322, in _perform_command response_bytes = self._communicate(request_bytes, number_of_bytes_to_read) File "/usr/local/lib/python3.10/site-packages/minimalmodbus.py", line 1490, in _communicate raise NoResponseError("No communication with the instrument (no answer)") minimalmodbus.NoResponseError: No communication with the instrument (no answer)

ElD4n1 commented 2 years ago

Ok, this also looks like a cable problem. I guess the other two FTDI devices are your DCC30S?

Could you try it with one of the stock cables (unless it's not compatible with the Rover) to ensure that it's not the custom cable's fault?

philjmaier commented 2 years ago

They have RJ45 ends on the Renogy stock cables. The rover has an RJ12 connector.

Here's my cable (the adapter end that is): 20220817_133930

Swapped TX and RX (black and white wires) no change..

Here's the diagram I used: Screen Shot 2022-08-17 at 2 05 59 PM

philjmaier commented 2 years ago

@ElD4n1 , Daniel, if you think it's the cable, can you recommend one that works?

The renogy one is no longer offered in the RJ12/RS232 format.

ElD4n1 commented 2 years ago

Ok this looks like mine, except that I have soldered the wires to pin headers. Maybe its a contact problem? IMG_20220817_203035

Another possibility would be a wrong voltage level, maybe yours has 3.3V levels? I think it should be 5V, I just measured mine and it even had 6V.

I am using this adaptor: https://www.amazon.de/gp/product/B00QUZY4UG

philjmaier commented 2 years ago

Ya, mine were at 5-6v as well. Hmm. This is the cable I have: DTECH cable and the breakout adapter: DB9 breakout

philjmaier commented 2 years ago

@ElD4n1 , Daniel, are there any CLI commands I can type to see if there is any data coming though at the host level from terminal?

ElD4n1 commented 2 years ago

Ya, mine were at 5-6v as well. Hmm.

Ok then it should be fine.

@ElD4n1 , Daniel, are there any CLI commands I can type to see if there is any data coming though at the host level from terminal?

Not sure, might be difficult on Home Assistant OS. I think there is no data coming at all from the Rover, otherwise the modbus library would print a different error.

I'm not honestly not sure what else it could be other than a connection issue. Maybe an upgraded firmware or newer model than I have or something like that.

philjmaier commented 2 years ago

I reconnected the BT-1 and I get data to my phone app. So the port is still working.

ElD4n1 commented 2 years ago

Does it show hardware model and firmware version of the rover?

philjmaier commented 2 years ago

RNG-CTRL-RVR40, Version 3.0.1

ElD4n1 commented 2 years ago

It could be related with firmware version (see here). I will check which version I have tomorrow and maybe see if I can find more info if I have time.

philjmaier commented 2 years ago

It could be related with firmware version (see here). I will check which version I have tomorrow and maybe see if I can find more info if I have time.

..I hope not.

philjmaier commented 2 years ago

I ordered another cable with a FT232 chipset in it. Will see if that's it when it comes in: FT232 cable

ElD4n1 commented 2 years ago

Hmm yeah could be. Mine has a PL232 chipset too and I remember that I indeed got the same error after some hours of operation. After restarting HA it worked again though. I did not have this problem so far with the stock cable, which has a FT232 in it.

philjmaier commented 2 years ago

Did you get the firmware number of your Rover?

I also have a Wanderer 10 laying around I can test with. I did hook it up to the BT-1 and it's fine, but have same issue with the USB cable and HA as I am having with the Rover 40.

Joe13183 commented 2 years ago

I've had the same issue today. but giving up on this and trying the wildmountain solarthing showed me a clue In the setup it does a search through modbus addresses. The search came back with a connection and serial data on address 16. So I went back to this integration. SSH into pi, then cd config/custom_components/renogy_rover Then nano individually into init.py , config_flow.py and renogy_rover.py being very careful to only change the serial/com port number. init.py line to amend : hass.data.setdefault(DOMAIN, {})[entry.entry_id] = RenogyRover(entry.data[CONF_PORT], 1)

config_flow.py line to amend : client = RenogyRover(com_port, 1)

RenogyRover.py line to amend (right at the bottom) : rover = RenogyRover("/dev/ttyUSB0", 1)

I only amended the number 1 at the end of each line to 16. Then restart Home assistant and the adding the renogy integration worked. It's night time now so most things showing zero but battery voltage is showing the correct figure. Hopefully it shows output load but I'll mess with that over the weekend. Hopefully this works for you guys. Screenshot_20220819-002839_Home Assistant

philjmaier commented 2 years ago

In the setup it does a search through modbus addresses. The search came back with a connection and serial data on address 16.

Check the "Devices not detected" section at this link: Solarthing

They recommend 10, or 16 if 10 doesn't work.

philjmaier commented 2 years ago

WORKS !! Thanks everyone! Changing the address to 16 solved it. It now detects and adds the Rover device.

philjmaier commented 2 years ago

@ElD4n1 , Daniel, can you point me in the direction I need to go to create similar setups as yours here for my other Renogy pieces like the DCC30 and the 100AH batteries? If I can get it to work, others can use it.

Joe13183 commented 2 years ago

In the setup it does a search through modbus addresses. The search came back with a connection and serial data on address 16.

Check the "Devices not detected" section at this link: Solarthing

They recommend 10, or 16 if 10 doesn't work.

Yes it's all working now once the sun came up. I am using a homemade cable like yours

ElD4n1 commented 2 years ago

Nice job @Joe13183, thanks. I completely forgot about Modbus having addresses (which the name implies, actually). Also note I did not write the renogy_rover.py myself, but took it from the solarshed project, so I am not that of an expert of the underlying protocol.

However, I will add support for different addresses and maybe implement an address scan if there can be other addresses than 1, 10 or 16.

FYI: I also found a documentation of the protocol specific for Renogy Rover here: ROVER MODBUS.docx

@ElD4n1 , Daniel, can you point me in the direction I need to go to create similar setups as yours here for my other Renogy pieces like the DCC30 and the 100AH batteries? If I can get it to work, others can use it.

It seems like the Solarthing project already supports the DCC30 and other Renogy products, so maybe it already works out of the box if the same registers are used. Can you try to add it the same way as your Rover? Or wait until I fix the thing with the device addresses, maybe I find some time on sunday. Otherwise, I would also be happy for any PR :) I took most of the information to create this integration from the Home Assistant developer docs.

I found the relevant code for Renogy products on the Solarthing repo here.

philjmaier commented 2 years ago

@ElD4n1 , I did try that actually. But I left the working Renogy Rover 40, and tried to add another. It wouldn't take the other ttyusb or their by-id. My guess is I'd have to scrap the working one and try the different modbus addresses on the other devices. I'll wait until you make your changes. This is great though. Thanks all. I'll be here to test it once it's ready for sure!!

philjmaier commented 2 years ago

@ElD4n1 , Daniel, since I had to modify the modbus address in the files to get the first Rover 40 working, which it still is working with no issues, how do I go about adding additional ones?

Do the files I originally modified get used for each additional device, so every time I add a device, I play with the modbus address/by-id combo to get the new device added?

I have a Wanderer 10 which uses the RJ12 cable to test on.

ElD4n1 commented 2 years ago

@philjmaier I implemented a device address scan now.

Can you please test it by downloading the v1.1.0-beta.1 release? You can do this by going into HACS, click on the Renogy Rover integration, then on the three-dot-menu at the top right and then first click on the second button and then on the third button (not sure how it translated in English). image

Also you need to enable beta versions: image

Then, after restarting home assistant your Rover should work without any modifications of the source code and also you can test your DC-DC chargers.

philjmaier commented 2 years ago

@ElD4n1 , SWEET !! Works great !

The two prompts on the Renogy Rover Integration are "Update Information" and "Redownload".

I had to remove the original Rover 40 device. I added back in no problem without modifying any files.

Then I added another device, the DCC30S, also no problem! Screen Shot 2022-08-25 at 4 03 19 PM

Screen Shot 2022-08-25 at 4 09 58 PM

Nicely done Daniel ! How can I help out with the "I would also be happy for any PR :)" part ?

I will test the Wanderer 40 at some point as well as the Renogy Hub and see how the devices show up in there. I also have the 100AH batteries, so not sure what can be done there.

Phil

ElD4n1 commented 2 years ago

@philjmaier Glad to hear that it works now and for other products as well. Maybe I should change a few namings then and check what kind of product is connected. Just let me know if any metrics are missing that you are interested in.

How can I help out with the "I would also be happy for any PR :)" part ?

Well if you are eager to help you could for example write some more detailed instructions about how to add the integration in the Readme.md ;)

philjmaier commented 2 years ago

@ElD4n1 , ya sure, I can do that. How do you want me to submit them for review? Directly in the Readme.md? Not a huge github user..

As for the metrics, I'll look at the list and see.

One thing that would be helpful if possible, is to have a prefix to all the sensors so they are grouped together in the list and easier to find, something like "RNG" as an example. The suffix was good because it made it clear I was looking at the 2nd device as all the sensors had the same name followed by "_2".

One of my next steps is to bring this data into Influx and Grafana. Already this is a great improvement over the Renogy DC Home app.

ElD4n1 commented 2 years ago

@philjmaier

How do you want me to submit them for review? Directly in the Readme.md? Not a huge github user..

You would need to fork my repo, change the Readme.md (e.g. using the GitHub website directly), then create a pull request into this repo.

One thing that would be helpful if possible, is to have a prefix to all the sensors so they are grouped together in the list and easier to find, something like "RNG" as an example. The suffix was good because it made it clear I was looking at the 2nd device as all the sensors had the same name followed by "_2".

Yeah, would make sense, will look into that. When I change the sensor names now then the previous data in the HA DB will be lost I guess.

I will close this issue now. For any new feature requests, please open a new issue.