Closed RikBast closed 1 year ago
Ok, I need to check these variables and see.
Thx for sharing:-)
Charge/Discharge still give crazy graphs :-(
for the battery, the power graphs seem OK (lot of sun today, battery charged a lot and I was even fully autonomous for 5 hours. The energy graphs are effectively weird. The energy data we use seem fine (increasing) though).
The weekly graphs (day by day) for energy seem fine:
I have these for the battery:
Hi,
already one thing for the solar panel total: it seems that the data to be used is from the getDevRealKpi API as well. In my case (residential inverter, type 38), it is "total_cap", so for it is not going backwards (as the total_power from getStationRealKpi api does). This is for the "energy" for the graph having "mppt_power" for the "power". As I understood, your inverter is another type (1), and you have the "total_cap" value, but also the "mppt_total_cap" value. I do not know which one you should use.
Probably need some help with programming, can you share your code?
First, I just saw a very bad thing in the database, MultiMeter:
18,1040,380,1.84467440737095e+19,0,0,0,"2022-10-06 11:40:00"
18,1040,380,1.84467440737095e+19,0,0,0,"2022-10-06 11:45:00"
18,1040,380,1.84467440737095e+19,0,0,0,"2022-10-06 11:50:00"
18,1040,630,1.84467440737095e+19,0,0,0,"2022-10-06 11:55:01"
So, as from yesterday, I keep everything (the results from the API and the logs), I found that the weird HUGE value (1.84467440737095e+19) is the result of the data sent by the Huawei system. Instead of an usual integer value for "ch_discharge_power", it sent "1022.9999999999999"... which is indeed valid for Huawei, because the value is a double...
{"data":[{"devId":1000000035363268,"dataItemMap":{"max_discharge_power":4400.0,"max_charge_power":5000.0,"battery_soh":0.0,"busbar_u":433.9,"discharge_cap":1.04,**"ch_discharge_power":1022.9999999999999**,"run_state":1,"battery_soc":4.0,"charge_cap":0.38,"ch_discharge_model":1.0,"battery_status":2.0}}],"failCode":0,"message":null,"params":{"currentTime":1665049081429,"devIds":"1000000035363268","devTypeId":39},"success":true}
{"data":[{"devId":1000000035363268,"dataItemMap":{"max_discharge_power":4400.0,"max_charge_power":5000.0,"battery_soh":0.0,"busbar_u":434.4,"discharge_cap":1.04,**"ch_discharge_power":1022.9999999999999**,"run_state":1,"battery_soc":6.0,"charge_cap":0.63,"ch_discharge_model":1.0,"battery_status":2.0}}],"failCode":0,"message":null,"params":{"currentTime":1665050041104,"devIds":"1000000035363268","devTypeId":39}
Do not take anything for granted :-)
We need to make sure the "Watts" value returned by the API are really integer (no issue with the "kW" values from the API, because we convert them " * 1000 / 1" which render them integer.
A code like this:
IntVal=$(echo "scale=0; (${FloatVal} + 0.5) / 1" | bc | sed 's/^\./0./')
Not yet a solution to the energy graph problems though.
Hi, already one thing for the solar panel total: it seems that the data to be used is from the getDevRealKpi API as well. In my case (residential inverter, type 38), it is "total_cap", so for it is not going backwards (as the total_power from getStationRealKpi api does). This is for the "energy" for the graph having "mppt_power" for the "power". As I understood, your inverter is another type (1), and you have the "total_cap" value, but also the "mppt_total_cap" value. I do not know which one you should use.
Probably need some help with programming, can you share your code?
My code is for a type 38, therefore, I added the retrieval of "total_cap" after the retrieval of "mppt_power":
myCurrentMPPTkW=$(cat $mydir/inverterdevicerealtime.$$ |jq '.data[]|."dataItemMap".mppt_power' | bc | sed 's/^\./0./')
myTotalCapkWh=$(cat $mydir/inverterdevicerealtime.$$ |jq '.data[]|."dataItemMap".total_cap' | bc | sed 's/^\./0./')
And where the update of the Domoticz sensor "DomoticzHuaweiGeneratedRealTime" is done, I replaced "svalue=$myCurrentW;$myTotalWh" with "svalue=$myCurrentMPPTW;$myTotalCapWh":
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiGeneratedRealTime&nvalue=0&svalue=$myCurrentMPPTW;$myTotalCapWh"
But, as I said, you have another type of inverter, maybe you need "mppt_total_cap" instead of "total_cap" for the Total production of the PV ?
Regarding the weird energy graphs, I think I have an idea: as suspected (2 days ago), I was not sure that the "charge_cap" and "discharge_cap" were continuously increasing, or reset every day.
I am now quite sure they are reset every day :-(
18|6510|2180|909|0|0|0|2022-10-06 00:05:00
18|100|0|912|0|0|0|2022-10-06 00:10:00
Discharge Cap: goes from 6510 to 100 Charge Cap: goes from 2180 to 0
We need to cope with that.
One way is to keep for each ChargeCap and DischargeCap 2 Domoticz variables: Charge Cap:
Discharge Cap:
The pseudo-code (to be executed for both "discharge_cap" and "charge_cap") will be:
totalEnergyYesterday = get TotalEnergyYesterday from domoticz variable
previousDailyEnergy = get PreviousDailyEnergy from domoticz variable
dailyEnergy = get new data from getDevRealKpi API (for "discharge_cap" or "charge_cap")
if dailyEnergy < previousDailyEnergy
then
totalEnergyYesterday = totalEnergyYesterday + previousDailyEnergy
set totalEnergyYesterday into domoticz as totalEnergyYesterday
end if
set PreviousDailyEnergy into domoticz as dailyEnergy
totalEnergy = totalEnergyYesterday + dailyEnergy
Actual code will follow :-)
Here it is (a bit late for tonight..., new behaviour to be checked Saturday morning :-) Beware: code not really tested, please double check if I did not mix variable names (charge/discharge), etc.
Variables to define in "HuaweiSolar.env": (similar scheme as myDomoticzHuaweiTokenTimeStampID and myDomoticzHuaweiTokenTimeStampName)
=========================================
TotalEnergyYesterdayID_ChargeCap
TotalEnergyYesterdayName_ChargeCap
PreviousDailyEnergyID_ChargeCap
PreviousDailyEnergyName_ChargeCap
TotalEnergyYesterdayID_DischargeCap
TotalEnergyYesterdayName_DischargeCap
PreviousDailyEnergyID_DischargeCap
PreviousDailyEnergyName_DischargeCap
Code to put before the line " # Store the values over the json interface in Domoticz":
=======================================================================================
# Charge Cap
totalChargeEnergyYesterday=$(curl -s "$myDomoticzURL/json.htm?type=command¶m=getuservariable&idx=$TotalEnergyYesterdayID_ChargeCap"|jq '.result[].Value'|tr -d '"')
Echo "Stored totalChargeEnergyYesterday =" "$totalChargeEnergyYesterday"
previousDailyChargeEnergy=$(curl -s "$myDomoticzURL/json.htm?type=command¶m=getuservariable&idx=$PreviousDailyEnergyID_ChargeCap"|jq '.result[].Value'|tr -d '"')
Echo "Stored previousDailyChargeEnergy =" "$previousDailyChargeEnergy"
if [[ $myCurrentChargeCapkWh < $previousDailyChargeEnergy ]]; then
totalChargeEnergyYesterday=$(echo "(${totalChargeEnergyYesterday} + ${previousDailyChargeEnergy})" | bc | sed 's/^\./0./')
Echo "New totalChargeEnergyYesterday =" "$totalChargeEnergyYesterday"
# update Domoticz with new totalChargeEnergyYesterday
curl "$myDomoticzURL/json.htm?type=command¶m=updateuservariable&vname=$TotalEnergyYesterdayName_ChargeCap&vtype=1&vvalue=$totalChargeEnergyYesterday"
fi
# update Domoticz with myCurrentChargeCapkWh as new previousDailyChargeEnergy
curl "$myDomoticzURL/json.htm?type=command¶m=updateuservariable&vname=$PreviousDailyEnergyName_ChargeCap&vtype=1&vvalue=$myCurrentChargeCapkWh"
myCurrentChargeCapkWh=$(echo "(${totalChargeEnergyYesterday} + ${myCurrentChargeCapkWh})" | bc | sed 's/^\./0./')
Echo "Corrected myCurrentChargeCapkWh =" "$myCurrentChargeCapkWh"
# Discharge Cap
totalDischargeEnergyYesterday=$(curl -s "$myDomoticzURL/json.htm?type=command¶m=getuservariable&idx=$TotalEnergyYesterdayID_DischargeCap"|jq '.result[].Value'|tr -d '"')
Echo "Stored totalDischargeEnergyYesterday =" "$totalDischargeEnergyYesterday"
previousDailyDischargeEnergy=$(curl -s "$myDomoticzURL/json.htm?type=command¶m=getuservariable&idx=$PreviousDailyEnergyID_DischargeCap"|jq '.result[].Value'|tr -d '"')
Echo "Stored previousDailyDischargeEnergy =" "$previousDailyDischargeEnergy"
if [[ $myCurrentDischargeCapkWh < $previousDailyDischargeEnergy ]]; then
totalDischargeEnergyYesterday=$(echo "(${totalDischargeEnergyYesterday} + ${previousDailyDischargeEnergy})" | bc | sed 's/^\./0./')
Echo "New totalDischargeEnergyYesterday =" "$totalDischargeEnergyYesterday"
# update Domoticz with new totalDischargeEnergyYesterday
curl "$myDomoticzURL/json.htm?type=command¶m=updateuservariable&vname=$TotalEnergyYesterdayName_DischargeCap&vtype=1&vvalue=$totalDischargeEnergyYesterday"
fi
# update Domoticz with myCurrentDischargeCapkWh as new previousDailyDischargeEnergy
curl "$myDomoticzURL/json.htm?type=command¶m=updateuservariable&vname=$PreviousDailyEnergyName_DischargeCap&vtype=1&vvalue=$myCurrentDischargeCapkWh"
myCurrentDischargeCapkWh=$(echo "(${totalDischargeEnergyYesterday} + ${myCurrentDischargeCapkWh})" | bc | sed 's/^\./0./')
Echo "Corrected myCurrentDischargeCapkWh =" "$myCurrentDischargeCapkWh"
BTW, currently, graph is fine, even without the new code... I guess it degrades during the day, as new values pour...
Correction about the location where to put the "cumulative" code: in order for it to run only if the data are available, it is better to put it after those lines:
if [ -z $myCurrentChargeDischargeW ]
then
myCurrentChargeDischargeW="-N/A-"
myCurrentChargeCapWh="-N/A-"
myCurrentDischargeCapWh="-N/A-"
else
Beware that maybe the names of the values are a bit different for you (I renamed some of them for consistency, adding the kWh for instance for "myCurrentChargeCapkWh".
BTW, currently, graph is fine, even without the new code... I guess it degrades during the day, as new values pour...
Your batteries charge slower then my small 5kWh battery it seems :-) And after 0.00 drop to zero again.
Regarding autonomous, my usage in the house is pretty low (no big pond to heat ;-) ) In the morning my battery has about 10-15% left and then starts charging again. This scenario works most of the time I noticed. On bad days with poweryield of 4-5 kWh, I am 52% autonomous. In the month september I was 90% autonomous, not bad, but will go down during the winter I presume.
Correction about the location where to put the "cumulative" code: in order for it to run only if the data are available, it is better to put it after those lines:
if [ -z $myCurrentChargeDischargeW ] then myCurrentChargeDischargeW="-N/A-" myCurrentChargeCapWh="-N/A-" myCurrentDischargeCapWh="-N/A-" else
Beware that maybe the names of the values are a bit different for you (I renamed some of them for consistency, adding the kWh for instance for "myCurrentChargeCapkWh".
Hi,
I need to digest all this info hahaha. Is it all in the BatteryRealTime () function?
Maybe you can share the .env and .sh file so I can debug a little myself.
BTW, currently, graph is fine, even without the new code... I guess it degrades during the day, as new values pour...
Your batteries charge slower then my small 5kWh battery it seems :-) And after 0.00 drop to zero again.
The data were inconsistent because of the previous days wrong values... The system needs at least one day to stabilise.
Here are my ".sh" and ".env". I changed a lot of things mainly to consolidate the code, check if data are not returned (API over quota), etc.
HuaweiSolar_API.sh.txt HuaweiSolar.env.txt
Do not forget to put back your values in the ".env" file (where "ChangeMe" is written)
Let me know :-)
For reference, those are my Domoticz user variables:
Thx! I already figured out that it were Domoticz uservariables :-) Will try it tonight, you put a lot of effort in this, I wish I could program code like you ...
It would be helpfull for all my other home automation projects :-)
I have no glory, that was my job (application security in a bank), and I program since I am 12 (now: 60 :-) ).
Anyway, you showed very good thought and reflection, so I guess, the skill will come easily to you.
Keep me in the loop if you find something odd or if you need help in any way. We must wait 1-2 days to let the data settle in.
Not all ok it seems. Solarpanels (current) still has a value.... Oh wait, you also add the battery return there
Same for me:
Currently, the battery is discharging, exactly the same amount of what I have called "Solar Installation" (the panels only are MPPT. So the "active_power" is any production, solar panels as well as batteries.
My Today value is wrong in "MPPT", it shows total power generated, apparently I need other variable? Or this is by design?
As I said, your inverter is another type (1) than mine, and you have the "total_cap" value, but also the "mppt_total_cap" value. I do not know which one you should use. As I do not have the "mppt_total_cap", my script uses "total_cap". Maybe you should print out in the log file both values, and keep the correct one.
Yes, you told. This sensor should show the Total Yield? right?
Yes, this sensor should only show what is produced by the solar panels. The other sensor (the original one, with "active_power" and the original "total" should represent what the inverter is processing from DC (batteries + solar panels) towards the load (the household); at least this is what I intended to achieve.
Yes, this sensor should only show what is produced by the solar panels
The Total Yield, not a daily yield? that's what I mean
. The other sensor (the original one, with "active_power" and the original "total" should represent what the inverter is processing from DC (batteries + solar panels) towards the load (the household); at least this is what I intended to achieve.
Now you added the battery discharge (active_power at night), this will be distracted from to the daily yield (the second graph in the sensor), don't know if that is as intended? The Yield graph will go down in value there.
I did not modify the values to « add the discharge », I just assume what is happening with the « active power ». And for the initial « total » value, maybe it is not the correct one to use there as well. What I can do is to compare what the Huawei site displays and the API values to get the correct understanding of the meaning of the API values.
Yes, you told. This sensor should show the Total Yield? right?
It is Domoticz which use the total value to deduce the daily values. This is why the data we give to the curl for updating the sensor must be continuously increasing (thus, yes, total yield)
Yes, you told. This sensor should show the Total Yield? right?
It is Domoticz which use the total value to deduce the daily values. This is why the data we give to the curl for updating the sensor must be continuously increasing (thus, yes, total yield)
Understood, so this will take some days to become visible
I did not modify the values to « add the discharge », I just assume what is happening with the « active power ». And for the initial « total » value, maybe it is not the correct one to use there as well. What I can do is to compare what the Huawei site displays and the API values to get the correct understanding of the meaning of the API values.
Active_power can be both PV power as Battery discharge power, as you said :-) In this case when no PV power is available it will 'switch' to battery discharge as an active_power. That means that total yield/day will decrease. I now have changed active_power back to mppt_power
I keep 2 sensors: one using mppt_power (for the solar panels only) and one with the active_power. Which leads to the thought that maybe, as you just said, it is normal for the total yield/day to decrease when batteries discharge, therefore maybe I should remove the code making sure the "total_power" value (from the "getStationRealKpi" API, not the "getDevRealKpi") keeps growing ? You were the one bothered that that value my decrease, so I added that code. What do you think ?
Let me think on your question and meanwhile let the data grow, so tomorrow evening I have a clearer view :-)
I still have the idea to add 'used house hold power' and 'amount fed to the grid' to the battery P1 sensor. We have 2 variables left there. But how will Domoticz handle this?
OK ! For your question, I do not know, and moreover, those data are not really related to the battery. Personally, I do not like to mix things unrelated. Maybe another sensor (2 in fact, because also "used house hold power" and "amount fed to the grid" are also not really related, aren't they ? I am sure these values (for the "used house hold power" and "amount fed to the grid") can be extracted from the "Power sensor" (device type 47): active_power (consumption from grid / injection towards the grid), active_cap (energy injected into grid), reverse_active_cap (energy taken from grid).
I have those sensors already in place (data taken from the P1 Smart Meter I have since 1 year):
It is kinda what you speak about, but I find more relevant to have them on their own sensor (type Electricity (Instant + Counter)).
Yes, but I am waiting for my digital meter, will take several weeks, think I already mentioned this. This is then my program coding assignment: build 2 sensors , 1 for used power and one for injected power. :-)
I can use the power sensor 47 for the data as mentioned.
Yes, but I am waiting for my digital meter, will take several weeks, think I already mentioned this.
Do not worry, it was not meant to be a criticism. it was just to mention how I did it and show the result. It is indeed the best way for you to use the sensor 47.
Hi, I found 4 errors in my script :-( (I always miss the fact that integer comparaison in bash is with -lt, -eq, etc. while string comparison is with <, ==, etc.).
Change the line:
if [[ $exceptionInfo = "null" ]]
with:
if [[ $exceptionInfo == "null" ]]
Change the line (yes, it appears twice):
if [[ $exceptionInfo = "null" ]]
with:
if [[ $exceptionInfo == "null" ]]
Change the line:
if [[ $myCurrentChargeCapkWh < $previousDailyChargeEnergy ]]; then
with:
if [[ $myCurrentChargeCapkWh -lt $previousDailyChargeEnergy ]]; then
Change the line:
if [[ $myCurrentDischargeCapkWh < $previousDailyDischargeEnergy ]]; then
with:
if [[ $myCurrentDischargeCapkWh -lt $previousDailyDischargeEnergy ]]; then
Sorry for that.
$myCurrentDischargeCapkWh < $previousDailyDischargeEnergy
Done! :-)
I was already starting code programming for the Power Meter ID47, let me try and work it, after finish, you want to review?
I also need to debug the negative values here:
$myCurrentDischargeCapkWh < $previousDailyDischargeEnergy
Done! :-)
I was already starting code programming for the Power Meter ID47, let me try and work it, after finish, you want to review?
No problem, I am here :-)
Regarding the negative values for "active_power" (Current (W)) for the inverter getStationRealKpi, it seems to occur when the battery begins to charge (look at matching lines tagged with "**" in both Inverter and Battery data below).
Inverter:
Fri Oct 7 19:44:02 CEST 2022 Current (W): 1087 W, Current MPPT (W): 0 W, Total: 27580 Wh, Total Cap (W): 27530 Wh, Today: 9.31 kWh
**Fri Oct 7 19:48:01 CEST 2022 Current (W): -1010 W, Current MPPT (W): 0 W, Total: 27580 Wh, Total Cap (W): 27590 Wh, Today: 9.25 kWh**
Fri Oct 7 19:56:01 CEST 2022 Current (W): -1010 W, Current MPPT (W): 0 W, Total: 27580 Wh, Total Cap (W): 27590 Wh, Today: 9.41 kWh
Fri Oct 7 20:00:02 CEST 2022 Current (W): -1010 W, Current MPPT (W): 0 W, Total: 27580 Wh, Total Cap (W): 27590 Wh, Today: 9.41 kWh
Fri Oct 7 20:04:02 CEST 2022 Current (W): 0 W, Current MPPT (W): 0 W, Total: 27620 Wh, Total Cap (W): 27590 Wh, Today: 9.47 kWh
Battery:
Fri Oct 7 19:42:02 CEST 2022 Battery Level (%): 2 %, Current Charge: 0 W, Current Discharge: 1087 W, Charge/Discharge Power (W): -1087 W, Charged energy (Wh): 2750 Wh, Discharged energy (Wh): 2820 Wh
**Fri Oct 7 19:46:01 CEST 2022 Battery Level (%): 0 %, Current Charge: 1010 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1010 W, Charged energy (Wh): 2750 Wh, Discharged energy (Wh): 2940 Wh**
Fri Oct 7 19:50:01 CEST 2022 Battery Level (%): 0 %, Current Charge: 1010 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1010 W, Charged energy (Wh): 2750 Wh, Discharged energy (Wh): 2940 Wh
Fri Oct 7 19:54:02 CEST 2022 Battery Level (%): 1 %, Current Charge: 1010 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1010 W, Charged energy (Wh): 2830 Wh, Discharged energy (Wh): 2940 Wh
Fri Oct 7 19:58:01 CEST 2022 Battery Level (%): 2 %, Current Charge: 1010 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1010 W, Charged energy (Wh): 2910 Wh, Discharged energy (Wh): 2940 Wh
Fri Oct 7 20:06:02 CEST 2022 Battery Level (%): 2 %, Current Charge: 0 W, Current Discharge: 0 W, Charge/Discharge Power (W): 0 W, Charged energy (Wh): 2970 Wh, Discharged energy (Wh): 2940 Wh
Inverter:
Sat Oct 8 09:20:01 CEST 2022 Current (W): 52 W, Current MPPT (W): 52 W, Total: 27660 Wh, Total Cap (W): 27840 Wh, Today: 0.07 kWh
**Sat Oct 8 09:24:01 CEST 2022 Current (W): -868 W, Current MPPT (W): 158 W, Total: 27690 Wh, Total Cap (W): 27840 Wh, Today: 0.1 kWh**
Sat Oct 8 09:28:02 CEST 2022 Current (W): -883 W, Current MPPT (W): 141 W, Total: 27780 Wh, Total Cap (W): 27840 Wh, Today: 0.19 kWh
Sat Oct 8 09:40:02 CEST 2022 Current (W): 96 W, Current MPPT (W): 96 W, Total: 27860 Wh, Total Cap (W): 27850 Wh, Today: 0.27 kWh
Battery:
Sat Oct 8 09:18:01 CEST 2022 Battery Level (%): 0 %, Current Charge: 0 W, Current Discharge: 0 W, Charge/Discharge Power (W): 0 W, Charged energy (Wh): 2970 Wh, Discharged energy (Wh): 3120 Wh
**Sat Oct 8 09:22:01 CEST 2022 Battery Level (%): 1 %, Current Charge: 1027 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1027 W, Charged energy (Wh): 3030 Wh, Discharged energy (Wh): 3150 Wh**
Sat Oct 8 09:26:01 CEST 2022 Battery Level (%): 1 %, Current Charge: 1024 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1024 W, Charged energy (Wh): 3120 Wh, Discharged energy (Wh): 3150 Wh
Sat Oct 8 09:30:02 CEST 2022 Battery Level (%): 1 %, Current Charge: 1024 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1024 W, Charged energy (Wh): 3120 Wh, Discharged energy (Wh): 3150 Wh
Sat Oct 8 09:34:01 CEST 2022 Battery Level (%): 2 %, Current Charge: 0 W, Current Discharge: 0 W, Charge/Discharge Power (W): 0 W, Charged energy (Wh): 3150 Wh, Discharged energy (Wh): 3150 Wh
Hmmm, sorry, what I thought was a mistake was not, because the comparison needs to by done "string wise", due to the fact those values are not integer :-(
Please change back:
if [[ $myCurrentChargeCapkWh -lt $previousDailyChargeEnergy ]]; then
to:
if [[ $myCurrentChargeCapkWh < $previousDailyChargeEnergy ]]; then
and:
if [[ $myCurrentDischargeCapkWh -lt $previousDailyDischargeEnergy ]]; then
to:
if [[ $myCurrentDischargeCapkWh < $previousDailyDischargeEnergy ]]; then
I will write a better code for the float comparison to be better :-)
Better code, in real math :-) Change
if [[ $myCurrentChargeCapkWh < $previousDailyChargeEnergy ]]; then
to:
if [[ $(echo "if (${myCurrentChargeCapkWh} < ${previousDailyChargeEnergy}) 1 else 0" | bc) -eq 1 ]]
then
And:
if [[ $myCurrentDischargeCapkWh < $previousDailyDischargeEnergy ]]; then
to:
if [[ $(echo "if (${myCurrentDischargeCapkWh} < ${previousDailyDischargeEnergy}) 1 else 0" | bc) -eq 1 ]]
then
Regarding the negative values for "active_power" (Current (W)) for the inverter getStationRealKpi, it seems to occur when the battery begins to charge (look at matching lines tagged with "**" in both Inverter and Battery data below).
Inverter:
Fri Oct 7 19:44:02 CEST 2022 Current (W): 1087 W, Current MPPT (W): 0 W, Total: 27580 Wh, Total Cap (W): 27530 Wh, Today: 9.31 kWh **Fri Oct 7 19:48:01 CEST 2022 Current (W): -1010 W, Current MPPT (W): 0 W, Total: 27580 Wh, Total Cap (W): 27590 Wh, Today: 9.25 kWh** Fri Oct 7 19:56:01 CEST 2022 Current (W): -1010 W, Current MPPT (W): 0 W, Total: 27580 Wh, Total Cap (W): 27590 Wh, Today: 9.41 kWh Fri Oct 7 20:00:02 CEST 2022 Current (W): -1010 W, Current MPPT (W): 0 W, Total: 27580 Wh, Total Cap (W): 27590 Wh, Today: 9.41 kWh Fri Oct 7 20:04:02 CEST 2022 Current (W): 0 W, Current MPPT (W): 0 W, Total: 27620 Wh, Total Cap (W): 27590 Wh, Today: 9.47 kWh
Battery:
Fri Oct 7 19:42:02 CEST 2022 Battery Level (%): 2 %, Current Charge: 0 W, Current Discharge: 1087 W, Charge/Discharge Power (W): -1087 W, Charged energy (Wh): 2750 Wh, Discharged energy (Wh): 2820 Wh **Fri Oct 7 19:46:01 CEST 2022 Battery Level (%): 0 %, Current Charge: 1010 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1010 W, Charged energy (Wh): 2750 Wh, Discharged energy (Wh): 2940 Wh** Fri Oct 7 19:50:01 CEST 2022 Battery Level (%): 0 %, Current Charge: 1010 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1010 W, Charged energy (Wh): 2750 Wh, Discharged energy (Wh): 2940 Wh Fri Oct 7 19:54:02 CEST 2022 Battery Level (%): 1 %, Current Charge: 1010 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1010 W, Charged energy (Wh): 2830 Wh, Discharged energy (Wh): 2940 Wh Fri Oct 7 19:58:01 CEST 2022 Battery Level (%): 2 %, Current Charge: 1010 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1010 W, Charged energy (Wh): 2910 Wh, Discharged energy (Wh): 2940 Wh Fri Oct 7 20:06:02 CEST 2022 Battery Level (%): 2 %, Current Charge: 0 W, Current Discharge: 0 W, Charge/Discharge Power (W): 0 W, Charged energy (Wh): 2970 Wh, Discharged energy (Wh): 2940 Wh
Inverter:
Sat Oct 8 09:20:01 CEST 2022 Current (W): 52 W, Current MPPT (W): 52 W, Total: 27660 Wh, Total Cap (W): 27840 Wh, Today: 0.07 kWh **Sat Oct 8 09:24:01 CEST 2022 Current (W): -868 W, Current MPPT (W): 158 W, Total: 27690 Wh, Total Cap (W): 27840 Wh, Today: 0.1 kWh** Sat Oct 8 09:28:02 CEST 2022 Current (W): -883 W, Current MPPT (W): 141 W, Total: 27780 Wh, Total Cap (W): 27840 Wh, Today: 0.19 kWh Sat Oct 8 09:40:02 CEST 2022 Current (W): 96 W, Current MPPT (W): 96 W, Total: 27860 Wh, Total Cap (W): 27850 Wh, Today: 0.27 kWh
Battery:
Sat Oct 8 09:18:01 CEST 2022 Battery Level (%): 0 %, Current Charge: 0 W, Current Discharge: 0 W, Charge/Discharge Power (W): 0 W, Charged energy (Wh): 2970 Wh, Discharged energy (Wh): 3120 Wh **Sat Oct 8 09:22:01 CEST 2022 Battery Level (%): 1 %, Current Charge: 1027 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1027 W, Charged energy (Wh): 3030 Wh, Discharged energy (Wh): 3150 Wh** Sat Oct 8 09:26:01 CEST 2022 Battery Level (%): 1 %, Current Charge: 1024 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1024 W, Charged energy (Wh): 3120 Wh, Discharged energy (Wh): 3150 Wh Sat Oct 8 09:30:02 CEST 2022 Battery Level (%): 1 %, Current Charge: 1024 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1024 W, Charged energy (Wh): 3120 Wh, Discharged energy (Wh): 3150 Wh Sat Oct 8 09:34:01 CEST 2022 Battery Level (%): 2 %, Current Charge: 0 W, Current Discharge: 0 W, Charge/Discharge Power (W): 0 W, Charged energy (Wh): 3150 Wh, Discharged energy (Wh): 3150 Wh ``
I see..seems logical, in day time Postive, @night, negative(delivery)
too many variables available ;-)
This should be correct code:
# Build Power Meter Device Request header
#####################################
BuildPowerMeterDeviceHeader () {
myPowerDeviceDeviceHeaderData="{\"devIds\": \"$powermeterDeviceID\",\"devTypeId\": \"47\"}"
Echo "Power Meter Device Data: "$myPowerDeviceDeviceHeaderData
}
# Get Power Meter Device Real Time data
###################################
PowerMeterRealTime () {
BuildPowerMeterDeviceHeader
Echo ======
Echo "Existing token: "$myToken
Echo "StationCode: "$stationCode
Echo "PowerMeterDeviceID: "$powermeterDeviceID
curl -s -X POST -H "CONTENT-Type:application/json" -H "XSRF-TOKEN:$myToken" -d "$myPowerDeviceDeviceHeaderData" $baseURL/getDevRealKpi > $mydir/powermeterdevicerealtime.$$
cat $mydir/powermeterdevicerealtime.$$ >> getDevRealKpi_powermeter_data.txt
echo "" >> getDevRealKpi_powermeter_data.txt
# check if we got data (often API call is rejected "over quota"
exceptionInfo=$(cat $mydir/powermeterdevicerealtime.$$ |jq '.exceptionInfo')
if [[ $exceptionInfo == "null" ]]
then
myCurrentPowerFromGridkWh=$(cat $mydir/powermeterdevicerealtime.$$ |jq '.data[]|."dataItemMap".reverse_active_cap' | bc | sed 's/^\./0./')
myCurrentPowerReturnedToGridkWh=$(cat $mydir/powermeterdevicerealtime.$$ |jq '.data[]|."dataItemMap".active_cap' | bc | sed 's/^\./0./')
Echo "Current Power From Grid (kWh): "$myCurrentPowerFromGridkWh
Echo "Current Power To Grid (kWh): "$myCurrentPowerReturnedToGridkWh
# Store the values over the json interface in Domoticz
if [ -z $myCurrentPowerFromGridkWh ]
then
myCurrentPowerFromGridkWh="-N/A-"
myCurrentPowerReturnedToGridkWh="-N/A-"
else
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiPowerFromGrid&nvalue=0&svalue=$myCurrentPowerFromGridkWh"
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiBPowerReturnedToGrid&nvalue=0&svalue=$myCurrentPowerReturnedToGridkWh"
fi
echo `date` "Current Power From Grid (kWh): "$myCurrentPowerFromGridkWh "kWh, Current Power To Grid (kWh): "$myCurrentPowerReturnedToGridkWh "kWh" >> realtime_powermeter_data.txt
else
Echo "exceptionInfo:" "$exceptionInfo"
fi
}
Because it is 3 back-quotes (```) not single quotes as I wrongly said :-(
Your code seems really fine ! Congrats!
No data in Domoticz, sensors are updated, but only the timestamp
These sensors need 2 variables, not 1.
Adding active_power also not solving the issue
v1.1 :-)
# Build Power Meter Device Request header
#####################################
BuildPowerMeterDeviceHeader () {
myPowerDeviceDeviceHeaderData="{\"devIds\": \"$powermeterDeviceID\",\"devTypeId\": \"47\"}"
Echo "Power Meter Device Data: "$myPowerDeviceDeviceHeaderData
}
# Get Power Meter Device Real Time data
###################################
PowerMeterRealTime () {
BuildPowerMeterDeviceHeader
Echo ======
Echo "Existing token: "$myToken
Echo "StationCode: "$stationCode
Echo "PowerMeterDeviceID: "$powermeterDeviceID
curl -s -X POST -H "CONTENT-Type:application/json" -H "XSRF-TOKEN:$myToken" -d "$myPowerDeviceDeviceHeaderData" $baseURL/getDevRealKpi > $mydir/powermeterdevicerealtime.$$
cat $mydir/powermeterdevicerealtime.$$ >> getDevRealKpi_powermeter_data.txt
echo "" >> getDevRealKpi_powermeter_data.txt
# check if we got data (often API call is rejected "over quota"
exceptionInfo=$(cat $mydir/powermeterdevicerealtime.$$ |jq '.exceptionInfo')
if [[ $exceptionInfo == "null" ]]
then
myCurrentPowerFromGridkWh=$(cat $mydir/powermeterdevicerealtime.$$ |jq '.data[]|."dataItemMap".reverse_active_cap' | bc | sed 's/^\./0./')
myCurrentPowerReturnedToGridkWh=$(cat $mydir/powermeterdevicerealtime.$$ |jq '.data[]|."dataItemMap".active_cap' | bc | sed 's/^\./0./')
myCurrentActivePowerW=$(cat $mydir/powermeterdevicerealtime.$$ |jq '.data[]|."dataItemMap".active_power' | bc | sed 's/^\./0./')
if [ $myCurrentActivePowerW -gt 0 ]
then
myActivePowerToGridW=$myCurrentActivePowerW
myActivePowerFromGridW=0
else
myActivePowerFromGridW=$myCurrentActivePowerW
myActivePowerToGridW=0
fi
Echo "Current Power From Grid (kWh): "$myCurrentPowerFromGridkWh
Echo "Current Power To Grid (kWh): "$myCurrentPowerReturnedToGridkWh
Echo "Current Active Power (W): "$myCurrentActivePowerW
# Store the values over the json interface in Domoticz
if [ -z $myCurrentPowerFromGridkWh ]
then
myCurrentPowerFromGridkWh="-N/A-"
myCurrentPowerReturnedToGridkWh="-N/A-"
else
# multiply by 1000 => W(h)
myCurrentPowerFromGridWh=$(echo "scale=0; ${myCurrentPowerFromGridkWh} * 1000 / 1" | bc | sed 's/^\./0./')
myCurrentPowerReturnedToGridWh=$(echo "scale=0; ${myCurrentPowerReturnedToGridkWh} * 1000 / 1" | bc | sed 's/^\./0./')
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiPowerReturnedToGrid&nvalue=0&svalue=$myActivePowerToGridW;$myCurrentPowerReturnedToGridWh"
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiPowerFromGrid&nvalue=0&svalue=$myActivePowerFromGridW;$myCurrentPowerFromGridWh"
fi
echo `date` "Current Power From Grid (kWh): "$myCurrentPowerFromGridkWh "kWh, Current Power To Grid (kWh): "$myCurrentPowerReturnedToGridkWh "kWh, Active Power (W): "$myCurrentActivePowerW "W" >> realtime_powermeter_data.txt
else
Echo "exceptionInfo:" "$exceptionInfo"
fi
}
Seems fine now !!! I used a P1 Smart Sensor (like for the battery) to have all the Meter data in one place, because my dashboard becomes crowded :-) But I think now I have it all (I added a mesure of the data rack consumption today... I was afraid it was huge but it is "only" 220 W (2 Synology NAS, 1 MacMini as local server for Domoticz and all my automation control and monitoring systems, the modems, router and switches, the security systems power, etc. Till now, I identified 470 Wh, hence I am still searching where the remaining 350 Wh are hiding...) !
I think I need to make the return value a positive value for the sensor to operate in a good way
Oh, yes, I missed that in your code: you should have (cf the Battery code):
myActivePowerFromGridW==$(echo "${myCurrentActivePowerW} * -1" | bc
where you have:
myActivePowerFromGridW=$myCurrentActivePowerW
Do we need to use only the dummy sensor with sensor type custom sensor? Would be nice to have also diagrams besides the graph, with sensor type electric or usage we can generate diagrams.