Energy in dummy device in LUA

Post Reply
journeyman
Posts: 27
Joined: Sunday 04 December 2016 17:21
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Energy in dummy device in LUA

Post by journeyman » Monday 06 March 2017 20:29

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
Bez tytułu.png
Bez tytułu.png (29.07 KiB) Viewed 1210 times
How in LUA can I take Daily usage from my first counter and put it to second "Daily" one?

supermat
Posts: 13
Joined: Thursday 07 April 2016 18:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Energy in dummy device in LUA

Post by supermat » Tuesday 07 March 2017 0:44

Hello,

I made something similar but with two tarif.
Sorry, it's in french :
https://matdomotique.wordpress.com/2017 ... f-virtuel/

journeyman
Posts: 27
Joined: Sunday 04 December 2016 17:21
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Energy in dummy device in LUA

Post by journeyman » Tuesday 07 March 2017 11:14

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.

journeyman
Posts: 27
Joined: Sunday 04 December 2016 17:21
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Energy in dummy device in LUA

Post by journeyman » Tuesday 07 March 2017 12:16

I try to use your script, I put my ID devices. but I get an error :oops:

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) 

supermat
Posts: 13
Joined: Thursday 07 April 2016 18:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Energy in dummy device in LUA

Post by supermat » Tuesday 07 March 2017 13:59

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.

journeyman
Posts: 27
Joined: Sunday 04 December 2016 17:21
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Energy in dummy device in LUA

Post by journeyman » Tuesday 07 March 2017 16:08

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

journeyman
Posts: 27
Joined: Sunday 04 December 2016 17:21
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Energy in dummy device in LUA

Post by journeyman » Tuesday 07 March 2017 16:18

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?

supermat
Posts: 13
Joined: Thursday 07 April 2016 18:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Energy in dummy device in LUA

Post by supermat » Tuesday 07 March 2017 20:05

You can show that directly in domoticz. Inside the device.


Envoyé de mon iPhone en utilisant Tapatalk

Abbadon
Posts: 55
Joined: Thursday 01 October 2015 8:25
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland, Wrocław
Contact:

Re: Energy in dummy device in LUA

Post by Abbadon » Sunday 19 March 2017 11:22

supermat wrote:You can show that directly in domoticz. Inside the device.


Envoyé de mon iPhone en utilisant Tapatalk
can you tell us more?

Abbadon
Posts: 55
Joined: Thursday 01 October 2015 8:25
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland, Wrocław
Contact:

Re: Energy in dummy device in LUA

Post by Abbadon » Sunday 19 March 2017 14:07

journeyman 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?
idk if that possible in LUA, i made it in bash, take your counter IDX
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&param=udevice&IDX=120&nvalue=0&svalue="$data"kWh"
curl --silent $string
make that script executable with

Code: Select all

chmod +x filename.sh
and then add to cron like (every 1 min, for 5mins interval change first '*' with '*/5'

Code: Select all

* * * * * sh /home/pi/domoticz/scripts/daily.sh
in imperihome add it, change icon and its ok.

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
Screenshot_2017-03-19-15-17-21.png (252.37 KiB) Viewed 1049 times

journeyman
Posts: 27
Joined: Sunday 04 December 2016 17:21
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Energy in dummy device in LUA

Post by journeyman » Monday 20 March 2017 16:59

Thats great! :)
Thank you!

But how can i split it in to T1 and T2? To make calculation and show "Today costs"

Abbadon
Posts: 55
Joined: Thursday 01 October 2015 8:25
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland, Wrocław
Contact:

Re: Energy in dummy device in LUA

Post by Abbadon » Monday 20 March 2017 20:26

no idea, probably need to call database

User avatar
Brutus
Posts: 283
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Heerlen, The Netherlands
Contact:

Re: Energy in dummy device in LUA

Post by Brutus » 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.

Code: Select all

sEnergyPower, sEnergyTotal = otherdevices_svalues['Energie']:match("([^;]+);([^;]+)")
I can't extract the part from the French LUA because I don't understand it.
1x Intel NUC D54250WYK (Windows 7)
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
17x Fibaro Modules

journeyman
Posts: 27
Joined: Sunday 04 December 2016 17:21
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Energy in dummy device in LUA

Post by journeyman » Thursday 03 August 2017 9:40

After yesterday update to Beta 3.8197 This counter with T1 T2 is not working anymore :?


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 :oops:

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

Post Reply

Who is online

Users browsing this forum: jake and 3 guests