How to get summary power consumption from different counters ?

Moderator: leecollings

Post Reply
PowerTech
Posts: 1
Joined: Thursday 01 October 2015 22:16
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4351
Contact:

How to get summary power consumption from different counters ?

Post 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.
derrij
Posts: 14
Joined: Friday 30 December 2016 12:14
Target OS: Linux
Domoticz version:
Contact:

Re: How to get summary power consumption from different counters ?

Post by derrij »

interested too
derrij
Posts: 14
Joined: Friday 30 December 2016 12:14
Target OS: Linux
Domoticz version:
Contact:

Re: How to get summary power consumption from different counters ?

Post 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
Abbadon
Posts: 40
Joined: Thursday 01 October 2015 8:25
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland, Wrocław
Contact:

Re: How to get summary power consumption from different counters ?

Post 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
kispalsz
Posts: 31
Joined: Friday 13 October 2017 19:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to get summary power consumption from different counters ?

Post 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.
Bernoo
Posts: 6
Joined: Sunday 07 January 2018 22:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.97
Location: Germany
Contact:

Re: How to get summary power consumption from different counters ?

Post 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
don't drink whisky without water and don't drink water without whisky...
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest