Closed RikBast closed 1 year ago
I changed it, seems to work great.
Would it be difficult to translate this code in LUA like code (Fibaro Homecenter 2) you think?
I never "spoke" LUA :-) but from what I found (https://fr.wikipedia.org/wiki/Lua) it should be easy; the only question is "is it easy to run shell scripts from within it (for instance for accessing files like last_token and for the curl - although I guess there is an internal command for that as Domoticz knows LUA as well (https://www.domoticz.com/wiki/LUA_commands) -)
The MPPT meter behaves strange, let's look into it.
Alread 2 kWh generated, that's no correct
Mine displays normal (beside a small episode with negative values for power (-2 W, -34 W) during this morning when the batteries completed discharge, but I think this is normal.
No clue why it does that to your graph while the "mppt_power" values seem fine. Do you use "total_cap" or "mppt_total_cap" for the energy value ? My script is using "total_cap" because I do not have "mppt_total_cap" on my "38" inverter.
I was using total_cap, looking at the inverter I get these data:
Already that high Yield today, that must be the electrical household power at night, or the battery discharge added to the total_cap value. I don't have another conclusion.
Now I changed to mppt_total_cap and will let it run for a day and see. But immediately I had 64 kWh after first update:
The first data is normal, if the initial total value was higher than the previous value used. Anyway, yes, leave it for a day or two. (another approach should have been that you could have put the mppt_total_cap in the echo, and see on several days the evolution before changing the value fed to Domoticz)
I created another sensor with mppt_total_cap data, now 3 sensors ;-) So I can follow graphically, will add also to .txt file
Yes, it is a good approach.
It is sad there is no more documentation about what value does exactly what and moreover how they are used in the Huawei Customer Site for instance.
It is........... ;-)
Which one is correct? Solarpanels (Current) is the nearest with the App value
"correct" is not the word I would use. They are all correct, certainly, but we have no clue what they represent ;-)
In my case for today: with "total_cap" I have: 3,20 kWh (I do not have mppt_total_cap); with the "total_power": 3,31 kWh; with "day_power": 3,35 kWh, and the app says: "yield today" and "consumed from PV): 3,06 kWh.
Go figure ?????!!!!???
Yes, you are right, all values are correct of course. There is indeed great difference between the App value and all of our sensors
"correct" is not the word I would use. They are all correct, certainly, but we have no clue what they represent ;-)
In my case for today: with "total_cap" I have: 3,20 kWh (I do not have mppt_total_cap); with the "total_power": 3,31 kWh; with "day_power": 3,35 kWh, and the app says: "yield today" and "consumed from PV): 3,06 kWh.
Go figure ?????!!!!???
Don't you think we miss data due to API quota control?
Yes, maybe for the "instant" values, but not for the totalisation values.
These battery values for charging and discharging remain very strange compared to the fusion solar app Should be like this:
Why do you say that the values for the battery are strange ? On the FusionSolar app, they are positive for charge, negative for discharge, but on Domoticz, both are positive (green for charge, blue for discharge).
I have (today, very sunny here):
The curve in Domoticz is nothing alike the curve in the app (besides negative for discharge). I hoped it would look more like the one in the official app
And this is my battery graphs for today
Ah, you means the fact that the curve goes to zero ? I was wondering as well now, because the data show not "0" during the charge or discharge:
Tue Oct 11 14:06:02 CEST 2022 Battery Level (%): 13 %, Current Charge: 5110 W, Current Discharge: 0 W, Charge/Discharge Power (W): 5110 W, Charged energy (Wh): 10050 Wh, Discharged energy (Wh): 8540 Wh
Tue Oct 11 14:26:01 CEST 2022 Battery Level (%): 22 %, Current Charge: 1562 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1562 W, Charged energy (Wh): 11070 Wh, Discharged energy (Wh): 8540 Wh
Tue Oct 11 14:30:02 CEST 2022 Battery Level (%): 22 %, Current Charge: 1562 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1562 W, Charged energy (Wh): 11070 Wh, Discharged energy (Wh): 8540 Wh
Tue Oct 11 14:34:01 CEST 2022 Battery Level (%): 23 %, Current Charge: 1437 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1437 W, Charged energy (Wh): 11190 Wh, Discharged energy (Wh): 8540 Wh
Tue Oct 11 14:42:01 CEST 2022 Battery Level (%): 25 %, Current Charge: 1273 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1273 W, Charged energy (Wh): 11400 Wh, Discharged energy (Wh): 8550 Wh
Tue Oct 11 14:50:01 CEST 2022 Battery Level (%): 26 %, Current Charge: 1311 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1311 W, Charged energy (Wh): 11500 Wh, Discharged energy (Wh): 8550 Wh
Tue Oct 11 15:02:02 CEST 2022 Battery Level (%): 28 %, Current Charge: 1161 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1161 W, Charged energy (Wh): 11780 Wh, Discharged energy (Wh): 8550 Wh
Tue Oct 11 15:10:02 CEST 2022 Battery Level (%): 29 %, Current Charge: 1245 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1245 W, Charged energy (Wh): 11850 Wh, Discharged energy (Wh): 8550 Wh
Tue Oct 11 15:14:01 CEST 2022 Battery Level (%): 30 %, Current Charge: 1255 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1255 W, Charged energy (Wh): 11960 Wh, Discharged energy (Wh): 8550 Wh
Tue Oct 11 15:18:01 CEST 2022 Battery Level (%): 31 %, Current Charge: 1234 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1234 W, Charged energy (Wh): 12060 Wh, Discharged energy (Wh): 8550 Wh
Tue Oct 11 15:30:02 CEST 2022 Battery Level (%): 32 %, Current Charge: 1218 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1218 W, Charged energy (Wh): 12250 Wh, Discharged energy (Wh): 8550 Wh
Tue Oct 11 15:42:01 CEST 2022 Battery Level (%): 35 %, Current Charge: 1201 W, Current Discharge: 0 W, Charge/Discharge Power (W): 1201 W, Charged energy (Wh): 12520 Wh, Discharged energy (Wh): 8550 Wh
Tue Oct 11 15:46:02 CEST 2022 Battery Level (%): 35 %, Current Charge: 196 W, Current Discharge: 0 W, Charge/Discharge Power (W): 196 W, Charged energy (Wh): 12600 Wh, Discharged energy (Wh): 8550 Wh
Tue Oct 11 15:50:01 CEST 2022 Battery Level (%): 35 %, Current Charge: 196 W, Current Discharge: 0 W, Charge/Discharge Power (W): 196 W, Charged energy (Wh): 12600 Wh, Discharged energy (Wh): 8550 Wh
Tue Oct 11 15:54:01 CEST 2022 Battery Level (%): 35 %, Current Charge: 249 W, Current Discharge: 0 W, Charge/Discharge Power (W): 249 W, Charged energy (Wh): 12610 Wh, Discharged energy (Wh): 8560 Wh
Tue Oct 11 16:10:02 CEST 2022 Battery Level (%): 35 %, Current Charge: 0 W, Current Discharge: 812 W, Charge/Discharge Power (W): -812 W, Charged energy (Wh): 12640 Wh, Discharged energy (Wh): 8580 Wh
Tue Oct 11 16:14:01 CEST 2022 Battery Level (%): 34 %, Current Charge: 0 W, Current Discharge: 433 W, Charge/Discharge Power (W): -433 W, Charged energy (Wh): 12640 Wh, Discharged energy (Wh): 8660 Wh
Tue Oct 11 16:26:02 CEST 2022 Battery Level (%): 33 %, Current Charge: 0 W, Current Discharge: 237 W, Charge/Discharge Power (W): -237 W, Charged energy (Wh): 12640 Wh, Discharged energy (Wh): 8820 Wh
So it is Domoticz which has an issue: as it draws a value every 5 minutes, but as the data are available at different times than 5 minutes, Domoticz consider the missing values as zero ???
That will not be easy to counteract :-(
Ah! Ok, but we have this annoying quota API control preventing nice graphics 😐
Exactly... The solution is to send the same data as the previous run in case the API reject the call... I am busy on another matter, but I will try to come with something (if you do not find something before me).
OK, I tried this. We need to leave it running for a day to see...
HuaweiSolar_API.sh.txt HuaweiSolar.env.txt
It requires 3 new user variables (of type "string"):
# ID and names for uservariable 'string' to store previous successfully retrieved data to compensate for the "Request is rejected by api quotaControl"
PreviousDataID_Inverter=ChangeMe
PreviousDataName_Inverter=Inverter_PreviousData
PreviousDataID_Battery=ChangeMe
PreviousDataName_Battery=Battery_PreviousData
PreviousDataID_Meter=ChangeMe
PreviousDataName_Meter=Meter_PreviousData
You may want to perform a "diff" to check my work and maybe do not throw away any modification you brought to the previous version (e.g. for the mppt_total_cap, etc...). It was quite late today.
Sadly, the "caching" of the values while the API quota is happening does not solve the "go to zero" issue :-(
Wed Oct 12 05:31:01 CEST 2022 Active Power (W): -975 W, Consumed Power (W): 975 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125120 Wh
Wed Oct 12 05:35:01 CEST 2022 Active Power (W): -975 W, Consumed Power (W): 975 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125120 Wh
Wed Oct 12 05:39:01 CEST 2022 Active Power (W): -975 W, Consumed Power (W): 975 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125120 Wh
Wed Oct 12 05:43:01 CEST 2022 Active Power (W): -1145 W, Consumed Power (W): 1145 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125400 Wh
Wed Oct 12 05:47:01 CEST 2022 Active Power (W): -1050 W, Consumed Power (W): 1050 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125480 Wh
Wed Oct 12 05:51:01 CEST 2022 Active Power (W): -904 W, Consumed Power (W): 904 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125560 Wh
Wed Oct 12 05:55:00 CEST 2022 Active Power (W): -904 W, Consumed Power (W): 904 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125560 Wh
Wed Oct 12 05:59:01 CEST 2022 Active Power (W): -891 W, Consumed Power (W): 891 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125650 Wh
Wed Oct 12 06:03:01 CEST 2022 Active Power (W): -891 W, Consumed Power (W): 891 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125650 Wh
Wed Oct 12 06:07:01 CEST 2022 Active Power (W): -891 W, Consumed Power (W): 891 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125650 Wh
Wed Oct 12 06:11:00 CEST 2022 Active Power (W): -891 W, Consumed Power (W): 891 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125650 Wh
Wed Oct 12 06:15:01 CEST 2022 Active Power (W): -1183 W, Consumed Power (W): 1183 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 125950 Wh
Wed Oct 12 06:19:01 CEST 2022 Active Power (W): -1100 W, Consumed Power (W): 1100 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126050 Wh
Wed Oct 12 06:23:01 CEST 2022 Active Power (W): -1097 W, Consumed Power (W): 1097 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126130 Wh
Wed Oct 12 06:27:01 CEST 2022 Active Power (W): -1086 W, Consumed Power (W): 1086 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126230 Wh
Wed Oct 12 06:31:01 CEST 2022 Active Power (W): -1086 W, Consumed Power (W): 1086 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126230 Wh
Wed Oct 12 06:35:01 CEST 2022 Active Power (W): -1086 W, Consumed Power (W): 1086 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126230 Wh
Wed Oct 12 06:39:02 CEST 2022 Active Power (W): -1355 W, Consumed Power (W): 1355 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126440 Wh
Wed Oct 12 06:43:01 CEST 2022 Active Power (W): -1336 W, Consumed Power (W): 1336 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126550 Wh
Wed Oct 12 06:47:00 CEST 2022 Active Power (W): -1336 W, Consumed Power (W): 1336 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126550 Wh
Wed Oct 12 06:51:01 CEST 2022 Active Power (W): -1242 W, Consumed Power (W): 1242 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126770 Wh
Wed Oct 12 06:55:01 CEST 2022 Active Power (W): -1242 W, Consumed Power (W): 1242 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126770 Wh
Wed Oct 12 06:59:02 CEST 2022 Active Power (W): -1260 W, Consumed Power (W): 1260 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126870 Wh
Wed Oct 12 07:03:01 CEST 2022 Active Power (W): -1260 W, Consumed Power (W): 1260 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 126870 Wh
Wed Oct 12 07:07:01 CEST 2022 Active Power (W): -1248 W, Consumed Power (W): 1248 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 127080 Wh
Wed Oct 12 07:11:01 CEST 2022 Active Power (W): -1286 W, Consumed Power (W): 1286 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 127190 Wh
Wed Oct 12 07:15:01 CEST 2022 Active Power (W): -1286 W, Consumed Power (W): 1286 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 127190 Wh
Wed Oct 12 07:19:01 CEST 2022 Active Power (W): -1242 W, Consumed Power (W): 1242 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 127300 Wh
Wed Oct 12 07:23:01 CEST 2022 Active Power (W): -1448 W, Consumed Power (W): 1448 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 127400 Wh
Wed Oct 12 07:27:01 CEST 2022 Active Power (W): -1204 W, Consumed Power (W): 1204 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 127510 Wh
Wed Oct 12 07:31:01 CEST 2022 Active Power (W): -1067 W, Consumed Power (W): 1067 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 127620 Wh
Wed Oct 12 07:35:01 CEST 2022 Active Power (W): -1067 W, Consumed Power (W): 1067 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 127620 Wh
Example, after 6:27, we see clearly that the "caching" works and compensate for the "API quota error":
{"data":[{"devId":1000000035363269,"dataItemMap":{"active_cap":3.39,"meter_status":1.0,"meter_i":-2.95,"reverse_active_cap":126.23,"power_factor":-0.792,"reactive_power":243.0,"active_power":-1086.0,"run_state":1,"meter_u":239.1,"grid_frequency":49.97}}],"failCode":0,"message":null,"params":{"currentTime":1665548821283,"devIds":"1000000035363269","devTypeId":47},"success":true}
{"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
{"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
{"data":[{"devId":1000000035363269,"dataItemMap":{"active_cap":3.39,"meter_status":1.0,"meter_i":-2.86,"reverse_active_cap":126.44,"power_factor":-0.83,"reactive_power":31.0,"active_power":-1355.0,"run_state":1,"meter_u":239.3,"grid_frequency":49.99}}],"failCode":0,"message":null,"params":{"currentTime":1665549541857,"devIds":"1000000035363269","devTypeId":47},"success":true}
But still, value goes to zero :-(
As we have now caching, I will set the crontab to run every minute, and see if it goes better.
* * * * * cd /Users/mrabozee/sources/fusionsolar/Huawei_Sun2000/ ; ./HuaweiSolar_API.sh InverterRealTime >/dev/null 2>&1
* * * * * cd /Users/mrabozee/sources/fusionsolar/Huawei_Sun2000/ ; ./HuaweiSolar_API.sh BatteryRealTime >/dev/null 2>&1
* * * * * cd /Users/mrabozee/sources/fusionsolar/Huawei_Sun2000/ ; ./HuaweiSolar_API.sh MeterRealTime >/dev/null 2>&1
Hi, adapting the crontab was also my first idea. I now use 2-4 min. Maybe every minute is the way to go, will try that also.
The issue is more complicated to fix. Look at these values: I compensated the "API quota" by "caching" the data. But if the caching spans on more than 5 minutes, the "energy" data stay the same, so for the graph, the "power" is 0. It does not seem to use the "power" given, only the "energy" :-( The cached data are tagged with "**" here below:
Wed Oct 12 08:50:02 CEST 2022 Active Power (W): -1128 W, Consumed Power (W): 1128 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129270 Wh
Wed Oct 12 08:51:02 CEST 2022 Active Power (W): -1047 W, Consumed Power (W): 1047 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129360 Wh
**Wed Oct 12 08:52:01 CEST 2022 Active Power (W): -1047 W, Consumed Power (W): 1047 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129360 Wh
**Wed Oct 12 08:53:01 CEST 2022 Active Power (W): -1047 W, Consumed Power (W): 1047 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129360 Wh
**Wed Oct 12 08:54:01 CEST 2022 Active Power (W): -1047 W, Consumed Power (W): 1047 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129360 Wh
**Wed Oct 12 08:55:01 CEST 2022 Active Power (W): -1047 W, Consumed Power (W): 1047 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129360 Wh
**Wed Oct 12 08:56:01 CEST 2022 Active Power (W): -1047 W, Consumed Power (W): 1047 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129360 Wh
**Wed Oct 12 08:57:01 CEST 2022 Active Power (W): -1047 W, Consumed Power (W): 1047 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129360 Wh
**Wed Oct 12 08:58:01 CEST 2022 Active Power (W): -1047 W, Consumed Power (W): 1047 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129360 Wh
**Wed Oct 12 08:59:01 CEST 2022 Active Power (W): -1047 W, Consumed Power (W): 1047 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129360 Wh
**Wed Oct 12 09:00:01 CEST 2022 Active Power (W): -1047 W, Consumed Power (W): 1047 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129360 Wh
Wed Oct 12 09:01:01 CEST 2022 Active Power (W): -839 W, Consumed Power (W): 839 W, Injected Power (W): 0 W, Active Cap (Wh): 3390 Wh, Reverse Active Cap (Wh): 129520 Wh
The only way to avoid the "0" in the graph is to extrapolate the "energy" future value. Impossible LOL
I will try this: "How to change Domoticz graph sampling time" (from the page: https://www.creasol.it/en/support/domotics-home-automation-and-diy/134-domoticz-tips-and-tricks) and set the sampling to 10 minutes instead of 5. This should only impact the graph, not the current values displayed on the dashboard. Will see in some hours ;-)
I am wondering what might the reason hitting the quota......again a maybe a far fetched idea... You use WiFi for your inverter of you have ethernet connection?
I use WiFi.......
And another note: Data from the power smart meter doesn't show these strange graphs, it follows the curve as seen in the app, as you know it's the same idea as the battery. Active power can be positive and negative. So maybe we need to split the data into two sensors. So, there might be an issue with the P1 smart meter in Domoticz?
Look also at these 2 pictures, same data, different presentation (p1 smart meter, electricity meter)
I am wondering what might the reason hitting the quota......again a maybe a far fetched idea... You use WiFi for your inverter of you have ethernet connection?
I use WiFi.......
I use a wired LAN connection.
And another note: Data from the power smart meter doesn't show these strange graphs, it follows the curve as seen in the app, as you know it's the same idea as the battery. Active power can be positive and negative. So maybe we need to split the data into two sensors. So, there might be an issue with the P1 smart meter in Domoticz?
Yes, maybe there is a issue in the Domoticz code for P1 Smart Meter graphs, because they manipulate the energy values without seeming to use the power values (for the graphs at least, because the instant data is fine).
Look also at these 2 pictures, same data, different presentation (p1 smart meter, electricity meter)
Clearly, the way they draw the graphs in the P1 Smart sensor is weird.
With a 10 minutes sampling time (after 10:00, of course the peaks are smoothed, but the zeroing has disappeared (very little chance that the API quota blocks during 10 minutes). Smart Meter Type 47:
Battery:
And the Huawei app for battery:
For the battery, the Huawei one show zero values (normal, because today it is cloudy, the battery does not charge often)... So I obviously do not see that in the Domoticz graphs anymore...
What a dilemma !
Looks much better now :-) I can try also this setting.
Yes, it is smoother, but the peaks are no more visible, because the drawing system seems to do a mean value across the "sampling interval". But, it is roughly OK, in the sense than at the end of the day, it is the "energy" which is relevant, and that one is independent of the sampling period :-)
With a 10 minutes sampling time (after 10:00, of course the peaks are smoothed, but the zeroing has disappeared (very little chance that the API quota blocks during 10 minutes).
Smart Meter Type 47:
Battery:
And the Huawei app for battery:
For the battery, the Huawei one show zero values (normal, because today it is cloudy, the battery does not charge often)... So I obviously do not see that in the Domoticz graphs anymore...
What a dilemma !
I was looking at your battery energy usage and return curves, it seems I don't have them like you. Need to check the code 🤨
I have this at this moment:
My script is the one I posted during the night, with the "caching" + crontab every minute.
Hello, one thing I observed regarding the API quota: in fact, it is quite clear the quota if by user (openAPI user), but global: if I do 3 getDevRealKpi calls simultaneously (about the 3 devices Inverter, Battery and Meter), they all fail or succeed at the same time; hence it is not the fact to call an API several times a minute, but moreover how many people call that API simultaneously. This is a real stupidity.
Inverter:
Thu Oct 13 14:19:03 CEST 2022 {"data":[{"devId":1000000035362538,"dataItemMap":{"pv1_u":121.7,"pv2_u":124.7,"pv3_u":0.0,"pv4_u":0.0,"pv5_u":0.0,"pv6_u":0.0,"power_factor":1.0,"pv7_u":0.0,"pv8_u":0.0,"open_time":1665649876000,"inverter_state":512.0,"a_i":2.064,"total_cap":63.85,"c_i":0.0,"mppt_3_cap":0.0,"b_i":0.0,"reactive_power":-0.003,"a_u":119.3,"temperature":28.4,"c_u":0.0,"b_u":0.2,"bc_u":0.0,"elec_freq":49.96,"mppt_4_cap":0.0,"efficiency":100.0,"day_cap":0.65,"mppt_power":0.488,"run_state":1,"mppt_1_cap":27.72,"close_time":"N/A","pv1_i":2.24,"pv2_i":2.23,"pv3_i":0.0,"mppt_2_cap":34.79,"pv4_i":0.0,"active_power":0.488,"pv5_i":0.0,"pv6_i":0.0,"ca_u":0.0,"ab_u":243.0,"pv7_i":0.0,"pv8_i":0.0}}],"failCode":0,"message":null,"params":{"currentTime":1665663543298,"devIds":"1000000035362538","devTypeId":38},"success":true}
Thu Oct 13 14:20:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:21:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:22:02 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:23:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:24:02 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:25:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:26:02 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:27:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:28:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:29:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:30:02 CEST 2022 {"data":[{"devId":1000000035362538,"dataItemMap":{"pv1_u":121.7,"pv2_u":127.8,"pv3_u":0.0,"pv4_u":0.0,"pv5_u":0.0,"pv6_u":0.0,"power_factor":1.0,"pv7_u":0.0,"pv8_u":0.0,"open_time":1665649876000,"inverter_state":512.0,"a_i":5.136,"total_cap":64.01,"c_i":0.0,"mppt_3_cap":0.0,"b_i":0.0,"reactive_power":0.0,"a_u":119.7,"temperature":29.0,"c_u":0.0,"b_u":0.2,"bc_u":0.0,"elec_freq":49.99,"mppt_4_cap":0.0,"efficiency":100.0,"day_cap":0.81,"mppt_power":2.829,"run_state":1,"mppt_1_cap":27.83,"close_time":"N/A","pv1_i":12.2,"pv2_i":11.02,"pv3_i":0.0,"mppt_2_cap":34.91,"pv4_i":0.0,"active_power":1.243,"pv5_i":0.0,"pv6_i":0.0,"ca_u":0.0,"ab_u":243.9,"pv7_i":0.0,"pv8_i":0.0}}],"failCode":0,"message":null,"params":{"currentTime":1665664202398,"devIds":"1000000035362538","devTypeId":38},"success":true}
Battery:
Thu Oct 13 14:21:01 CEST 2022 {"data":[{"devId":1000000035363268,"dataItemMap":{"max_discharge_power":4400.0,"max_charge_power":5000.0,"battery_soh":0.0,"busbar_u":427.4,"discharge_cap":0.01,"ch_discharge_power":28.0,"run_state":1,"battery_soc":2.0,"charge_cap":0.02,"ch_discharge_model":4.0,"battery_status":2.0}}],"failCode":0,"message":null,"params":{"currentTime":1665663661532,"devIds":"1000000035363268","devTypeId":39},"success":true}
Thu Oct 13 14:22:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:23:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:24:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:25:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:26:02 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:27:00 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:28:00 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:29:00 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:30:01 CEST 2022 {"data":[{"devId":1000000035363268,"dataItemMap":{"max_discharge_power":4400.0,"max_charge_power":5000.0,"battery_soh":0.0,"busbar_u":439.1,"discharge_cap":0.01,"ch_discharge_power":1586.0,"run_state":1,"battery_soc":2.0,"charge_cap":0.03,"ch_discharge_model":4.0,"battery_status":2.0}}],"failCode":0,"message":null,"params":{"currentTime":1665664201828,"devIds":"1000000035363268","devTypeId":39},"success":true}
Meter:
Thu Oct 13 14:21:01 CEST 2022 {"data":[{"devId":1000000035363269,"dataItemMap":{"active_cap":3.39,"meter_status":1.0,"meter_i":3.26,"reverse_active_cap":156.99,"power_factor":-0.003,"reactive_power":72.0,"active_power":-15.0,"run_state":1,"meter_u":244.3,"grid_frequency":49.99}}],"failCode":0,"message":null,"params":{"currentTime":1665663661512,"devIds":"1000000035363269","devTypeId":47},"success":true}
Thu Oct 13 14:22:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:23:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:24:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:25:01 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:26:02 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:27:00 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:28:00 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:29:00 CEST 2022 {"errorCode":"49401021002","exceptionInfo":"Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST"}
Thu Oct 13 14:30:01 CEST 2022 {"data":[{"devId":1000000035363269,"dataItemMap":{"active_cap":3.39,"meter_status":1.0,"meter_i":3.31,"reverse_active_cap":156.99,"power_factor":0.006,"reactive_power":-5.0,"active_power":-23.0,"run_state":1,"meter_u":243.6,"grid_frequency":49.97}}],"failCode":0,"message":null,"params":{"currentTime":1665664201830,"devIds":"1000000035363269","devTypeId":47},"success":true}
Sorry for the late reply, yes you are right, it's not really smart setup for these API calls, wish we Could access the inverter, battery and power smamr meter directly, but as you said, not much info to be found.
Tonight I will try your latest code.
Have a good day
I am now inserting the new code, takes some time, as you named other variables as me and I need to look for the difference and in the inverter I defined 2 more variables.
Let's wait for the sun now ........
Charge/Discharge Power enforced as INTEGER (W): 127 Stored totalChargeEnergyYesterday = 0 Stored previousDailyChargeEnergy = 4.03 ./HuaweiSolar_API_Test.sh: line 436: [[: 4.03: syntax error: invalid arithmetic operator (error token is ".03") { "status" : "OK", "title" : "UpdateUserVariable" } Corrected myCurrentChargeCapkWh = 4.03 Stored totalDischargeEnergyYesterday = 0 Stored previousDailyDischargeEnergy = 0.12 ./HuaweiSolar_API_Test.sh: line 455: [[: 0.12: syntax error: invalid arithmetic operator (error token is ".12")
Some errors I don't understand, can you help me a little?
Sure, let's see.
First of all, line 436 should be:
if [[ $(echo "if (${myCurrentChargeCapkWh} < ${previousDailyChargeEnergy}) 1 else 0" | bc) -eq 1 ]]
and line 455 should be:
if [[ $(echo "if (${myCurrentDischargeCapkWh} < ${previousDailyDischargeEnergy}) 1 else 0" | bc) -eq 1 ]]
Maybe you retrieved a version before I put a new one stating there was an issue in the floating values tests ? I know I flagged a mistake giving errors like the ones you see.
if [[ $(echo "if (${myCurrentDischargeCapkWh} < ${previousDailyDischargeEnergy}) 1 else 0" | bc) -eq 1 ]]
That works :-)
Now the inverter:
myTokenAge: 604 seconds
Existing token: x-ftrulenu5is91cnt7zmlvwepiq7v45g9am7yek5inttjc7nvo47xvujsg5qp4algk5tirubwbsdgmmpdnypic5cahijsph7u3xnzik88mk3tob9fddrxikk5apbusb06
Header Data: {"stationCodes": "NE=35314940"}
Timed Header Data: {"stationCodes": "NE=35314940","collectTime": "1665847026182"}
Inverter Device Data: {"devIds": "1000000035314942","devTypeId": "1"}
======
Existing token: x-ftrulenu5is91cnt7zmlvwepiq7v45g9am7yek5inttjc7nvo47xvujsg5qp4algk5tirubwbsdgmmpdnypic5cahijsph7u3xnzik88mk3tob9fddrxikk5apbusb06
StationCode: NE=35314940
InverterDeviceID: 1000000035314942
Using stored inverterData = 0
Current Household Usage (kW): 0
Current (kW):
Current MPPT (kW):
Today (kWh): 6.32
Total (kWh): 650.36
Total Cap (kWh):
Total MPPT Cap (kWh):
previousTotalEnergy: 650.4 kWh
Total (kWh) CORRECTED: 650.4
{
"status" : "OK",
"title" : "UpdateUserVariable"
}
{
"status" : "OK",
"title" : "Update Device"
}
{
"status" : "OK",
"title" : "Update Device"
}
Current (W):
Current MPPT (W):
Total (Wh): 650400
Current Household usage (W):
Looks like the names of the printed variables is not matching the ones which are filled with data...
It seems ok:
# Get Inverter Device Real Time data
####################################
InverterRealTime () {
BuildInverterDeviceHeader
Echo ======
Echo "Existing token: "$myToken
Echo "StationCode: "$stationCode
Echo "InverterDeviceID: "$inverterDeviceID
curl -s -X POST -H "CONTENT-Type:application/json" -H "XSRF-TOKEN:$myToken" -d "$myHeaderData" $baseURL/getStationRealKpi > $mydir/realtime.$$
myTodaykWh=$(cat $mydir/realtime.$$ |jq '.data[]|."dataItemMap".day_power' | bc | sed 's/^\./0./')
# cat $mydir/realtime.$$
myTotalkWh=$(cat $mydir/realtime.$$ |jq '.data[]|."dataItemMap".total_power' | bc | sed 's/^\./0./')
curl -s -X POST -H "CONTENT-Type:application/json" -H "XSRF-TOKEN:$myToken" -d "$myInverterDeviceHeaderData" $baseURL/getDevRealKpi > $mydir/inverterdevicerealtime.$$
cat $mydir/inverterdevicerealtime.$$ >> getDevRealKpi_inverter_data.txt
echo "" >> getDevRealKpi_inverter_data.txt
# check if we got data (often API call is rejected "over quota"
exceptionInfo=$(cat $mydir/inverterdevicerealtime.$$ |jq '.exceptionInfo')
if [[ $exceptionInfo == "null" ]]
then
# retrieve the previous data from Domoticz variable
inverterData=$(curl -s "$myDomoticzURL/json.htm?type=command¶m=getuservariable&idx=$PreviousDataID_Inverter"|jq '.result[].Value'|tr -d '"')
if [ -z $inverterData ]
then
Echo "No previous data, bailing"
exit
fi
Echo "Using stored inverterData =" "$inverterData"
else
myCurrentHouseHoldkW=$(cat $mydir/inverterdevicerealtime.$$ |jq '.data[]|."dataItemMap".active_power' | bc | sed 's/^\./0./')
myCurrentkW=$(cat $mydir/inverterdevicerealtime.$$ |jq '.data[]|."dataItemMap".mppt_power' | bc | sed 's/^\./0./')
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./')
myTotalCapMPPTkWh=$(cat $mydir/inverterdevicerealtime.$$ |jq '.data[]|."dataItemMap".mppt_total_cap' | bc | sed 's/^\./0./')
inverterData="$myCurrentHouseHoldkW,$myCurrentkW,$myCurrentMPPTkW,$myTotalCapkWh,$myTotalCapMPPTkWh"
Echo "Using new inverterData =" "$inverterData"
# stores the new "previous data" into Domoticz variable
curl "$myDomoticzURL/json.htm?type=command¶m=updateuservariable&vname=$PreviousDataName_Inverter&vtype=2&vvalue=$inverterData"
fi
IFS=',' ; inverterData=($inverterData) ; IFS=' '
myCurrentHouseHoldkW=${inverterData[0]}
myCurrentkW=${inverterData[1]}
myCurrentMPPTkW=${inverterData[2]}
myTotalCapkWh=${inverterData[3]}
myTotalCapMPPTkWh=${inverterData[4]}
Echo "Current Household Usage (kW): "$myCurrentHouseHoldkW
Echo "Current (kW): "$myCurrentkW
Echo "Current MPPT (kW): "$myCurrentMPPTkW
Echo "Today (kWh): "$myTodaykWh
Echo "Total (kWh): "$myTotalkWh
Echo "Total Cap (kWh): "$myTotalCapkWh
Echo "Total MPPT Cap (kWh): "$myTotalCapMPPTkWh
# sometimes, the Huawei server return empty data
if [ -z $myTotalkWh ]
then
myTotalWh="-N/A-"
myCurrentW="-N/A-"
myCurrentMPPTW="-N/A-"
myTotalCapWh="-N/A-"
myTotalCapMPPTkWh="-N/A-"
myCurrentHouseHoldkW="-N/A-"
else
# make sure the total energy value keeps increasing
previousTotalEnergy=$(curl -s "$myDomoticzURL/json.htm?type=command¶m=getuservariable&idx=$myDomoticzHuaweiInverterLastTotalEnergyID"|jq '.result[].Value'|tr -d '"')
Echo previousTotalEnergy: $previousTotalEnergy kWh
# if domoticz variable null, just update it
if [[ $(echo "if (${previousTotalEnergy} > 0) 1 else 0" | bc) -eq 1 ]]
then
if [[ $(echo "if (${previousTotalEnergy} > ${myTotalkWh}) 1 else 0" | bc) -eq 1 ]]
then
echo `date` "*[Correction Total]* Total Read: "$myTotalkWh "kWh, Total corrected: "$previousTotalEnergy "kWh" >> realtime_inverter_data.txt
myTotalkWh=$previousTotalEnergy
Echo "Total (kWh) CORRECTED: "$myTotalkWh
fi
fi
# Write last total energy to Domoticz
curl "$myDomoticzURL/json.htm?type=command¶m=updateuservariable&vname=$myDomoticzHuaweiInverterLastTotalEnergyName&vtype=1&vvalue=$myTotalkWh"
# Store the values over the json interface in Domoticz
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiGeneratedToday&nvalue=0&svalue=$myTodaykWh"
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiGeneratedTotal&nvalue=0&svalue=$myTotalkWh"
# Store the values over the json interface in Domoticz
# multiply by 1000 => W(h)
myTotalWh=$(echo "scale=0; ${myTotalkWh} * 1000 / 1" | bc | sed 's/^\./0./')
if [ -z $myCurrentkW ]
then
myCurrentkW="-N/A-"
myCurrentMPPTkW="-N/A-"
myTotalCapkWh="-N/A-"
myTotalCapMPPTkWh="-N/A-"
myCurrentHouseHoldkW="-N/A-"
else
# multiply by 1000 => W(h)
myCurrentW=$(echo "scale=0; ${myCurrentkW} * 1000 / 1" | bc | sed 's/^\./0./')
myCurrentMPPTW=$(echo "scale=0; ${myCurrentMPPTkW} * 1000 / 1" | bc | sed 's/^\./0./')
myTotalCapWh=$(echo "scale=0; ${myTotalCapkWh} * 1000 / 1" | bc | sed 's/^\./0./')
myTotalCapMPPTWh=$(echo "scale=0; ${myTotalCapMPPTkWh} * 1000 / 1" | bc | sed 's/^\./0./')
myCurrentHouseHoldW=$(echo "scale=0; ${myCurrentHouseHoldkW} * 1000 / 1" | bc | sed 's/^\./0./')
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiGeneratedRealTime&nvalue=0&svalue=$myCurrentW;$myTotalWh"
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiGeneratedMPPTRealTime&nvalue=0&svalue=$myCurrentMPPTW;$myTotalCapWh"
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiGeneratedTotalCapMPPTRealTime&nvalue=0&svalue=$myCurrentMPPTW;$myTotalCapMPPTWh"
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiUsedHouseHoldRealTime&nvalue=0&svalue=$myCurrentHouseHoldW"
fi
Echo "Current (W): "$myCurrentW
Echo "Current MPPT (W): "$myCurrentMPPTW
Echo "Total (Wh): "$myTotalWh
Echo "Current Household usage (W): "$myCurrentHouseHoldW
fi
echo `date` "Current (W): "$myCurrentW "W, Current MPPT (W): "$myCurrentMPPTW "W, Total (Wh): "$myTotalWh "Wh, Total Cap (Wh): "$myTotalCapWh "Wh, Total MPPT Cap (Wh): "$myTotalCapMPPTWh "Wh, Today (kWh): "$myTodaykWh "kWh, House Hold (W): "$myCurrentHouseHoldW "W" >> realtime_inverter_data.txt
}
One thing I am seeing bothering me is
Using stored inverterData = 0
Are you sure you declare the variable corresponding to the stored previous inverter data ($PreviousDataName_Inverter) as a string ? Seems like a Integer in the log?
One thing I am seeing bothering me is
Using stored inverterData = 0
Are you sure you declare the variable corresponding to the stored previous inverter data ($PreviousDataName_Inverter) as a string ? Seems like a Integer in the log?
All rest is ok. Strange
Maybe the Inverter_PreviousData was initialised as "0", not as EMPTY ?
Maybe the Inverter_PreviousData was initialised as "0", not as EMPTY ?
Yes as "0", but when I update it to EMPTY it outputs: ,,,,
Maybe look at it tomorrow again :-(
Found it !
you need to change:
if [[ $exceptionInfo == "null" ]]
with:
if [[ $exceptionInfo != "null" ]]
:-)
Found it !
you need to change:
if [[ $exceptionInfo == "null" ]]
with:
if [[ $exceptionInfo != "null" ]]
:-)
Yes! thx :-)
I don't see the active power to and from the grid anymore in the Domoticz sensors for the powermeter. The user variable shows value:
But the sensors say '0', should read -134 W
Can you put your "Meter" code here, please ? I will give a look
# 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
Echo "exceptionInfo:" "$exceptionInfo"
# retrieve the previous data from Domoticz variable
meterData=$(curl -s "$myDomoticzURL/json.htm?type=command¶m=getuservariable&idx=$PreviousDataID_Meter"|jq '.result[].Value'|tr -d '"')
if [ -z $meterData ]
then
Echo "No previous data, bailing"
exit
fi
Echo "Using stored meterData =" "$meterData"
else
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./')
meterData="$myCurrentPowerFromGridkWh,$myCurrentPowerReturnedToGridkWh,$myCurrentActivePowerW"
Echo "Using new meterData =" "$meterData"
# stores the new "previous data" into Domoticz variable
curl "$myDomoticzURL/json.htm?type=command¶m=updateuservariable&vname=$PreviousDataName_Meter&vtype=2&vvalue=$meterData"
fi
IFS=',' ; meterData=($meterData) ; IFS=' '
myCurrentPowerFromGridkWh=${meterData[0]}
myCurrentPowerReturnedToGridkWh=${meterData[1]}
myCurrentActivePowerW=${meterData[2]}
Echo "Current Power From Grid (kWh): "$myCurrentPowerFromGridkWh
Echo "Current Power To Grid (kWh): "$myCurrentPowerReturnedToGridkWh
Echo "Current Active Power (W): "$myCurrentActivePowerW
if [ -z $myCurrentActivePowerW ]
then
myCurrentActivePowerW="-N/A-"
myCurrentPowerFromGridkWh="-N/A-"
myCurrentPowerReturnedToGridkWh="-N/A-"
else
# make sure the value myCurrentActivePowerW supposed be integer is integer...
myCurrentActivePowerW=$(echo "scale=0; if (${myCurrentActivePowerW} >= 0) (${myCurrentActivePowerW} + 0.5) / 1 else (${myCurrentActivePowerW} - 0.5) / 1" | bc | sed 's/^\./0./')
Echo "Active Power Power enforced as INTEGER (W): "$myCurrentActivePowerW
# 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./')
if [ $myCurrentActivePowerW -gt 0 ]
then
myActivePowerFromGridW=0
myActivePowerToGridW=$myCurrentActivePowerW
Echo "Current Injected Power (W): "$myActivePowerToGridW
else
#myActivePowerFromGridW=$myCurrentActivePowerW
myActivePowerToGridW=0
myActivePowerFromGridW==$(echo "${myCurrentActivePowerW} * -1" | bc)
Echo "Current Consumed Power (W): "$myActivePowerFromGridW
fi
# 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=$DomoticzHuaweiPowerReturnedToGrid&nvalue=0&svalue=$myActivePowerToGridW;$myCurrentPowerReturnedToGridWh"
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiPowerFromGrid&nvalue=0&svalue=$myActivePowerFromGridW;$myCurrentPowerFromGridWh"
curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$DomoticzHuaweiPowerToAndFromGrid&nvalue=0&svalue=$myCurrentPowerFromGridWh;0;$myCurrentPowerReturnedToGridWh;0;$myActivePowerFromGridW;$myActivePowerToGridW"
#curl "$myDomoticzURL/json.htm?type=command¶m=udevice&idx=$batteryUsageID&nvalue=0&svalue=$USAGE1;$USAGE2;$RETURN1;$RETURN2;$CONS;$PROD"
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
}
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.