Total power use

Moderator: leecollings

Post Reply
tony5093
Posts: 1
Joined: Friday 26 October 2018 3:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Total power use

Post by tony5093 »

I have many Sonoff POW and Medion units.
Each sends power use to the Domoticz server.
Now I would like to have a total of all the power consumption and have this displayed on the Utility page.
How can this be done?
Does anyone have an example?

Thanks in advance
SweetPants

Re: Total power use

Post by SweetPants »

tony5093 wrote: Friday 26 October 2018 3:53 How can this be done?
Just my 2 cents
1) Create a dummy device according your needs
2) Write a dz_Ventz script that gathers all data and update the dummy device
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Total power use

Post by waaren »

tony5093 wrote: Friday 26 October 2018 3:53 I have many Sonoff POW and Medion units.
Each sends power use to the Domoticz server.
Now I would like to have a total of all the power consumption and have this displayed on the Utility page.
How can this be done?
Does anyone have an example?

Thanks in advance
What are the type / subtypes of the domoticz devices receiving the power usages ?
Did you name these devices according to a naming convention ? (something like SonoffPowerUsage_1 .... SonoffPowerUsage_many)
Do you want to have the total displayed on a text sensor or alert sensor (or both) ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dospider
Posts: 15
Joined: Monday 04 August 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Total power use

Post by dospider »

Toy5093,
Do you have allready a solution? I'm looking for a solution to show the total power use again. This is gone with the new version of domoticz.
When you go to devices the total is there, but you can't see it within the utility page.
User avatar
michaldobrotka
Posts: 50
Joined: Sunday 01 November 2015 17:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Total power use

Post by michaldobrotka »

This is my lua script - counting together power use from 3 Phases and updating dummy device IDX 705 (Total).

Code: Select all

----------------------------------------------------------------------------------------------------------
local DeviceName1 = "Faza1" 		
local DeviceName2 = "Faza2" 		
local DeviceName3 = "Faza3" 		
local ConsumptionIDX = 705  			-- 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
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
 
	-- Calculate consumption
	PowerConsumption = Power1 + Power2 + Power3
	if Debug=="YES" then
		print("  ----- PowerConsumption = " .. PowerConsumption .. " W");
	end
	EnergyConsumption = Energy1 + Energy2 + Energy3 
	if Debug=="YES" then
		print("  ----- EnergyConsumption = " .. EnergyConsumption .. " Wh");
	end
 
	-- Update comsumption device in Domoticz
	if devicechanged[DeviceName1] or devicechanged[DeviceName2] or devicechanged[DeviceName3] then
		update(ConsumptionDeviceName, ConsumptionIDX, PowerConsumption, EnergyConsumption, 1)
	end
 
return commandArray
It is working, but Im geting Error message (needed some touchup) :

Code: Select all

2018-11-19 14:43:00.344 Error: EventSystem: in celkovaspotreba: [string "-- /home/pi/domoticz/scripts/lua/script_devic..."]:65: attempt to index global 'devicechanged' (a nil value) 
Domoticz on Raspi 3 and slave on ZeroW (running only with Broadlink plugin), Serial Mysensors GW on Arduino nano, Broadlink RM2, Rehau CO2 USB Stick, RF link 433 MHz, 2x Amazon Echo Dot (Controlicz), ESP2866 witk Espeasy, Sonoff
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest