nygma2004 / growatt2mqtt Goto Github PK
View Code? Open in Web Editor NEWGrowatt Solar Inverter Modbus Data to MQTT Gateway
License: MIT License
Growatt Solar Inverter Modbus Data to MQTT Gateway
License: MIT License
Hi Csongor,
if there was a Modbus communication error, e.g. error = Response timed out
and communication is resumed normally, the MQTT topic "error" is not updated.
I think in ReadHoldingRegisters()
, the "error" topic should also be updated if the condition (result == growattInterface.Success)
is true (e.g. error = "none").
Besides, the message string should be put in double quotes, i.e. error = "Response timed out"
.
Regards
Matthias
Hi guys, since begin the use of Growatt I have built myself a small USB dongle to read growatt (https://github.com/Diddlik/USB_Dongle_ESP8266_Max485).
Now I plan to install export limit as well. A good project is here: https://github.com/alessandromatera/SDM230-emulator-growatt-esp-mqtt
What I want to achieve is that I have a stick, an ESP, which is connected to two RS485 converters.
One is used to read Growatt (pin 3/4) and the other Converter would be connected to pin 7/8 to act as a smart meter.
Is it possible to combine the Code of alessandromatera and yours?
The development of hardware part seems to be an easy step, but software part imho not so easy...
Hi,
I've found your great project and will use a part of your code on a arduino nano, to display the data on a oled display.
Yesterday I've received my MIC 1500TL-X, I have connected the RS485A1 and B1 to an usb-rs485 convertert, I've send several requests (read input an holding register) but get absolutely no answer.
Is it possible to help me with an example complete modbius request message, so I can send this over a terminal an check the connection.
(the RS485A2 B2 port works well, here I can see the requests of the inverter to smartmeter after activating this, so I think the USB Converter works)
Thanks a lot
Richard
Any chance we can also send the modbus data to the growatt server so it gets accepted in the shine app?
Would be great if it can be made like the grott apllication, acts as proxy.
https://github.com/johanmeijer/grott
Hi,
Thank you very much for providing this project!
I would like to use this for a LoRaWAN based variant. Which license applies to this project?
For most of my project, I'm favoring the MIT license.
Best regards
Matthias
Howzit man, nice project,
I have been trying to get an esp working with an spf5000es, the comm port is a usb type A which connects to the dongle. Check the thread below, others have managed to flash the dongle (which has an esp chip) and use with esphome.
Any ideas on how to get Comms with this from the usb A port and an esp32, possible wiring?
https://community.home-assistant.io/t/esphome-modbus-growatt-shinewifi-s/369171/51
Hey probably best directed to @joe288 ,
I'm trying to use the useModulPower function standalone like plugging in the ESP board like an usb stick and have it rewrite the
Inverter Config.
Tried adding the code to the Setup method after initializing the Interface but it won't update the config in the Inverter. All I'm getting is either illegal function or response timeout. Is there some special sauce that makes this work in the mqtt request or am I just going crazy.
Currently using a static string for that looks the same when compared to the mqtt message but maybe some encoding difference?
like in the Growatt2mqtt_1p2s.ino (removed mqtt code)
void setup()
{
//Other init code
String message = "OA";
growattInterface.initGrowatt();
growattInterface.writeRegister(growattInterface.regOnOff, 0);
delay(500);
result = growattInterface.writeRegister(growattInterface.regModulPower, int(strtol(message.c_str(), NULL, 16)));
delay(500);
growattInterface.writeRegister(growattInterface.regOnOff, 1);
delay(1500);
if (result == growattInterface.Success) {
holdingregisters = false;
} else {
//using WebSerial to send the result
}
}
have also tried it in loop() (multiple execution prevented)
Help would be appreciated.
Is it possible to enable/disable and change export limits via modbus for mic type inverters. seams not possible ?
Can you tell us which housing you designed the pub for?
Cheers Robert
Hi,
Great work with all the detailed explanations and even videos!
I have a similar repo which I'm using for quite some years now but since the netmetering policy is going to change I was looking for a way to control the output power. Seems that you have already implemented this :)
I have a MOD 9000 TL3-X so that is a 3 phase model. Since you named your folder 1ps2, do you also have a local 3p2s repo which you can share? Else I am going to fork yours and add the 3 phase registers.
Thanks,
Maarten
Hi,
What a great project you have made here, I follow you video and think I made a correct setup, however I get Error: Invalid slave ID on the MQTT
My Growatt is same as yours, MIN 3000TL-XE
I check the COM ID on Growatt it is set to 001
I try change it to 002 or 003 with the same change in Arduino sketch
I double check my wiring of Wemos D1 and TTl to RS-485 module, I have same 230V power supply as you show
No matter what I try it give me same error, do you have any idea where to look?
Hi, as far as i can see, you can set the maximum inverter output with mqtt by the command /setMaxOutputActive but this doenst work.
So i took a quick search in the code and found a line /setMaxOutput. Then i tried /setmaxOutput and it worked.
Just wanted to make you aware that esphome has a preliminary growatt component.
https://esphome.io/components/sensor/growatt_solar.html
https://github.com/esphome/esphome/tree/dev/esphome/components/growatt_solar
Maybe it would be even easier to maintain etc to enhance the esphome component with the communications you have made here.
I think that would be a good place to merge the project as that will make it easily availble to the arduino/home-assistant community.
Congrats on a nice project!
I am trying to port the code to a ESP32C3 (I have a few, and I've used them in several other projects), and I've commented pretty much everything except the core functionality (no ArduinoOTA, no NeoPixel, no MQTT data send), just some Serial.println()
debug messages for now.
I'm trying to talk to one (of a pair) of Growatt SPF3000TL inverters.
But if I flash the code (stripped down as above) I get "Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0)." (error repeated verbatim for future searches). I noticed you mentioned a WDT timeout in one of the videos, which got my attention, so hoping you may have some more insights.
My Timer ISR (same as your master code) calls ReadHoldingRegisters()
in the ino, which invokes growattInterface.ReadHoldingRegisters(json)
in growattInterface, of which the relevant entry point is:
uint8_t growattIF::ReadHoldingRegisters(char* json) {
uint8_t result;
ITimer0.stopTimer();
result = growattInterface.readHoldingRegisters(setcounter * 64, 64); //<< WDT panic is occurring here
// result = 0;
ITimer0.restartTimer();
If I comment the readHoldingRegisters
line and uncomment the result=0;
it runs fine.
Of course there could be several reasons something is timing out there - communications problem with the TTL to RS485 board (mine looks identical to the one you used), failed communications with the Growatt, etc, etc.
I would really like to drill down in to the growattInterface.readHoldingRegisters(setcounter * 64, 64)
call to try and figure out in more detail exactly what is timing out, so I can narrow it down, but I'm lost in the overloading of ReadHoldingRegisters
(either capitalized or not) in the ino, and also in the growattInterface class.
So a specific question: where do I find the code that growattInterface.readHoldingRegisters(setcounter * 64, 64)
invokes? grep etc is not helping.
I really like the clean ISR approach to invoking the code, but I'm stuck trying to use it at the moment.
Any insights really appreciated!
I try to apply this solution with Growatt SPH10k BH-UP hybrig inventer. I cannot get any response from the inverter.
Using osciloscope I see the data are repeatedly sent to inventer on the 485 link, but there is no response visible (and nothing in serial monitor).
Using 485-3 RJ-45 port on inverter, pins 1-B, 5-A
Slave ID is 1 as on the other Growatt inverters, speed 9600, checked in inverter registry.
What to do the get it worked?
Sorry, no way to contact you directly except via an issue ticket ;-)
Thanks for reverse engineering the inverter. Works like a charm.
However the "main" code seems to freeze.
I think while (!mqtt.connected()) is the root cause if the wifi is lost after the last wifi check, this code will never exit the loop, as the mqtt will not connect, because the wifi is lost.
Added all relevant parameters to the wifi manager (after which I save them to flash). Having to re-compile to change mqtt server settings is not my preferred solution. I have had issues with this on another ESP project. After 3+ years a mod was needed to the IP address of the server, and it did not compile anymore due to "progress" in the development tools.
Added jumper to force the wifimanager to show. For security reasons I want to be the one that brings up the wifimanagers or not. Rationale: after a power down of the ESP and a wifi reset (aka fuse switched off in the house), the ESP is up and running faster than the wifi, it cannot connect to wifi and shows the wifimanager. Which is "open" for everyone to connect. So now the wifimanager only shows when I set a jumper.
Added a FAN to cool the inverter. Inverter is in a hot spot under the roof. The SW uses the temperature from the electronics board inside the inverter to switch on/off.
Can send you my changes if you are interested.
Greetings Matthijs
Hello,
first at all...THANK YOU VERY MUCH TO CREATE SUCH A GREAT PROJECT!!!!
Now I am trying to implement additional data from "Growatt Inverter Modbus RTU Protocol":
https://www.photovoltaikforum.com/core/attachment/265072-pdfcoffee-com-growatt-inverter-modbus-rtu-protocolii-v120-english-pdf-free-pdf/
(I think this is the right protocol for my SPH4600 because values until "95" (tempboost) are ok)
To get the SOC I add to your "growattInterface.cpp":
if (setcounter == 15) { // Battery modbusdata.socinverter = growattInterface.getResponseBuffer(1014 - 960); }
and below the section:
setcounter++; if (setcounter == 2) { setcounter = 0; // Generate the modbus MQTT message sprintf(json, "{", json); sprintf(json, "%s \"status\":%d,", json, modbusdata.status); sprintf(json, "%s \"socinverter\":%.1f,", json, modbusdata.socinverter);
In "growattInterface.h" I added to section the "socinverter":
struct modbus_input_registers { int status; float solarpower, pv1voltage, pv1current, pv1power, pv2voltage, pv2current, pv2power, outputpower, gridfrequency, gridvoltage; float energytoday, energytotal, totalworktime, allphaseenergy, gridpowertolocalload, energyp3, pv1energytoday, pv1energytotal, pv2energytoday, pv2energytotal, opfullpower; float dischargepower, chargepower, socinverter, batsoc; float tempinverter, tempipm, tempboost; int ipf, realoppercent, deratingmode, faultcode, faultbitcode, warningbitcode; };
As MQTT feedback I received a "0" :-(
("socinverter": 0)
Did I something wrong to define "setcounter"???
Let me preface this with saying I am an absolute beginner on arduino etc. (webdeveloper with some c# experience)
But would it be possible to adapt this library to use this over the usb connection on the MIC 600 TL-X or do I need the RS485 cable connection?
And with the RS485 would I use the COM port as I don't see a "Sys Com" port on the inverter.
As far as I can google the usb is apparently just an RS232 wrapper.
Hi,
I forked your software and made some changes. I saw your comments, if stabillity is no so good and OTA firmware update not working
I have tested it with my Growatt, run fine, Firmware update via OTA works fine well.
Helge
Hello,
Thank you for sharing this project. I recently has a solar system installed with the above Growatt inverter and I'm trying to get basic data from it into Home Assistant (HA). I've tried some of the HA integrations that pull from the Growatt server but these suffer from being blocked. So I thought I might be able to pull the data from the Modbus registers.
Your project looks like it could work if I pull the data from MQTT, however the SYS-COM definitions in the manual for my inverter differs from the one you show. (see following image of manual)
Do you think it might work ? which of the ports from sys-com should I use ?
Sorry for the simple questions, very much of this is new to me.
Hello,
I would like to use the data from growatt2mqtt for EVCC
EVCC propsed following for Growatt inverter:
(https://docs.evcc.io/docs/devices/meters)
`meters:
name: my_grid
type: template
template: growatt-hybrid
usage: grid
modbus: rs485serial
id: 1
device: /dev/ttyUSB0 # USB-RS485 Adapter Adresse
baudrate: 9600 # Prüfe die Geräteeinstellungen, typische Werte sind 9600, 19200, 38400, 57600, 115200
comset: "8N1" # Kommunikationsparameter für den Adapter
modbus: rs485tcpip
id: 1
host: 192.0.2.2 # Hostname
port: 502 # Port
modbus: tcpip
id: 1
host: 192.0.2.2 # Hostname
port: 502 # Port`
Is it possible to implement here the growatt2mqtt data?
or
I found also an older generic format of evcc:
`meters:
As I understood, this is refering directly to modbus data.?
But I don't know how to use.
Is the "uri" the IP of my Inverter or from D1-mini with growatt2mqtt?
"id" = ?
"address" = modbus id of Growatt protocol? ("1" for "Input power (high)", ...)
I am sure it is possible, but I was not able to solve.
Hello, I wanted to make a request to see if it is possible. I would like to retrieve the data of energy exported to the grid or otherwise the energy imported from the grid. In my case I have a meter connected to the growatt inverter, since it is obligatory in Spain.
I can see that data on the web, but I can't figure out what it is in modbus. How would it be possible to obtain this information? Thank you very much.
I am trying to help a friend monitor his inverters (5 x SPF5000TL HVM-P, arranged as 2 each in parallel on phase A and B, and 1 on phase C) and batteries (4 x Narada 48NPFC100). He has no ShineWifi dongles - apparently these inverters make use of the ShineWifi-F model, which talks RS232 over the USB D+ and D- lines of the USB-A connector.
I have been able to create an ESP32-based device with an SP3232 RS232 transceiver that can talk to one inverter via the USB-A connector. Now I am trying to figure out how best to communicate with the remaining inverters, and the batteries.
With the RS232 connection to a single inverter, and trying to brute force enumerate modbus slave addresses, I was able to find 1 (expected), and 17. I was wondering whether 17 would be the paralleled inverter, 17 == 16+1 or 0b1001, but the readings I got from address 17 were totally inconsistent with the readings from address 1. Lots of 65536 values. Anyone have any idea what might be at address 17?
I'm totally open to switching over to RS485 if it will make life easier in any way. That said, all I have read in the Growatt manuals has not provided any way of changing the modbus slave address from the default 1, which would mean that I would need a RS485 bus for each inverter regardless, to avoid conflict. In which case, since the RS232 transceiver chip I am using has two channels already, and the ESP32 can support up to 3 UARTs simultaneously, I could just use one ESP32 per phase to talk to two inverters, and add an RS485 transceiver to the C-phase ESP32 to talk to the batteries. That said, is it even necessary to query the paralleled inverter, should the readings not theoretically be the same as the primary?
Any other suggestions?
Hi,
Can you publish the schematic diagram of the interconnects ?
Thans in advance!
I had to add: PubSubClient and didn't find: SoftwareSerial ?
Growatt2mqtt_1p2s.ino
.
.
10 // - SoftwareSerial (didn't find this?)
11 // - PubSubClient (had to install this one)
BR Eirik - Norway
First of all I just want to say thank you for this project. I've got it working with my Growatt inverter and learned so much in the process.
I use Home Assistant and the trickiest part was figuring out how to import the values, I achieved this by adding MQTT sensors to my configuration.yaml
but it's a hacky solution.
sensor:
- platform: mqtt
name: 'Growatt Solarpower'
state_topic: 'growatt/data'
value_template: '{{ value_json.solarpower }}'
unit_of_measurement: 'W'
device_class: power
- platform: mqtt
name: 'Growatt Enery Today'
state_topic: 'growatt/data'
value_template: '{{ value_json.energytoday }}'
unit_of_measurement: 'kWh'
device_class: energy
I was wondering if you might add the functionality to publish the sensors from your sketch into the `homeassistant/sensor/growatt' topic, as this would allow Home Assistant auto-discovery:
I borrowed this example from another solution:
Topic :homeassistant/sensor/inverter_1_pv_power/config
{"device":{"ids":["sa_inverter"],"mdl":"Growatt MIN/MIC","mf":"Growatt","name":"Growatt MIN/MIC"},"device_class":"power","name":"PV power","state_topic":"solar/inverter_1/pv_power/state","uniq_id":"inverter_1_pv_power","unit_of_measurement":"W"}
Have to say that this code works fine with this 6kw 3phase model. Only problem is that I can't get voltages from different phases.
Can I somehow scan all the messages that growat sends so I could check em if it sends them?
Hi Csongor,
at first i want to thank you very much, for your work here and also on Youtube. I'm one of your subscriber and have to say, i have learned a ton from what you do and explain... in an age of >55 ;-) Thank you man!
So now, i want to inform you there is a register mismatch and failure in the code For MIC-TL-X.
I do not get total- or today-energy values in mosquitto or influx. I've checked the register with the Growatt Inverter Modbus RTU Protocol V.1.2 and it says on the very first page:
Instruction: Register range for various types of inverter
TL-X (MIN Type): 03 register range: 0-124, 3000-3124; 04 register range: 3000-3124, 3125-3249
...
Storage (MIX Type): 03 register range: 0-124, 1000-1124; 04 register range: 0-124, 1000-1124
...
So, there is no input register type range (04) 0 - 124 in the MIC TL-X devices, only 3000-3124 also not even the (04) 3125-3249 range like the manual says.
your code: growattinterface.cpp:
modbusdata.energytoday = ((growattInterface.getResponseBuffer(53) << 16) | growattInterface.getResponseBuffer(54)) * 0.1;
modbusdata.energytotal = ((growattInterface.getResponseBuffer(55) << 16) | growattInterface.getResponseBuffer(56)) * 0.1;
modbusdata.totalworktime = ((growattInterface.getResponseBuffer(57) << 16) | growattInterface.getResponseBuffer(58)) * 0.5;modbusdata.pv1energytoday = ((growattInterface.getResponseBuffer(59) << 16) | growattInterface.getResponseBuffer(60)) * 0.1;
modbusdata.pv1energytotal = ((growattInterface.getResponseBuffer(61) << 16) | growattInterface.getResponseBuffer(62)) * 0.1;
The Growatt RTU Protocol Description for MIC-TL-X input (04) registers says:
3053 | Epv_total H | PV energy total
3054 | Epv_total L | PV energy total
3055 | Epv1_today H | PV1 energy today
3056 | Epv1_today L | PV1 energy today
3057 | Epv1_total H | PV1 energy total
3058 | Epv1_total L | PV1 energy total
Please, could you maybe check and correct this?
Greetings from Karlsruhe/Germany
Tom
I just tried to set the ModulPower only get a response of Illegal Function.
Question is what Firmware version does this work with.
Mine is v1.2.0p2s
just to make sure it's the fact that I use this over the usb interface instead and not just growatt locking the function in a more up to date firmware.
Hi,
what must i change in code to use
topicroot/write/setMaxOutput | subscribe | 0-100 | set the output level of the growatt in percent
as described in documentation?
Micha.
Hello,
I have a question about the hardware.
you use 5V for your circuit. The ESP generates the 3.3V for the core voltage from this. This means that you would actually need a level shifter between ESP and MAX.
Will it work without one?
Thanks
BR
Stumpf
Hi,
Really useful code! I'm implementing it now for my Growatt inverter. As Growatt modbus addresses meanings are not very well documented, I wonder if you know which is the address (if exists) to read smart meter data related to exported/imported instant power.
Thanks in advance!
Here’s some information on my communications configuration: My battery is managed by a Batrium of which is monitoring 8 separate batteries via the Batrium system. The Batrium is communication with my Victron Cerbo GX and is throttling and controlling my charge controllers (Victron) and it is working perfectly, no issues. I am able to see the Growatt inverter output using Energy Meters which are connected to the Cerbo GX, no issues. I am also able to see my AC input into the Growatt inverters should the situation call for grid input. I am again using Energy Meters to communication this information to the Cerbo GX, no issues. The information I need to send back to my Growatt is the State of Charge of the battery. The reason I need the Growatts to see the SOC of the battery is to switch from battery to grid should I drop below a State of Charge percentage that I determine. I would also like the Cerbo GX to be able to show the status of the inverters such as On/Off position, errors, ect. I have two Growatt SPF 12000T DVM inverters running two separate AC load banks Any way this can be done?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.