ioBroker / AdapterRequests

This Place is used to track the status of new Adapter-Requests.
247 stars 36 forks source link

Adapter Request for Huawei SUN2000 Solar Inverter + Battery #894

Closed badsnoopy667 closed 5 months ago

badsnoopy667 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

Hallo Bolliy,

danke für dein Angebot, aber ich kann leider auch kein Adapter erstellen. Mein Englisch ist auch nicht so toll, aber bei Github kommt man mit dem Google-Übersetzer in der Regel gut durch.

Deshalb würde ich an deiner Stelle das Angebot mit deinem Skript doch mal dort im Forum machen.

Kann man in die Objekte die dein Skript erzeugt direkt aus einem anderen Skript Werte schreiben? Bei dem Skript das ich verwende, welches aus dem Web stammt und um die Schreibfunktion erweitert wurde funktionier das nämlich nicht.

Gruß und schönen Sonntag noch.

Franz

Von: bolliy @.> Gesendet: Samstag, 18. November 2023 18:26 An: ioBroker/AdapterRequests @.> Cc: Franz Killig @.>; Comment @.> Betreff: Re: [ioBroker/AdapterRequests] Adapter Request for Huawei SUN2000 Solar Inverter + Battery (Issue #894)

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.

— Reply to this email directly, view it on GitHub https://github.com/ioBroker/AdapterRequests/issues/894#issuecomment-1817576627 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ2RKG2DBTJV5S4N5GPLCELYFDVTZAVCNFSM6AAAAAA6UWQK2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJXGU3TMNRSG4 . You are receiving this because you commented. https://github.com/notifications/beacon/AQ2RKG6O2SPKYSP4NNZBWWTYFDVTZA5CNFSM6AAAAAA6UWQK2SWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTMKYCLG.gif Message ID: @.***>

bolliy commented 5 months ago

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 commented 5 months ago

Hallo,

da deine Anleitung auf Deutsch ist, können wir wahrscheinlich auch direkt auf Deutsch kommunizieren. Zumal mein Englisch eh nicht so toll ist.

Ich habe das aktuelle Flow in Notered importiert (vorher alle Unid-ID auf 1 gestellt) und dann entsprechen konfiguriert. Leider habe ich zwei Phänomene

bei den ich nicht dahinter komme, was es sein kann.

Zum einen werden nicht alle aktiven Nodes als Objekte angelegt, obwohl „Create states if not exist“ ausgewählt ist.

Zum anderen habe ich ständig diese Meldungen im LOG:

2023-11-19 17:18:17.896

info

State value to set for "0_userdata.0.Huawei.Inverter.Input_Power" has to be stringified but received type "number"

2023-11-19 17:18:15.469

info

State value to set for "0_userdata.0.Huawei.Meter.Active_Power" has to be stringified but received type "number"

2023-11-19 17:18:14.622

info

State value to set for "0_userdata.0.Huawei.Battery.Battery_Max_Discharge_Power_TEST" has to be type "number" but received type "object"

2023-11-19 17:18:09.874

info

State value to set for "0_userdata.0.Huawei.Inverter.Input_Power" has to be stringified but received type "number"

2023-11-19 17:18:08.887

info

State value to set for "0_userdata.0.Huawei.Meter.Active_Power" has to be stringified but received type "number"

2023-11-19 17:18:03.642

info

State value to set for "0_userdata.0.Huawei.Inverter.Input_Power" has to be stringified but received type "number"

2023-11-19 17:18:03.157

info

State value to set for "0_userdata.0.Huawei.Meter.Active_Power" has to be stringified but received type "number"

2023-11-19 17:18:00.405

info

State value to set for "0_userdata.0.Huawei.Inverter.Input_Power" has to be stringified but received type "number"

Bei einigen steht der Wert zwar auf „Object“ gar nicht auf „Stringfield“ aber auch ein umstellen auf „Number“ bring nichts.

Hast du da eine Idee?

Gruß

Franz

Von: badsnoopy667 @.> Gesendet: Freitag, 17. November 2023 11:38 An: ioBroker/AdapterRequests @.> Cc: Franz Killig @.>; Comment @.> Betreff: Re: [ioBroker/AdapterRequests] Adapter Request for Huawei SUN2000 Solar Inverter + Battery (Issue #894)

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 https://forum.iobroker.net/topic/51639/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.

— Reply to this email directly, view it on GitHub https://github.com/ioBroker/AdapterRequests/issues/894#issuecomment-1816128883 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ2RKG4HCY6KH6ZULGLI7QTYE45BNAVCNFSM6AAAAAA6UWQK2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJWGEZDQOBYGM . You are receiving this because you commented. https://github.com/notifications/beacon/AQ2RKG7ZAJUQLLUOZYUHQQTYE45BNA5CNFSM6AAAAAA6UWQK2SWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTMH7WXG.gif Message ID: @. @.> >

bolliy commented 5 months ago

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 commented 5 months ago

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

Request for Latest: https://github.com/ioBroker/ioBroker.repositories/pull/3007

mcm1957 commented 5 months ago

Finalization of adapter will be processed with related issue: https://github.com/ioBroker/AdapterRequests/issues/752