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
Power consumption from json. [Solved]
Moderator: leecollings
-
- Posts: 71
- Joined: Tuesday 30 April 2019 16:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Location: Portugal
- Contact:
Re: Power consumption from json.
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
}
-
- Posts: 8
- Joined: Tuesday 01 January 2019 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Contact:
Re: Power consumption from json.
I will give it try, thanks!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 }
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?
-
- Posts: 71
- Joined: Tuesday 30 April 2019 16:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Location: Portugal
- Contact:
Re: Power consumption from json. [Solved]
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: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?
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
}
-
- Posts: 8
- Joined: Tuesday 01 January 2019 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Contact:
Re: Power consumption from json.
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.
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
}
Who is online
Users browsing this forum: Google [Bot] and 0 guests