GoumJer / Huawei_Sun2000

Shell script to read data from Huawei website en send to Domoticz/Influx
2 stars 1 forks source link

Domoticz Dummy sensortype usage #3

Closed RikBast closed 1 year ago

RikBast commented 1 year ago

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.

RikBast commented 1 year ago
Schermafbeelding 2022-10-02 om 20 41 18

Yes, better

MichelRabozee commented 1 year ago

\o/ yesss

RikBast commented 1 year ago

There is no value in the graph for charging the battery. Wonder why that is.

Schermafbeelding 2022-10-03 om 18 51 28

realtime_battery_data.txt

Maybe multiply $myCurrentCharge * - 1 also, to make that negative number. negative is 'delivery' is my guess

MichelRabozee commented 1 year ago

I do not think the value should be negative. The P1 Smart Meter data are all positive, even the "injected" energy.

Something else is happening.

Are you familiar with sqlite3 commands ?

You may try to see if the data are correctly put into the Domoticz database, if you know where it is stored:

sqlite3 domoticz.db select * from MultiMeter where DeviceRowID=YOUR_BATTERY_DEVICE_IDX; .quit

RikBast commented 1 year ago

I do not think the value should be negative. The P1 Smart Meter data are all positive, even the "injected" energy.

Something else is happening.

Are you familiar with sqlite3 commands ?

You may try to see if the data are correctly put into the Domoticz database, if you know where it is stored:

sqlite3 domoticz.db select * from MultiMeter where DeviceRowID=YOUR_BATTERY_DEVICE_IDX; .quit

No, no experience with sqlite3 commands, sorry.

Just run these command in .sh file where domoticz.db is stored?

MichelRabozee commented 1 year ago

Yesterday, before 22:00, was it also like that ?

RikBast commented 1 year ago

Yes, no return data

We were editing the script then.

MichelRabozee commented 1 year ago

Just run these command in .sh file where domoticz.db is stored?

Yes to start sqlite3:

sqlite3 domoticz.db

To see all the data for your "device" (the one like a Smart Meter to which you send the data):

select * from MultiMeter where DeviceRowID=YOUR_BATTERY_DEVICE_IDX

To quit sqlite3 (there is a '.' in front of "quit"):

.quit
RikBast commented 1 year ago

Like this:

sqlite3 domoticz.db select * from MultiMeter where DeviceRowID=31 .quit

or

select 31 ?

MichelRabozee commented 1 year ago

First choice :-)

sqlite3 domoticz.db
select * from MultiMeter where DeviceRowID=31
.quit
RikBast commented 1 year ago
Schermafbeelding 2022-10-03 om 21 15 44

Nothing happening here

MichelRabozee commented 1 year ago

Oh, sorry, the select command must be ended with a semicolon ';'

select * from MultiMeter where DeviceRowID=31;

Just enter a ';' and press (you will get an error, it is fine), then reissue the "select" line, ending it with a semicolon

RikBast commented 1 year ago

Ok, something for tomorrow:-)

RikBast commented 1 year ago

image

Almost all '0' except first value? Not so in the text file and in Domoticz

RikBast commented 1 year ago

image

MichelRabozee commented 1 year ago

OK, it explains the lack of data in the graph. Can you share the whole "BatteryRealTime ()" code please ? put it here between 2 lines of 3 consecutive single quotes (so the code is not touched by the formatting of this forum). \'\'\' YOUR CODE HERE \'\'\'

RikBast commented 1 year ago

HuaweiSolar_API.sh.txt

Don't know why it still formats the text, so I added the whole file, maybe last lines not correct?

'''

Build Battery Device Request header

###################################### BuildBatteryDeviceHeader () {

get devices list

curl -s -X POST -H "CONTENT-Type:application/json" -H "XSRF-TOKEN:$myToken" -d "$myHeaderData" $baseURL/getDevList > $mydir/devices.$$

result=($(cat $mydir/devices.$$ | jq -r '.data[]|[.devTypeId, .id, .devName]|@csv'))

#

for resultItem in "${result[@]}"

do

IFS=',' ; resultItemArray=($resultItem) ; IFS=' '

retrieve the inverter device ID (device type 39)

if [ ${resultItemArray[0]} == "1" ]

then

devIds=${resultItemArray[1]}

fi

done

# myBatteryDeviceHeaderData="{\"devIds\": \"$batteryDeviceID\",\"devTypeId\": \"39\"}" Echo "Battery Device Data: "$myBatteryDeviceHeaderData }

Get Battery Device Real Time data

#################################### BatteryRealTime () {

BuildBatteryDeviceHeader

Echo ====== Echo "Existing token: "$myToken Echo "StationCode: "$stationCode Echo "BatteryDeviceID: "$batteryDeviceID

curl -s -X POST -H "CONTENT-Type:application/json" -H "XSRF-TOKEN:$myToken" -d "$myBatteryDeviceHeaderData" $baseURL/getDevRealKpi > $mydir/batterydevicerealtime.$$

cat $mydir/batterydevicerealtime.$$

myCurrentPercentage=$(cat $mydir/batterydevicerealtime.$$ |jq '.data[]|."dataItemMap".battery_soc' | bc | sed 's/^./0./') myCurrentChargeDischarge=$(cat $mydir/batterydevicerealtime.$$ |jq '.data[]|."dataItemMap".ch_discharge_power' | bc | sed 's/^./0./') myCurrentChargeCap=$(cat $mydir/batterydevicerealtime.$$ |jq '.data[]|."dataItemMap".charge_cap' | bc | sed 's/^./0./') myCurrentDischargeCap=$(cat $mydir/batterydevicerealtime.$$ |jq '.data[]|."dataItemMap".discharge_cap' | bc | sed 's/^./0./')

myCurrentChargeCapWh=$(echo "scale=0; ${myCurrentChargeCap} 1000 / 1" | bc | sed 's/^./0./') myCurrentDischargeCapWh=$(echo "scale=0; ${myCurrentDischargeCap} 1000 / 1" | bc | sed 's/^./0./')

Echo "Current Battery Status(%): "$myCurrentPercentage Echo "Charge/Discharge Power (W): "$myCurrentChargeDischarge Echo "Charged energy (kWh): "$myCurrentChargeCap Echo "Discharged energy (kWh): "$myCurrentDischargeCap

Store the values over the json interface in Domoticz

if [ -z $myCurrentPercentage ] then myCurrentPercentage="-N/A-" else curl "$myDomoticzURL/json.htm?type=command&param=udevice&idx=$DomoticzHuaweiBatteryPercentage&nvalue=0&svalue=$myCurrentPercentage" fi

Store the values over the json interface in Domoticz

if [ -z $myCurrentChargeDischarge ] then myCurrentChargeDischarge="-N/A-" myCurrentChargeCapWh="-N/A-" myCurrentDischargeCapWh="-N/A-" else

multiply by 1000 => W(h)

myCurrentChargeCapWh=$(echo "scale=0; ${myCurrentChargeCap} 1000 / 1" | bc | sed 's/^./0./') myCurrentDischargeCapWh=$(echo "scale=0; ${myCurrentDischargeCap} 1000 / 1" | bc | sed 's/^./0./')

if [ $myCurrentChargeDischarge -gt 0 ] then myCurrentCharge=$myCurrentChargeDischarge myCurrentDischarge=0 Echo "Current Charge (W): "$myCurrentCharge else myCurrentDischarge=$(echo "${myCurrentChargeDischarge} * -1" | bc) myCurrentCharge=0 Echo "Current Discharge (W): "$myCurrentDischarge fi curl "$myDomoticzURL/json.htm?type=command&param=udevice&idx=$batteryUsageID&nvalue=0&svalue=$myCurrentDischargeCapWh;$USAGE2;$myCurrentChargeCapWh;$RETURN2;$myCurrentDischarge;$myCurrentCharge" fi echo date "DischargeCap (Wh): "$myCurrentDischargeCapWh "Wh, ChargeCap (Wh): "$myCurrentChargeCapWh "Wh, Current Discharge (W): "$myCurrentDischarge "W, Current Charge (W): "$myCurrentCharge "W" >> realtime_battery_data.txt } '''

MichelRabozee commented 1 year ago

nothing wrong in your code pops into my mind :-(

RikBast commented 1 year ago

nothing wrong in your code pops into my mind :-(

It's strange that according to the database all is zero except first number, when looking in Domoticz I see all the values, just not the 'production' graph.image

image

MichelRabozee commented 1 year ago

Yes, I have no clue why the production ("return") is not on the graph, but it is definitively because the values in the "" table are zero.

What you see on your last screen shot comes from another table "DeviceStatus", holding the last received data. in sqlite3, you may see those with "select * from DeviceStatus;"

BTW, where do you see that last screen in Domoticz ? I have nothing like that for my P1 Smart Meter in the Dashboard or the Utility screen, I just have:

MichelRabozee commented 1 year ago

May I see the last data from r"ealtime_battery_data.txt", from "select from MultiMeter where DeviceRowID=31;" and from "select from DeviceStatus;"

RikBast commented 1 year ago

Make a new sensor in Domoticz and test?

MichelRabozee commented 1 year ago

Yeah, maybe.

RikBast commented 1 year ago

Yes, I have no clue why the production ("return") is not on the graph, but it is definitively because the values in the "" table are zero.

What you see on your last screen shot comes from another table "DeviceStatus", holding the last received data. in sqlite3, you may see those with "select * from DeviceStatus;"

BTW, where do you see that last screen in Domoticz ? I have nothing like that for my P1 Smart Meter in the Dashboard or the Utility screen, I just have:

----> When using my phone to get to Domoticz (not the app, but the mobile web page)

  • Dashboard:
image
  • Utility: image
RikBast commented 1 year ago

Yeah, maybe.

Also all 0 in the database for new P1 smart meter. Is there a need for converting to 'real' explicit in order for Domoticz to understand in the P1 smart meter? For all we now, the 'number' from Huawei might be strings?

For the normal sensor (usage + counter) I see all the entries in the database table

MichelRabozee commented 1 year ago

These are the values for my Smart Meter: select * from DeviceStatus; 7|2|82007|1|Smart Meter|1|250|1|0|1|12|255|0|5566943.00;6608021.00;38292.00;13917.00;272.00;0|2022-10-04 11:50:01|11|0.0|1.0|0.0|1.0|||0|0|0|||

select * from MultiMeter where DeviceRowID=7 7|5566458|38292|0|64|6608021|13917|2022-10-04 10:45:01 7|5566466|38292|158|0|6608021|13917|2022-10-04 10:50:00

All data are "integer" and in "Watt", but your code is fine: in bash, there is no such thing as "string" or "integer", all arguments are passed as strings to "curl", and when Domoticz receives them, it converts them from strings to integers (or float) according to its needs.

RikBast commented 1 year ago

Another theory:

curl "$myDomoticzURL/json.htm?type=command&param=udevice&idx=$batteryUsageID&nvalue=0&svalue=$myCurrentDischargeCapWh;$USAGE2;$myCurrentChargeCapWh;$RETURN2;$myCurrentDischarge;$myCurrentCharge"

The first value I do see in the database, then after the second variable '$USAGE2' all remains empty. Maybe we need to hard program '$USAGE2' as zero? Also for '$RETURN2'. Then Domoticz understands it?

MichelRabozee commented 1 year ago

That is a very good point. Anyway, just replace in the curl line the "$USAGE2" and "$RETURN2" with 0 So:

curl "$myDomoticzURL/json.htm?type=command&param=udevice&idx=$batteryUsageID&nvalue=0&svalue=$myCurrentDischargeCapWh;0;$myCurrentChargeCapWh;0;$myCurrentDischarge;$myCurrentCharge"

It is worth the try !

RikBast commented 1 year ago

I just did! Works!

image

Some very high value?

Not seen this in the database as you can see.

image

MichelRabozee commented 1 year ago

Wow, perfect !

Tomorrow, normally, my battery will be installed !

RikBast commented 1 year ago

Wow, perfect !

Tomorrow, normally, my battery will be installed !

Then you will be ready for it to work :-)

MichelRabozee commented 1 year ago

The high value is effectively strange. Maybe a cumulative artefact ? Also, itisalways possible to delete a bad data by SHIFT-clicking on it if it is really a bad data’

RikBast commented 1 year ago

Shift-click doesn't seem to work on diagrams. Around midnight I get big negative value which doesn't show in the domoticz database.

Schermafbeelding 2022-10-04 om 17 28 28
MichelRabozee commented 1 year ago

If there is nothing in the database table "Meter", you may look into the table "Meter_Calendar": that table holds data by day, computed from the continuous data found in the table Meter (which is then cleared every 0:00). This is clearly a kind of computation artefact. In my case, when I got big negative values for Energy, one hour later, a big positive value appeared, compensating for the negative data. The negative data came from the fact that sometimes, at night, the "total Energy" is going to zero transiently, then back to the normal increasing value.

RikBast commented 1 year ago

Yes, it's a calculation effect, must be.

Good luck with the installation of your 10kW battery, show me also the graphs when operating.

We can expand the script more by adding actual usage of our houses in the P1 meter ($USAGE2) and the Difference between: power from the PV - Actual_usage - charging battery = input to grid ($RETURN2)

What you think?

MichelRabozee commented 1 year ago

Yes, it's a calculation effect, must be.

Good luck with the installation of your 10kW battery, show me also the graphs when operating.

Thank you, and, sure, I will give feedback. I just hope I will not have to re-ask for another openAPI account, I hate paperwork (or rather, I hate asking and asking and asking someone (the installer) to do an email to Huawei just to give me permission to access the system...)

We can expand the script more by adding actual usage of our houses in the P1 meter ($USAGE2) and the Difference between: power from the PV - Actual_usage - charging battery = input to grid ($RETURN2)

What you think?

Currently, as I have a Connected (Smart) meter, I have to a P1 Smart Meter sensor the usage from grid and the return to grid. I have the actual house consumption, but with a Arduino and "current sensors".

So if you do not have the real Smart meter (because with it and a P1 Plugwise Smile, you get the grid consumption and the grid injection, yes, what you propose is good, but how do you get the "actual usage in the house" value ? it requires a measure between the inverter and the cupboard with the fuse ?

RikBast commented 1 year ago

You can get the actual usage from the inverter directly: active_power I think it is called, you used that variable in your script in the beginning instead of mppt_power.

I don't have a digital meter (yet), waiting for install :-(

MichelRabozee commented 1 year ago

In my inverter, active_power does not seem to give the "usage": the only difference I see between active_power and mppt_power is that ppt_power gives 10 W more. But none of them gives the actual usage in house or the usage from the grid. graph with "active_power":

image

graph with "mppt_power":

image

Maybe this behavioural difference comes from the fact that I have a "residential inverter" (type 38), and you have a string inverter (type 1)

MichelRabozee commented 1 year ago

Usage from / to grid:

image

House usage yesterday:

image
RikBast commented 1 year ago

I just did! Works!

image

Some very high value?

Not seen this in the database as you can see.

image

mmhhhh, the database entry seems not correct The second entry should be a zero (we made it zero ourselves), but get's a value. The last two values: 1 of the 2 should get a value.

In Domoticz I get strange high values for loading the battery

curl "$myDomoticzURL/json.htm?type=command&param=udevice&idx=$batteryUsageID&nvalue=0&svalue=$myCurrentDischargeCapWh;0;$myCurrentChargeCapWh;0;$myCurrentDischarge;$myCurrentCharge"

MichelRabozee commented 1 year ago

Hello,

They have done the installation. And my openAPI credentials still work ! Good thing.

I think now I have some things to play a bit with, because besides the new inverter and the batteries, I now have a "Meter" device [Power Sensor(Export+import meter)], kind of smart meter to know when to discharge the batteries or charge them, etc. depending on the direction of the flows:

Device Type: 38, Device ID: 1000000035362538, Device name: "Inverter-1" Device Type: 39, Device ID: 1000000035363268, Device name: "Battery" Device Type: 47, Device ID: 1000000035363269, Device name: "Meter-1"

The installer said it can be queried for some things as well.

BTW, I experienced now the difference, as you said, between "active_power" (with may be negative) and mppt_power (for the solar array). Hence, the batteries are the modifying factor here !

I expect to run into some of your issues as well (for the graphs), it will be helpful for looking at the issue myself (2 pairs of eyes are better than 1).

More to follow later :-)

MichelRabozee commented 1 year ago

And, as it is a new inverter, the "total energy" started from scratch, producing a big negative value with respect to the life of the previous inverter....

image
RikBast commented 1 year ago

Hello,

They have done the installation. And my openAPI credentials still work ! Good thing.

I think now I have some things to play a bit with, because besides the new inverter and the batteries, I now have a "Meter" device [Power Sensor(Export+import meter)], kind of smart meter to know when to discharge the batteries or charge them, etc. depending on the direction of the flows:

Device Type: 38, Device ID: 1000000035362538, Device name: "Inverter-1" Device Type: 39, Device ID: 1000000035363268, Device name: "Battery" Device Type: 47, Device ID: 1000000035363269, Device name: "Meter-1"

Nice! I also have the Meter-1 ID:47 smart meter.

The installer said it can be queried for some things as well.

BTW, I experienced now the difference, as you said, between "active_power" (with may be negative) and mppt_power (for >the solar array). Hence, the batteries are the modifying factor here !

Ah! I was already wondering why you had those different values

I expect to run into some of your issues as well (for the graphs), it will be helpful for looking at the issue myself (2 pairs of eyes are better than 1).

Oh yes! The charge/discharge values in Domoticz are totally wrong presented in the graphs, I really can't grasp it right now. They are ok when looking in the database, but the graphs are really crazy

The webpage of fusion solar can make really nice graphs for your devices. For the battery we should see graphs like this in Domoticz I think.

Schermafbeelding 2022-10-05 om 19 24 17

More to follow later :-)

Yes! let's stay in touch for more data grinding fun :-)

MichelRabozee commented 1 year ago

I clearly have my "total" which goes backwards at some point. Will try to use the "total_cap" value from "getDevRealKpi" API instead. There are so many different values, but the doc lacks a clear explanation on which is what (at least for someone like me who is not a solar energy/inverter engineer).

BTW, my battery stops discharging when it reached 16 % it that normal ?

RikBast commented 1 year ago

I clearly have my "total" which goes backwards at some point. Will try to use the "total_cap" value from "getDevRealKpi" API instead. There are so many different values, but the doc lacks a clear explanation on which is what (at least for someone like me who is not a solar energy/inverter engineer).

Don't you see the strange graphs for charge/discharge? Values in the Domoticz database are correct, the presentation in Domoticz is totally wrong.

BTW, my battery stops discharging when it reached 16 % it that normal ?

You can set this value in the FusionSolar app, the tab 'Devices', parameter settings. mine goes to 2% minimal. I never touched this setting but you can choose value between 0-20%, don't know the ideal setting.

MichelRabozee commented 1 year ago

Yes, the graphs are weird

image

I will let the things run for 1 or 2 days before trying to understand, because on today, the data are void due to the incomplete day, and the fact that the installer first made a mistake with the "Meter" leading to charging the battery from the grid LOL

Thank you for the "percentage" settings ! Once the value changed, does it needs time for the new setting to activate ? (the battery still does not discharge yet)

MichelRabozee commented 1 year ago

The battery has begun to discharge below 16 % \o/ !

RikBast commented 1 year ago

Yes, the graphs are weird

image

I will let the things run for 1 or 2 days before trying to understand, because on today, the data are void due to the incomplete day, and the fact that the installer first made a mistake with the "Meter" leading to charging the battery from the grid LOL

That's actually a setting of the Battery called TOU, only interesting if you have double tariff of electricity or so. There is info on Huawei on this

Thank you for the "percentage" settings !

Once the value changed, does it needs time for the new setting to activate ? (the battery still does not discharge yet)

RikBast commented 1 year ago

The battery has begun to discharge below 16 % \o/ !

Super!

I just read that standard 15% is used, need to check why mine is set to 'NA'

MichelRabozee commented 1 year ago

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.