Page 1 of 1
Power consumption from json.
Posted: Wednesday 12 January 2022 11:35
by azzilla
I am a complete moron when it comes to scripting..
If anyone could have a go at helping me create a script for pulling values from my EV-chargers load balancing energy meter into one or possibly three virtual sensors, I would appreciate it.
The values from the load balancing meter are accessible to me via the EV-chargers IP adress.
The values that are of interest are "phaseXCurrent" and the values shown in the image corresponds to:
"phase1Current: 48" = 4,8A
"phase2Current: 31" = 3,1A
"phase3Current: 5" = 0,5A
The soaring energy prices in country has made a huge crater in my wallet but I am more than happy to contribute to the Domoticz project in any way, shape or form when I can. But as I mentioned, scripting is just above my skillset
Re: Power consumption from json.
Posted: Tuesday 01 February 2022 22:52
by javalin
Hi, I am not specialist but should be something like this to get phase1Current value in your LOG
Code: Select all
local scriptVar = 'EV-chargers'
return
{
on =
{
timer =
{
'every 1 minutes',
},
httpResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'EV-chargers',
},
execute = function(dz, item)
if item.isTimer then
dz.openURL({
url = 'put your http adresse here',
method = 'GET',
callback = scriptVar, -- httpResponses above.
})
return
elseif item.json then
local rt = item.json
local phase1Current = rt.phase1Current/10
dz.log('phase1Current: ' .. phase1Current ..' A' , dz.LOG_DEBUG )
else
dz.log('problem with return', dz.LOG_ERROR)
dz.log(item, dz.LOG_DEBUG)
end
end
}
Re: Power consumption from json.
Posted: Wednesday 02 February 2022 11:46
by azzilla
javalin wrote: ↑Tuesday 01 February 2022 22:52
Hi, I am not specialist but should be something like this to get phase1Current value in your LOG
Code: Select all
local scriptVar = 'EV-chargers'
return
{
on =
{
timer =
{
'every 1 minutes',
},
httpResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'EV-chargers',
},
execute = function(dz, item)
if item.isTimer then
dz.openURL({
url = 'put your http adresse here',
method = 'GET',
callback = scriptVar, -- httpResponses above.
})
return
elseif item.json then
local rt = item.json
local phase1Current = rt.phase1Current/10
dz.log('phase1Current: ' .. phase1Current ..' A' , dz.LOG_DEBUG )
else
dz.log('problem with return', dz.LOG_ERROR)
dz.log(item, dz.LOG_DEBUG)
end
end
}
I will give it try, thanks!
Do i create a dummy electric and instant counter and name it 'EV-chargers' as you are calling it in the first line of the script?
Re: Power consumption from json. [Solved]
Posted: Wednesday 02 February 2022 22:15
by javalin
Do i create a dummy electric and instant counter and name it 'EV-chargers' as you are calling it in the first line of the script?
Create a dummy Ampere (3 phase), you don´t need to give that name. Just take note of the IDX number and put here instead 628:
Code: Select all
local scriptVar = 'EV-chargers'
return
{
on =
{
timer =
{
'every 1 minutes',
},
httpResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'EV-chargers',
},
execute = function(dz, item)
local EV_charger = dz.devices(628)
if item.isTimer then
dz.openURL({
url = 'put your http adresses',
method = 'GET',
callback = scriptVar, -- httpResponses above.
})
return
elseif item.json then
local rt = item.json
local phase1Current = rt.phase1Current/10
local phase2Current = rt.phase2Current/10
local phase3Current = rt.phase3Current/10
dz.log('phase1Current: ' .. phase1Current ..' A' , dz.LOG_DEBUG )
EV_charger.updateCurrent(phase1Current,phase2Current,phase3Current) -- store new value in A
else
dz.log('problem with return', dz.LOG_ERROR)
dz.log(item, dz.LOG_DEBUG)
end
end
}
Re: Power consumption from json.
Posted: Thursday 03 February 2022 9:00
by azzilla
I want to leave this for anyone who might stumble on this thread in the future.
For kWh for all three phases, this works very good.
Code: Select all
local scriptVar = 'EV-chargers'
return
{
on =
{
timer =
{
'every 1 minutes',
},
httpResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'EV-chargers',
},
execute = function(dz, item)
local EV_charger = dz.devices(347)
if item.isTimer then
dz.openURL({
url = 'input url here',
method = 'GET',
callback = scriptVar, -- httpResponses above.
})
return
elseif item.json then
local rt = item.json
local phase1Current = rt.phase1Current*23
local phase2Current = rt.phase2Current*23
local phase3Current = rt.phase3Current*23
local sum = phase1Current + phase2Current + phase3Current;
dz.log('sum of all inputs: ' .. sum ..' W' , dz.LOG_DEBUG )
EV_charger.updateElectricity(sum) -- store new value in A
else
dz.log('problem with return', dz.LOG_ERROR)
dz.log(item, dz.LOG_DEBUG)
end
end
}