mvdklip / Domoticz-myenergi

Domoticz plugin to get myenergi information
GNU General Public License v3.0
1 stars 3 forks source link

History data #4

Open dannybloe opened 2 years ago

dannybloe commented 2 years ago

So, the plugin is indeed monitoring the Zappi and logs this into Domoticz. Eventually the totals should match with what's stored in the hub and with MyEnergi. However, if you miss a couple of checks (e.g. Domoticz was offline a bit) then your logs in Domoticz are off with the 'truth'.

So I was wondering if we could come up with some scheme that updates stuff in Domoticz based on the historical data. Like a device that constantly calculates how much you charged today and update that total. And perhaps a similar device for charged this week, this month and this year. Wouldn't that be safer and more accurate eventually?

I'm still looking for a good way to export this data properly so I can charge my company with the most accurate data.

Cheers, Danny

mvdklip commented 2 years ago

You are totally right. The problem I faced when developing this plugin is that the Domoticz energy meter can be set to 'from device' or 'computed'. For the first you need access to a running total (meterstand), for the second you can just provide it the wattage and it'll calculate the kWh's from there. As the myenergi cloud API doesn't return any running totals I saw no other option than using the 'computed' setting.

However: 1) A lot of time has passed. I could check the output of the API nowadays.

2) Maybe it's possible to use the totals from the current month as the running totals. I'm not sure if Domoticz handles overflows/resets of these values gracefully. I think I saw it calculating negative values when I tested this.

3) Maybe it's possible to add additional meters for each month and then feed those with the total for the current month as returned by the API.

The last option would actually mean that the plugin creates new meters every month. Not great but at least it would guarantee historical data to be stored.

I'll have a look when I have some spare time. I don't look the 'computed' situation myself as well.

On Tue, 15 Feb 2022, 16:46 Danny Bloemendaal, @.***> wrote:

So, the plugin is indeed monitoring the Zappi and logs this into Domoticz. Eventually the totals should match with what's stored in the hub and with MyEnergi. However, if you miss a couple of checks (e.g. Domoticz was offline a bit) then your logs in Domoticz are off with the 'truth'.

So I was wondering if we could come up with some scheme that updates stuff in Domoticz based on the historical data. Like a device that constantly calculates how much you charged today and update that total. And perhaps a similar device for charged this week, this month and this year. Wouldn't that be safer and more accurate eventually?

I'm still looking for a good way to export this data properly so I can charge my company with the most accurate data.

Cheers, Danny

— Reply to this email directly, view it on GitHub https://github.com/mvdklip/Domoticz-myenergi/issues/4, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQ47TED3ZKKU4IR6SUWHLU3JYNPANCNFSM5OO5NA2A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

mvdklip commented 2 years ago

I have started developing a new version of this plugin which has both 'instant' (like the current version) and 'today' meters. This is based on the data I can get from the app API quite easily. I am currently working on adding the 'today' data up so that I can also add 'total' meters.

Some thoughts/comments:

1) The 'total' meters would start counting from the first day the plugin was installed so it's not a true total but a running total since plugin installation.

2) The 'instant' meters can be fed with the same data as the 'total' meters so that they show the same data. That would make the totals meters seemingly redundant but I think I need them to be able to store the data somewhere.

3) The plugin would create a total of 15 meters. Quite a lot, but again I think I need all those meters to be able to store relevant data.

@dannybloe Let me know your thoughts if you have any.

dannybloe commented 2 years ago

I sent you a message via your site. Perhaps you can send me a pm.

dannybloe commented 2 years ago

I follow a similar scheme for my SolarEdge scripts. I download the daily total and put that in a general energy dummy (not computed) and I just update whatever the service gives me. So this should work 🙂

mvdklip commented 2 years ago

Must be something wrong with my site because I didn't get your message and also not a test message I sent to myself and I think PMs are non-existant on Github, aren't they?

mvdklip commented 2 years ago

I follow a similar scheme for my SolarEdge scripts. I download the daily total and put that in a general energy dummy (not computed) and I just update whatever the service gives me. So this should work 🙂

You mean you use the daily total as the counter for the instant+counter energy meter? I think the daily wrapping of the counter causes an error in Domoticz because it's not supposed to wrap. Are you sure this works without problems?

mvdklip commented 2 years ago

This is what happens when I use the daily values as the counter for an instant+counter electricity meter:

Screenshot 2022-02-19 084203

Notice the negative today values for the meters. This happens during the transition from computed to from device mode so maybe it does work correctly when setup in from device mode from the beginning. I have just removed it and I'll check it tomorrow again.

mvdklip commented 2 years ago

Nope. That doesn't work. Apparently Domoticz compares the last value of yesterday with the latest value received and starts reporting negative numbers for today after wrapping, so I'll have to come up with another strategy.

@dannybloe Can you comment on what you're doing? As suspected using the daily running totals as the counter doesn't work.

dannybloe commented 2 years ago

Ok, here is the dzVents script:

return {
    on = {
        timer = {
            'every 5 minutes'
        },
        httpResponses = { 'SolarEdge' },
    },
    data = {
            lifeTime = { initial = nil }
    },
    execute = function(domoticz, triggerItem)
        if (triggerItem.isTimer) then
        if (domoticz.time.matchesRule('at daytime') or domoticz.data.lifeTime == nil) then
                domoticz.openURL({
                    url = 'https://monitoringapi.solaredge.com/site/417711/overview?api_key=xyz',
                    method = 'GET',
                    callback = 'SolarEdge'
                })
            else
                -- keep posting the lifeTime value
                local lifeTime = domoticz.data.lifeTime
                domoticz.devices('SolarEdge').updateElectricity(0, lifeTime)
                domoticz.devices('SolarEdge: totaal').updateCustomSensor(lifeTime / 1000)
            end
        elseif (triggerItem.isHTTPResponse) then

            local response = triggerItem

            if (response.statusCode == 200 and response.isJSON) then
                local lifeTime = response.json.overview.lifeTimeData.energy
                local current = response.json.overview.currentPower.power
                local revenue = response.json.overview.lifeTimeData.revenue
                domoticz.devices('SolarEdge').updateElectricity(current, lifeTime)
                domoticz.devices('SolarEdge: opbrengst').updateCustomSensor(revenue)
                domoticz.devices('SolarEdge: totaal').updateCustomSensor(lifeTime / 1000)
                domoticz.data.lifeTime = lifeTime -- for updating at night
            else
                domoticz.log('Error fetching SolarEdge data', domoticz.LOG_ERROR)
                domoticz.log(response.data, domoticz.LOG_ERROR)
            end
        end
    end
}

Mmm, it has been a couple of years since I wrote this script. Clearly I do persist the lifeTime in a persistent variable and even when there there is no current usage I set the 'SolarEdge' device to that lifeTime value. So the service gives me a lifeTime value and I use that or I use the previously stored lifeTime value. I am not sure anymore why I did this and what happens if you don't. The energy counters have always a bit vague to me on how exactly they operate.

This is the dummy device info Domoticz sends to the client:

{
            "AddjMulti" : 1.0,
            "AddjMulti2" : 1.0,
            "AddjValue" : 0.0,
            "AddjValue2" : 0.0,
            "BatteryLevel" : 255,
            "CounterToday" : "0.000 kWh",
            "CustomImage" : 0,
            "Data" : "20309.420 kWh",
            "Description" : "",
            "EnergyMeterMode" : "",
            "Favorite" : 1,
            "HardwareDisabled" : false,
            "HardwareID" : 4,
            "HardwareName" : "Dummy",
            "HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
            "HardwareTypeVal" : 15,
            "HaveTimeout" : false,
            "ID" : "00082557",
            "LastUpdate" : "2022-02-21 07:40:02",
            "Name" : "SolarEdge",
            "Notifications" : "false",
            "PlanID" : "3",
            "PlanIDs" : 
            [
                3,
                27
            ],
            "Protected" : false,
            "ShowNotifications" : true,
            "SignalLevel" : "-",
            "SubType" : "kWh",
            "SwitchTypeVal" : 4,
            "Timers" : "false",
            "Type" : "General",
            "TypeImg" : "current",
            "Unit" : 1,
            "Usage" : "0 Watt",
            "Used" : 1,
            "XOffset" : "0",
            "YOffset" : "0",
            "idx" : "557"
        },

It looks like this: Screenshot 2022-02-21 at 07 47 25

Device settings: Screenshot 2022-02-21 at 07 48 21

And this is how the charts look like: Screenshot 2022-02-21 at 07 49 16

This seems to work 🙂.

mvdklip commented 2 years ago

Thanks. The trick here is that the solaredge cloud service returns the lifetime value. The Domoticz instant+counter meter needs this lifetime value to operate properly. The problem is that the myenergi cloud doesn't return this value. ;-)

I'm trying a few strategies right now and I'm sure I will come up with something. I can always try and keep a running total myself although this would probably be fragile.

dannybloe commented 2 years ago

Yeah. Well, you could perhaps get the totals and correct the local values if you miss a couple of readings. I think there are totals.

mvdklip commented 2 years ago

There are no totals in the myenergi API. That's why it's so hard to get this right. Still experimenting with different kinds of meters in Domoticz... Will let you know if I get it to work.