Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History data #4

Open
dannybloe opened this issue Feb 15, 2022 · 12 comments
Open

History data #4

dannybloe opened this issue Feb 15, 2022 · 12 comments

Comments

@dannybloe
Copy link

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
Copy link
Owner

mvdklip commented Feb 15, 2022 via email

@mvdklip
Copy link
Owner

mvdklip commented Feb 18, 2022

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
Copy link
Author

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

@dannybloe
Copy link
Author

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
Copy link
Owner

mvdklip commented Feb 18, 2022

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
Copy link
Owner

mvdklip commented Feb 18, 2022

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
Copy link
Owner

mvdklip commented Feb 19, 2022

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
Copy link
Owner

mvdklip commented Feb 20, 2022

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
Copy link
Author

dannybloe commented Feb 21, 2022

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
Copy link
Owner

mvdklip commented Feb 21, 2022

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
Copy link
Author

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
Copy link
Owner

mvdklip commented Feb 22, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants