Page 1 of 1
How to get summary power consumption from different counters ?
Posted: Monday 01 February 2016 11:17
by PowerTech
Hi, i need script to get sum "PowerMeter1"+ "PowerMeter2" and send result to virtual incremental counter.
Two power meters(incremental) data need to put together.
Please help.
Re: How to get summary power consumption from different counters ?
Posted: Monday 20 March 2017 7:51
by derrij
interested too
Re: How to get summary power consumption from different counters ?
Posted: Tuesday 21 March 2017 13:56
by derrij
working for me
Code: Select all
-- /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
local DeviceName1 = "HallBathroom"
local DeviceName2 = "KitchenWallPlug"
local DeviceName3 = "LogiaChildroomWallPlug"
local DeviceName4 = "Appliance"
local DeviceName5 = "LivingroomChildroom"
local ConsumptionIDX = 399 -- IDX of the energy device that shows calculated Consumption
local ConsumptionDeviceName = "Total" -- Name of the energy device that shows calculated Consumption
----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
Energy1 = 0 -- in Watt hours
Power1 = 0 -- in Watts
Energy2 = 0 -- in Watt hours
Power2 = 0 -- in Watts
Energy3 = 0 -- in Watt hours
Power3 = 0 -- in Watts
Energy4 = 0 -- in Watt hours
Power4 = 0 -- in Watts
Energy5 = 0 -- in Watt hours
Power5 = 0 -- in Watts
Energy6 = 0 -- in Watt hours
Power6 = 0 -- in Watts
EnergyConsumption = 0 -- in Watt hours
PowerConsumption = 0 -- in Watts
Debug = "NO" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------------------------------------------------------------------
-- Lua Functions
----------------------------------------------------------------------------------------------------------
function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end
----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}
Power1, Energy1 = otherdevices_svalues[DeviceName1]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName1 .. "Power = " .. Power1 .. " W");
print(" ----- ".. DeviceName1 .. "Energy = " .. Energy1 .. " Wh");
end
Power2, Energy2 = otherdevices_svalues[DeviceName2]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName2 .. "Power = " .. Power2 .. " W");
print(" ----- ".. DeviceName2 .. "Energy = " .. Energy2 .. " Wh");
end
Power3, Energy3 = otherdevices_svalues[DeviceName3]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName3 .. "Power = " .. Power3 .. " W");
print(" ----- ".. DeviceName3 .. "Energy = " .. Energy3 .. " Wh");
end
Power4, Energy4 = otherdevices_svalues[DeviceName4]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName4 .. "Power = " .. Power4 .. " W");
print(" ----- ".. DeviceName4 .. "Energy = " .. Energy4 .. " Wh");
end
Power5, Energy5 = otherdevices_svalues[DeviceName5]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName5 .. "Power = " .. Power5 .. " W");
print(" ----- ".. DeviceName5 .. "Energy = " .. Energy5 .. " Wh");
end
-- Calculate consumption
PowerConsumption = Power1 + Power2 + Power3 + Power4 + Power5
if Debug=="YES" then
print(" ----- PowerConsumption = " .. PowerConsumption .. " W");
end
EnergyConsumption = Energy1 + Energy2 + Energy3 + Energy4 + Energy5
if Debug=="YES" then
print(" ----- EnergyConsumption = " .. EnergyConsumption .. " Wh");
end
-- Update comsumption device in Domoticz
if devicechanged[DeviceName1] or devicechanged[DeviceName2] or devicechanged[DeviceName3] or devicechanged[DeviceName4] or devicechanged[DeviceName5] then
update(ConsumptionDeviceName, ConsumptionIDX, PowerConsumption, EnergyConsumption, 1)
end
return commandArray
Re: How to get summary power consumption from different counters ?
Posted: Tuesday 21 March 2017 14:01
by Abbadon
derrij wrote:working for me
Code: Select all
-- /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
local DeviceName1 = "HallBathroom"
local DeviceName2 = "KitchenWallPlug"
local DeviceName3 = "LogiaChildroomWallPlug"
local DeviceName4 = "Appliance"
local DeviceName5 = "LivingroomChildroom"
local ConsumptionIDX = 399 -- IDX of the energy device that shows calculated Consumption
local ConsumptionDeviceName = "Total" -- Name of the energy device that shows calculated Consumption
----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
Energy1 = 0 -- in Watt hours
Power1 = 0 -- in Watts
Energy2 = 0 -- in Watt hours
Power2 = 0 -- in Watts
Energy3 = 0 -- in Watt hours
Power3 = 0 -- in Watts
Energy4 = 0 -- in Watt hours
Power4 = 0 -- in Watts
Energy5 = 0 -- in Watt hours
Power5 = 0 -- in Watts
Energy6 = 0 -- in Watt hours
Power6 = 0 -- in Watts
EnergyConsumption = 0 -- in Watt hours
PowerConsumption = 0 -- in Watts
Debug = "NO" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------------------------------------------------------------------
-- Lua Functions
----------------------------------------------------------------------------------------------------------
function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end
----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}
Power1, Energy1 = otherdevices_svalues[DeviceName1]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName1 .. "Power = " .. Power1 .. " W");
print(" ----- ".. DeviceName1 .. "Energy = " .. Energy1 .. " Wh");
end
Power2, Energy2 = otherdevices_svalues[DeviceName2]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName2 .. "Power = " .. Power2 .. " W");
print(" ----- ".. DeviceName2 .. "Energy = " .. Energy2 .. " Wh");
end
Power3, Energy3 = otherdevices_svalues[DeviceName3]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName3 .. "Power = " .. Power3 .. " W");
print(" ----- ".. DeviceName3 .. "Energy = " .. Energy3 .. " Wh");
end
Power4, Energy4 = otherdevices_svalues[DeviceName4]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName4 .. "Power = " .. Power4 .. " W");
print(" ----- ".. DeviceName4 .. "Energy = " .. Energy4 .. " Wh");
end
Power5, Energy5 = otherdevices_svalues[DeviceName5]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName5 .. "Power = " .. Power5 .. " W");
print(" ----- ".. DeviceName5 .. "Energy = " .. Energy5 .. " Wh");
end
-- Calculate consumption
PowerConsumption = Power1 + Power2 + Power3 + Power4 + Power5
if Debug=="YES" then
print(" ----- PowerConsumption = " .. PowerConsumption .. " W");
end
EnergyConsumption = Energy1 + Energy2 + Energy3 + Energy4 + Energy5
if Debug=="YES" then
print(" ----- EnergyConsumption = " .. EnergyConsumption .. " Wh");
end
-- Update comsumption device in Domoticz
if devicechanged[DeviceName1] or devicechanged[DeviceName2] or devicechanged[DeviceName3] or devicechanged[DeviceName4] or devicechanged[DeviceName5] then
update(ConsumptionDeviceName, ConsumptionIDX, PowerConsumption, EnergyConsumption, 1)
end
return commandArray
you should use for statement
Re: How to get summary power consumption from different counters ?
Posted: Thursday 09 November 2017 0:49
by kispalsz
I created a dummy device. The new device has a button: create virtual sensor. What type of virtual sensor should be selected to work on the script.
Thanks.
Re: How to get summary power consumption from different counters ?
Posted: Thursday 22 February 2018 16:54
by Bernoo
Hello derrij,
i would like to make a calculation from 2 counters
1 meter "gas quantity" (m³)
2 counter "Condensate quantity" (liters)
3 Counters "fuel efficiency" (%)
From the counters, the following calculation would have to be made:
"Condensate quantity" divided ("gas quantity" multiplied by 1.63) multiplied by 100 = .....%
Can you help me?
Grettings Berno