-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit script_device_power2p1.lua to sum power from more generators int…
…o a single virtual meter device
- Loading branch information
CreasolTech
committed
Jun 11, 2024
1 parent
38489b0
commit 9c922b3
Showing
1 changed file
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
-- scripts/lua/script_device_power2p1.lua - Called by script_device_master.lua | ||
-- scripts/lua/script_device_power2p1.lua | ||
-- Written by Creasol, https://creasol.it [email protected] | ||
-- Used to fill a virtual P1 meter with import and export power/energy. P1 meter is used by the Energy Dashboard | ||
-- You have to create, in Domoticz -> Setup -> Hardware, a virtual P1 meter and update the 4 variables below. | ||
-- Also, it groups several energy sources (photovoltaic1, photovoltaic2, wind, ...) into a single renewable generator virtual device, used by the Energy Dashboard | ||
-- The virtual device (name is written in GENERATOR_SUM_DEV below) should be created manually: see below. | ||
|
||
GRID_DEV="PowerMeter Grid" -- source used to measure the grid power (negative when producing) | ||
P1_DEV="PowerMeter Grid P1" -- virtual P1 meter that should be feed by this script | ||
TARIFF1_START=420 -- minutes since midnight when TARIFF1 starts (420=7:00) | ||
TARIFF1_STOP=1360 -- minutes since midnight when TARIFF2 stops (1360=23:00) | ||
|
||
--GENERATOR_SUM_DEV='' -- If Empty, skip the function that sums more generators into a single generator | ||
GENERATOR_SUM_DEV='PowerMeter_Renewable' -- Virtual kWh meter that must be created manually from Setup -> Hardware : it will be used to sum the generator power | ||
GENERATOR_DEVS={'PV_PowerMeter', 'PV_Garden'} -- Empty => skip the function that sums prod | ||
|
||
commandArray={} | ||
if (devicechanged[GRID_DEV]~=nil) then | ||
devValue=devicechanged[GRID_DEV] -- general kWh meter returns power;energy | ||
|
@@ -84,6 +90,21 @@ if (devicechanged[GRID_DEV]~=nil) then | |
commandArray[0]={['UpdateDevice']=otherdevices_idx[P1_DEV].."|0|"..str} | ||
commandArray['Variable:zP1Energy']=tostring(energy) | ||
-- print('Power2P1: energy='..energy..'Wh energyOld='..energyOld..'Wh energyDiff='..energyDiff..'Wh => Update P1 meter with values '..str) | ||
|
||
if (GENERATOR_SUM_DEV~='') then | ||
if (otherdevices[GENERATOR_SUM_DEV]==nil) then | ||
print('Power2P1: please create a Electric Instant+Counter device from Setup -> Hardware, named '..GENERATOR_SUM_DEV..', and set it in "Computed" mode') | ||
else | ||
powerout=0 | ||
for i,devName in pairs(GENERATOR_DEVS) do | ||
for str in otherdevices_svalues[devName]:gmatch("[^;]+") do | ||
powerout=powerout+tonumber(str) | ||
break | ||
end | ||
end | ||
commandArray[#commandArray+1]={['UpdateDevice']=otherdevices_idx[GENERATOR_SUM_DEV].."|0|"..powerout..';0'} | ||
end | ||
end | ||
end | ||
return commandArray | ||
|