Energy in dummy device in LUA
Moderator: leecollings
-
- Posts: 23
- Joined: Sunday 04 December 2016 16:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Poland
- Contact:
Energy in dummy device in LUA
Hello,
I have working Energy usage device (Dummy based on Pulse and ESP Easy).
In my home system I would like to se in IMperiHOME my daily usage. So the shortest way is to create another device How in LUA can I take Daily usage from my first counter and put it to second "Daily" one?
I have working Energy usage device (Dummy based on Pulse and ESP Easy).
In my home system I would like to se in IMperiHOME my daily usage. So the shortest way is to create another device How in LUA can I take Daily usage from my first counter and put it to second "Daily" one?
-
- Posts: 14
- Joined: Thursday 07 April 2016 18:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Energy in dummy device in LUA
Hello,
I made something similar but with two tarif.
Sorry, it's in french :
https://matdomotique.wordpress.com/2017 ... f-virtuel/
I made something similar but with two tarif.
Sorry, it's in french :
https://matdomotique.wordpress.com/2017 ... f-virtuel/
-
- Posts: 23
- Joined: Sunday 04 December 2016 16:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Poland
- Contact:
Re: Energy in dummy device in LUA
Unfortunately, completely I do not understand French but that is exactly what I need. Only if it will work with pulse counter from ESPEasy?
I would like to have insight into total consumption, monthly, daily, along with the enumeration of costs - divided into two fares. Tariff change me quite often.
I would like to have insight into total consumption, monthly, daily, along with the enumeration of costs - divided into two fares. Tariff change me quite often.
-
- Posts: 23
- Joined: Sunday 04 December 2016 16:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Poland
- Contact:
Re: Energy in dummy device in LUA
I try to use your script, I put my ID devices. but I get an error
Code: Select all
2017-03-07 11:09:00.279 Error: EventSystem: in Elektrownia: [string "function log(p_message)..."]:21: bad argument #1 to 'pairs' (table expected, got nil)
2017-03-07 11:09:12.790 Error: EventSystem: in Elektrownia: [string "function log(p_message)..."]:29: attempt to perform arithmetic on global 'EnergyImportLow' (a nil value)
-
- Posts: 14
- Joined: Thursday 07 April 2016 18:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Energy in dummy device in LUA
Hello,
OK I think it is because your "idxCompteurIntelligent" is new and it has now initial value, so it return a nil value.
For the first time, the new CompteurIntelligent need to be initialize.
Can you add these lines before : EnergyImport = EnergyImportLow + EnergyImportHigh
-- For the first time, the value are not initilize in the smart counter, we set 0 by default.
if(EnergyImportLow == nil)then
EnergyImportLow =0
EnergyImportHigh =0
EnergyExportLow = 0
EnergyExportHigh =0
PowerImport = 0
PowerExport = 0
end
It must be use only the first time the script is call.
OK I think it is because your "idxCompteurIntelligent" is new and it has now initial value, so it return a nil value.
For the first time, the new CompteurIntelligent need to be initialize.
Can you add these lines before : EnergyImport = EnergyImportLow + EnergyImportHigh
-- For the first time, the value are not initilize in the smart counter, we set 0 by default.
if(EnergyImportLow == nil)then
EnergyImportLow =0
EnergyImportHigh =0
EnergyExportLow = 0
EnergyExportHigh =0
PowerImport = 0
PowerExport = 0
end
It must be use only the first time the script is call.
-
- Posts: 23
- Joined: Sunday 04 December 2016 16:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Poland
- Contact:
Re: Energy in dummy device in LUA
Thank you helped.
I ran once, then removed.
Now is:
"EventSystem: Script event triggered"
But do not change the meter reading, is still 0.0
I ran once, then removed.
Now is:
"EventSystem: Script event triggered"
But do not change the meter reading, is still 0.0
-
- Posts: 23
- Joined: Sunday 04 December 2016 16:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Poland
- Contact:
Re: Energy in dummy device in LUA
There was my mistake with one of ID.
Its look like it took to T2 all of my already taken 22kWh. I will make some test now
Thank you!
OK Its working perfect!
What is the easiest way to put some daily/monthly data of usage or costs to another dummy or tex device? To show it in some external system like ImperiHome?
Its look like it took to T2 all of my already taken 22kWh. I will make some test now
Thank you!
OK Its working perfect!
What is the easiest way to put some daily/monthly data of usage or costs to another dummy or tex device? To show it in some external system like ImperiHome?
-
- Posts: 14
- Joined: Thursday 07 April 2016 18:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Energy in dummy device in LUA
You can show that directly in domoticz. Inside the device.
Envoyé de mon iPhone en utilisant Tapatalk
Envoyé de mon iPhone en utilisant Tapatalk
-
- Posts: 40
- Joined: Thursday 01 October 2015 8:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Poland, Wrocław
- Contact:
Re: Energy in dummy device in LUA
can you tell us more?supermat wrote:You can show that directly in domoticz. Inside the device.
Envoyé de mon iPhone en utilisant Tapatalk
-
- Posts: 40
- Joined: Thursday 01 October 2015 8:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Poland, Wrocław
- Contact:
Re: Energy in dummy device in LUA
idk if that possible in LUA, i made it in bash, take your counter IDXjourneyman wrote:There was my mistake with one of ID.
Its look like it took to T2 all of my already taken 22kWh. I will make some test now
Thank you!
OK Its working perfect!
What is the easiest way to put some daily/monthly data of usage or costs to another dummy or tex device? To show it in some external system like ImperiHome?
Add dummy text sensor, take IDX
Code: Select all
#!/bin/bash
data=`curl --silent -is "http://ip:port/json.htm?type=devices&rid=IDX" |grep "CounterToday" |sed 's/"//g' |awk '{print $3}'`
string="http://ip:port/json.htm?type=command¶m=udevice&IDX=120&nvalue=0&svalue="$data"kWh"
curl --silent $string
Code: Select all
chmod +x filename.sh
Code: Select all
* * * * * sh /home/pi/domoticz/scripts/daily.sh
ive made the same script which do the same every day at 23:55 and show me usage from last day (left usage is prev day, right 'this' day)
- Attachments
-
- Screenshot_2017-03-19-15-17-21.png (252.37 KiB) Viewed 5265 times
-
- Posts: 23
- Joined: Sunday 04 December 2016 16:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Poland
- Contact:
Re: Energy in dummy device in LUA
Thats great!
Thank you!
But how can i split it in to T1 and T2? To make calculation and show "Today costs"
Thank you!
But how can i split it in to T1 and T2? To make calculation and show "Today costs"
-
- Posts: 40
- Joined: Thursday 01 October 2015 8:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Poland, Wrocław
- Contact:
Re: Energy in dummy device in LUA
no idea, probably need to call database
- Brutus
- Posts: 249
- Joined: Friday 26 September 2014 9:33
- Target OS: Windows
- Domoticz version:
- Location: Netherlands
- Contact:
Re: Energy in dummy device in LUA
How can I extract in LUA the daily usage of a energie sensor?
I want to extract the daily solar power generation and send it through a notification with maybe some other information.
A simple extraction like this code will not work because it gives me only the total energy and current power.
I can't extract the part from the French LUA because I don't understand it.
I want to extract the daily solar power generation and send it through a notification with maybe some other information.
A simple extraction like this code will not work because it gives me only the total energy and current power.
Code: Select all
sEnergyPower, sEnergyTotal = otherdevices_svalues['Energie']:match("([^;]+);([^;]+)")
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
-
- Posts: 23
- Joined: Sunday 04 December 2016 16:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Poland
- Contact:
Re: Energy in dummy device in LUA
After yesterday update to Beta 3.8197 This counter with T1 T2 is not working anymore
Im getting this in log
What can I do to solve that? Its stop working after update
Im getting this in log
Code: Select all
2017-08-03 09:38:00.277 Error: EventSystem: in Elektrownia: [string "function log(p_message)..."]:21: bad argument #1 to 'pairs' (table expected, got nil)
What can I do to solve that? Its stop working after update
Code: Select all
function log(p_message)
-- print("[HPHC] " .. p_message)
end
function getdevname4idx(deviceIDX)
for i, v in pairs(otherdevices_idx) do
if v == deviceIDX then
return i
end
end
return 0
end
commandArray = {}
DEBUG = false
local nomCompteurPrincipal = getdevname4idx(129) --OWL
local idxCompteurIntelligent = 133
local nomCompteurIntelligent = getdevname4idx(idxCompteurIntelligent)--HPHC
local nomHeureCreuse = getdevname4idx(134) -- Switch Heures Creuses
for deviceName,deviceValue in pairs(devicechanged) do
if (deviceName==nomCompteurPrincipal) then
-- On récupère la valeur du compteur unique => consEnergy
ConsPower, consEnergy = string.match(otherdevices_svalues[nomCompteurPrincipal], "(%d+%.*%d*);(%d+%.*%d*)")
log(ConsPower.."-"..consEnergy)
--on somme les compteurs HP et HC => EnergyImport
--http://www.domoticz.com/wiki/Upload_energy_data_to_PVoutput
EnergyImportLow, EnergyImportHigh, EnergyExportLow, EnergyExportHigh, PowerImport, PowerExport = otherdevices_svalues[nomCompteurIntelligent]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
EnergyImport = EnergyImportLow + EnergyImportHigh
EnergyExport = EnergyExportLow + EnergyExportHigh
log(" ----- PowerImport = " .. PowerImport .. " W");
log(" ----- EnergyImportLow = " .. EnergyImportLow .. " Wh");
log(" ----- EnergyImportHigh = " .. EnergyImportHigh .. " Wh");
log(" ----- EnergyImport = " .. EnergyImport .. " Wh");
log(" ----- PowerExport = " .. PowerExport .. " W");
log(" ----- EnergyExportLow = " .. EnergyExportLow .. " Wh");
log(" ----- EnergyExportHigh = " .. EnergyExportHigh .. " Wh");
log(" ----- EnergyExport = " .. EnergyExport .. " Wh");
--On calcule le delta avec le compteur actuel
delta = consEnergy - EnergyImport
--On ajoute le delta sur le bon tarif
if (otherdevices[nomHeureCreuse] == 'On') then
EnergyImportLow = EnergyImportLow + delta
else
EnergyImportHigh = EnergyImportHigh + delta
end
--On modifie le compteur intelligent
commandArray['UpdateDevice'] = idxCompteurIntelligent.."|0|"..EnergyImportLow..";"..EnergyImportHigh..";0;0;"..ConsPower..";0"
end
end
return commandArray
-
- Posts: 113
- Joined: Sunday 14 July 2013 22:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: NL
- Contact:
Re: Energy in dummy device in LUA
Hi Brutus,Brutus wrote: ↑Thursday 13 July 2017 0:44 How can I extract in LUA the daily usage of a energie sensor?
I want to extract the daily solar power generation and send it through a notification with maybe some other information.
A simple extraction like this code will not work because it gives me only the total energy and current power.I can't extract the part from the French LUA because I don't understand it.Code: Select all
sEnergyPower, sEnergyTotal = otherdevices_svalues['Energie']:match("([^;]+);([^;]+)")
Just came along your update and need the answer as well. Did you get an update or/and do you know to get the daily usage with LUA?
Hope you can help me.
regards,
Jeroen
- McMelloW
- Posts: 427
- Joined: Monday 20 November 2017 17:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.1
- Location: Harderwijk, NL
- Contact:
Re: Energy in dummy device in LUA
@Brutus, @Jeroenkl
This is not in Lua but in dzVents 2.4. You can try the following
Of course this is somewhere in the middle of a dzVents script.
This works for me to parse all 6 values form the Electricity devicce of the P1 Smart Meter and update to different devices.
Correct me if I am wrong
This is not in Lua but in dzVents 2.4. You can try the following
Code: Select all
local Energy = domoticz.devices(Energie).rawData
domoticz.devices(Power).updateCounter(Energy[1])
domoticz.devices(TotalEnergy).updateCounter(Energy[2])
This works for me to parse all 6 values form the Electricity devicce of the P1 Smart Meter and update to different devices.
Correct me if I am wrong
Greetings McMelloW
Who is online
Users browsing this forum: No registered users and 1 guest