While developing and testing dzVents 2.4 I used this script to read my SolarEdge solar panels. So instead of using the hardware plugin (which is kind of inefficient if you have multiple converters) I use the new asynchronous http call functionality to fetch some json data from SolarEdge's API and stream the results into two virtual devices:
- SolarEdge (Electric (Instant/Counter, set to type 'Return', energy read from 'device'))
- SolarEdge: revenue (Custom, axis label 'Euros').
Code: Select all
local KEY = 'your api key'
local SITE_ID = 'your site id'
return {
on = {
timer = { 'every 5 minutes at daytime' },
httpResponses = { 'SolarEdge' } -- matches callback string below
},
execute = function(domoticz, triggerItem)
if (triggerItem.isTimer) then
-- get data from SolarEdge
domoticz.openURL({
url = 'https://monitoringapi.solaredge.com/site/' .. SITE_ID .. '/overview?api_key=' .. KEY,
method = 'GET',
callback = 'SolarEdge'
})
elseif (triggerItem.isHTTPResponse) then
-- we got data, let's update our devices
local response = triggerItem
if (response.ok 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: revenue').updateCustomSensor(revenue)
else
-- oops
domoticz.log('Error fetching SolarEdge data', domoticz.LOG_ERROR)
domoticz.log(response.data, domoticz.LOG_ERROR)
end
end
end
}