Hi,
i search for a Solution to restore the Power Consumption if my Shelly get a powerloss and the Total Power Consumption falls back to 0
So far I've made it this far:
I have a MQTT IN with the actually results of the Shelly (optional for testing a Inject Node)
One goes into a Function Query for Influx DB to Read the latest Power Consumption stored in the Influx DB
Other goes after Rename the Payload into a Join Node
Both goes to this function Node:
var totalstarttime = msg.payload.TotalStartTime;
var totalkwh = msg.payload.Total;
var yesterdaykwh = msg.payload.Yesterday;
var todaykwh = msg.payload.Today;
var period = msg.payload.Period;
var watt = msg.payload.Power;
var voltage = msg.payload.Voltage;
var ampere = msg.payload.Current;
var factor = msg.payload.Factor;
var scheinleistung = msg.payload.ApparentPower;
var blindleistung = msg.payload.ReactivePower;
var totalDB = msg.payload.totalkwh;
if (ampere === 0 && watt === 0) {
return [null, msg];
} else {
if (totalDB > totalkwh) {
msg.payload = {
totalstarttime: totalstarttime,
totalkwh: (totalDB + totalkwh).toFixed(3),
yesterdaykwh: yesterdaykwh,
todaykwh: todaykwh,
period: period,
watt: watt,
voltage: voltage,
ampere: ampere,
factor: factor,
scheinleistung: scheinleistung,
blindleistung: blindleistung,
}
return msg;
} else {
msg.payload = {
totalstarttime: totalstarttime,
totalkwh: totalkwh,
yesterdaykwh: yesterdaykwh,
todaykwh: todaykwh,
period: period,
watt: watt,
voltage: voltage,
ampere: ampere,
factor: factor,
scheinleistung: scheinleistung,
blindleistung: blindleistung,
}
return msg;
}
}
The If Power and Current = 0 is for stopping Input to the Influx Database if Power and Current = 0
The other one is my problem:
if (totalDB > totalkwh)
If the actually Value from Shelly (totalkwh) smaller than the Database Value (totalDB)
Add the actually Value to the Database Value
But there is the Problem:
eg.: Database have 6.500 kwh
actuall Value is 0.100 kwh
i gettin 6.600kwh thats correct, but after that add this value is added to InfluxDB
Now i have 6.600kwh in Influx DB and a actually value from Shelly of 0.150kwh
After the Second pass i have then not 6.650kwh but the wrong 6.750kwh because it asks the InfluxDB a second Time for the latest value.
I hope I explained that a bit understandable