Skip to content

Python Script to Request and Read Data from the Sofar HYD6000-ES Inverter RS422 Port and Write To EmonCMS

License

Notifications You must be signed in to change notification settings

AndyWhittaker/HYD6000

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

title author tags categories date
Sofar HYD6000-ES ModbusRead
Andy Whittaker
Modbus, Node-RED, Emon, RS485, Sofar Inverter, Hybrid, HYD6000-ES
Solar PV
2020-05-28

Sofar HYD6000-ES ModbusRead

This is a very badly written Python Script to Request and Read Data from the HYD6000 Inverter RS485 Port and Write To EmonCMS (or EmonPi).

Since we require the script to be called at regular intervals, I have also included a very simple Node-RED script to call the Python code (currently) at 30 second intervals.

Interfacing with the HYD6000

We require to interface between the Raspberry Pi and the Sofar HYD6000 inverter via RS485. On the bottom of the HYD6000 you can find the interface connections.

Sofar HYD6000 Interfaces

The CAN/485m connection goes off to the batteries. However, the next interface available is the RS485s connection, Sofar even gives you the correct connector to plug-in (it looks to me like a Phoenix/ Weidmüller Type).

We now need a cheap USB to RS485 (which is a two wire interface) to allow us to connect to our Raspberry Pi. Note RS485 is completely different from RS232, do not attempt to use the wrong interface. log-on to eBay and search for RS422 interfaces and you will have one in your possession within a few days. If you would like to read up about the differences between RS232, RS422 and RS485, please have a short Google search for them. RS422 and RS485 are similar, just full-duplex verses half-duplex.

RS485 Interface

Link the interface up with the inverter with a length of CAT5 pair of wire. Be sure to match-up the + and - connections on either end. In my case, TX- connects to D- and TX+ connects to D+.

Modbus

A quick word on the inverter (and almost all that I have seen) is that they communicate over the ModBus Protocol. This is entirely different from whether you are connected via RS232, RS422, RS485, TCP/IP, etc.

They have been used for Industrial Applications since the beginning of time! You can’t talk to them via a terminal by randomly typing in commands, nothing will work. You need a ModBus (generally) RTU emulator but the good news is that there are many available to download.

Setting up the Raspberry Pi

EmonPi

The guys over at openenergymonitor.org have created a really easy guide to have your Raspberry Pi up and running with emoncms in no time. If you would like to use emonpi head along to their GitHub repository and follow the instructions.

Don’t forget to do the usual sudo apt update && sudo apt full-upgradeafterwards to ensure your Pi is up to date. While you are setting up, make sure you enable SSH access so that you don’t have to connect a monitor and keyboard while you set the whole thing up.

For SSH access I love the Bitvise SSH Client because it not only allows you to bring up the remote bash console but it also enables you to exchange files with your PC. This is incredibly valuable when you are developing or setting up the Pi. It also allows you to copy to other UNIX devices as well.

On the PC end, I think NotePad++ is the editor to use at the moment.

USB Interface

Plug the USB RS485 interface into a spare USB port and reboot the Pi. SSH back in and type dmesg | grep ttydmesg displays a copy of the Pi’s boot log and grep does a search through it for anything that matches tty. This will give you the port number that your interface is attached to (look for ttyUSB0 or similar).

Once you know the USB port name, you will have to update its name within the sofar.py file, look for instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1) # port name, slave address.
For debugging, simply remove the comment lines (#) in front of the print statements.

Executing the Code

Assuming you can see sofar,py when you type “ls”, then to run it type python sofar.pyIf you get any errors, you are probably missing some python libraries which you will need to install using “pip”. Google is your friend here.

Node-RED

If your script is working, you need a way of executing it every, say, 30 seconds to log to the emonCMS database to give you pretty graphs to bore your friends with.

Node-RED Timer Script

The node-RED setup actually took me the longest to complete. I was looking everywhere to find a solution and downloading libraries and all sorts. In the end it was quite easy.
If you would like the above flow, it’s available in the repository under flows.json.

The Future

Everything we all do is never finished. I would like to get the script to write to my Domoticz server and, in future, instruct the inverter to charge up its batteries during cheap rate electricity.

Oh, did I mention batteries? I have adopted PylonTech US3000 units because they seem to be the best value units on the market (2020). Although this inverter will allow you to charge from your mains supply, this is actually frowned upon (i.e. illegal) here in the UK because every time you discharge the batteries, they are being metered as energy from your SolarPV panels. If you were to charge them from the mains during the night, you will probably be visited by some very angry men who will be in no mood for humour…

An alternative that anyone could do is to use the LuxPower LXP 3600ACS inverter. This is just wired up to your mains supply and is able to charge the batteries when it sees your system trying to export to the grid. By clever voltage monitoring, if export drops, it then discharges the batteries into your home. From what I can see, the Lux LXP 3600ACS is able to be monitored and controlled by ModBus. The only downside is that these inverters are limited to a maximum discharge load of 3600W unless you run them in parallel.

About

Python Script to Request and Read Data from the Sofar HYD6000-ES Inverter RS422 Port and Write To EmonCMS

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages