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

Adapter Request for Huawei SUN2000 Solar Inverter + Battery #894

Closed
badsnoopy667 opened this issue Oct 29, 2023 · 13 comments
Closed

Adapter Request for Huawei SUN2000 Solar Inverter + Battery #894

badsnoopy667 opened this issue Oct 29, 2023 · 13 comments
Labels
duplicate This issue or pull request already exists

Comments

@badsnoopy667
Copy link

The Huawei SUN2000 Solar Inverter and its battery (LUNA2000) can be accessed via Modbus to read information from them. This works in iobroker using Javascript or node-red.

However, I am not able to reliably WRITE data to the inverter. This is especially true for the "Force battery to charge from grid" feature that I want to use with the variable energy prices from tibber.

There seems to be a Home Assistant integration that can force charging among all other features.
Huawei HA integration (GitHub)

Is it possible to create an ioBroker Adapter based on the HA integration? That would be a great solution to even better utilize the features of the Huawei inverter!

Thanks so much!

@mcm1957 mcm1957 added the modbus sufficient? Is the Modbus Adapter maybe sufficient? label Oct 29, 2023
@mcm1957
Copy link
Collaborator

mcm1957 commented Oct 29, 2023

Does - to your knowledge - the modbus interface mot allow to write data to the Inverter?
Or does it simply fail to work?

As modbus connection eems to work at least for reading, I would suggest to ask for help at forum. If you assume a problem with the modbus adapter, please open a issue there,

I will kepp this request open - but in many cases it's not usefual to create a spezialized adapter for a device when general adapters are available..

@badsnoopy667
Copy link
Author

Writing does work to some extend. I am able to write the "maximum discharge power" of the battery using modbus. It only works with node-red though. The modbus adapter does not work because Huawei seems to be very picky with the timing of the modbus requests. Modbus adapter does not get a connection.

The problem with writing is, that it
a) Sometimes does not work when you read data in parallel. Thus, one must pause reading before writing for it to be reliable.
b) Huaweis documentation is (at least for my skills) not good enough to understand which modbus registers need be be written with what data to trigger forced battery charing from grid.

Especially because of b), I had hoped that porting the HA integration (that already can write the correct data) to ioBroker is my best shot at this!

@mcm1957
Copy link
Collaborator

mcm1957 commented Oct 29, 2023

Writing does work to some extend. I am able to write the "maximum discharge power" of the battery using modbus. It only works with node-red though. The modbus adapter does not work because Huawei seems to be very picky with the timing of the modbus requests. Modbus adapter does not get a connection.

The problem with writing is, that it a) Sometimes does not work when you read data in parallel. Thus, one must pause reading before writing for it to be reliable. b) Huaweis documentation is (at least for my skills) not good enough to understand which modbus registers need be be written with what data to trigger forced battery charing from grid.

So please open an issue at modbus adapter to analyze / fix the problem.

@badsnoopy667
Copy link
Author

That is a completely different issue.
As said, the connection does work with node-red and javascript.
The issue I am trying to adress here is that Huaweis documentation is so vague that it is really hard to figure out what data to send to the inverter to get it to work.
That the modbus adapter is not working is an entierly different issue that I has nothing to do with my request. Even with a working modbus adapter, the issue is still unsolved.
The HA integration has already solved the problem what data to write to the inverter.

@FranzKillig
Copy link

Hello,
I would also be happy about an adapter. I've already tried both. With NodeRed reading the data works with some error messages. However, I couldn't get the data writing to work. Reading and writing data works with Javascript via Modbus. However, not really reliable. It often happens that communication via Modbus is disrupted and the script has to be restarted. Another problem is that you cannot write values from another script into the objects. The only way to do this is via “simple-api”. That's why a convenient adapter like this one exists for other inverters would be very helpful.

NOTE: There are several versions of the Huawei manual with the descriptions of the data points in circulation. Version 3 is from 2020-10-22 and is much more informative.

greeting
Franz

@badsnoopy667
Copy link
Author

badsnoopy667 commented Nov 17, 2023

In the meantime I was able to get reading and writing to run using node-red in iobroker.
I have updated the instructions in the forum:
howto-huawei-sun2000-wr-modbus-mit-node-red-read-write
Using this method, it is also possible to trigger data writing from any other script by simply setting the correct objectIDs.
The manual also includes a link to the latest Modbus Interface Definitions pdf from Huawei, Version 5.

@bolliy
Copy link

bolliy commented Nov 18, 2023

I have a solution, but it is not yet implemented in an adapter. I currently have a js script running. If you are interested in the program code, please feel free to get in touch. Since my English is not good, I would prefer to speak in German.

@FranzKillig
Copy link

FranzKillig commented Nov 19, 2023 via email

@bolliy
Copy link

bolliy commented Nov 19, 2023

Hallo Franz,
ich habe auch noch keinen Adapter unter iobroker programmiert. Möchte mich aber gerne in Thematik einarbeiten. Als js script kann ich nun aber über modbus tcp auf den SUN2000 Solar Inverter zugreifen. Das sieht so aus:
//asynchrones Schreiben async function writeRegistersAsync(id,address,buffer) { try { await client.setID(ModBusIDs[id-1]); await client.writeRegisters(address,buffer); } catch (err) { console.error("Error received writing adress "+ address + " from id: " + ModBusIDs[id-1] + " with error: " + modbusErrorMessages[err.modbusCode], err); throw err; //Fehler weiterreichen } }

Über meine funktion "checkAnndPrepare" bereite ich den Wechselrichter für das "Time of Using charging" vor. Diese Einstellungen kannst du auch manuelle über die FusionSolar App vornehmen. Normalerweise steht das modbus Register 47086 auf 2 (Maximise self consumptions). Über die TOU (Register 47086 auf 5) Funktion in Verbindung mit ChargeFromGrid (47087 auf 1) kann ich nun aber den Inverter überreden den Speicher übers Netz zu laden.

https://support.huawei.com/enterprise/en/doc/EDOC1100186676/e8d2e6db/tou-time-of-use-mode und https://support.huawei.com/enterprise/de/doc/EDOC1100173562/5224833c

async function checkAndPrepare() { // Time of Using charging and discharging periodes (siehe Table 5-6) // tCDP[3]= 127 var tCDP = [1,0,1440,383,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; //nicht aus dem Netz laden let data = await readRegisterSpaceAsync(1,47086,4); /* 127 - Working mode settings 2 : Maximise self consumptions (default) 5 : Time Of Use(Luna) - hilfreich bei dynamischem Stromtarif (z.B Tibber) */ let workingMode = data[0]; // Working mode settings 2:Maximise self consumptio5=) let chargeFromGrid = data[1]; // Voraussetzung für Netzbezug in den Speicher (Luna) let gridChargeCutOff = data[2]/10; // Ab welcher Schwelle wird der Netzbezug beendet (default 50 %) let storageModel = data[3]; // Modell/Herrsteller des Speichers, 2 : HUAWEI-LUNA2000 try { if (storageModel == 2) { //wurde nur mit Luna getestet! if (workingMode != 5 || chargeFromGrid != 1 ) { console.debug('Row '+data+' Workingmode '+workingMode+ ' Charge from Grid '+chargeFromGrid+ ' Grid Cut Off '+gridChargeCutOff+'%'); await writeRegistersAsync(1,47086,[5,1,900]); //[TOU,chargeFromGrid,90%] await writeRegistersAsync(1,47255,tCDP); //Plan:1,StartZeit:00:00,EndZeit: 24:00,Endladen/täglich /* ggf. sinnvoll await writeRegistersAsync(1,47075,[0,5000]); //max. charging power await writeRegistersAsync(1,47077,[0,5000]); //max. discharging power */ } } } catch(err) { throw err; } }

nun kann einfach der Inverter zum Laden vom Netz (chargeFromGrid) aufgefordert werden. Der Status des "0_userdata.0.sun2000.ChargeFromGrid" (STATE-Datenpunkt) könnte über die "on" Funktion überwacht werden. Diese setzt dann eine globale Variable z.B. doChargeFromGrid auf true. Der Speicher würde beim Füllungsgrad von 90% auto. stoppen (siehe oben)

var lastChargeFromGrid; ..... async function processBattery() { try { var chargeFromGrid = getState("0_userdata.0.energyrouter.IO.StopDischarge").val if (typeof lastChargeFromGrid == "undefined" ||lastChargeFromGrid != chargeFromGrid ) { let tCDP = [1,0,1440,383,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; if (chargeFromGrid) tCDP[3] = 127; //charge from grid await writeRegistersAsync(1,47255,tCDP); lastChargeFromGrid = chargeFromGrid; } } catch (err) { throw err; } }
Die processBattery würde nun über setInterval in einem vorgegebenen Intervall aufgerufen werden.
Ist das so wie du dir das vorgestellt hast?
Stephan

@FranzKillig
Copy link

FranzKillig commented Nov 19, 2023 via email

@bolliy
Copy link

bolliy commented Nov 19, 2023

Hallo Franz, vielleicht sollten wir die Kommunikation lieber im https://forum.iobroker.net/category/5/iobroker-allgemein weiterführen. Legt doch dort einfach dein Thema an.

@mcm1957
Copy link
Collaborator

mcm1957 commented Dec 6, 2023

This adapter seesm to solve this issue:
https://github.com/daolis/ioBroker.sun2000-modbus

Request for Latest:
ioBroker/ioBroker.repositories#3007

@mcm1957 mcm1957 added InProgress modbus works The Modbus adapter works fine LATEST pending Request to accpet at lates repository is pending duplicate This issue or pull request already exists and removed modbus sufficient? Is the Modbus Adapter maybe sufficient? Requested InProgress modbus works The Modbus adapter works fine LATEST pending Request to accpet at lates repository is pending labels Dec 6, 2023
@mcm1957
Copy link
Collaborator

mcm1957 commented Dec 6, 2023

Finalization of adapter will be processed with related issue:
#752

@mcm1957 mcm1957 closed this as completed Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants