Page 1 of 1
LUA: Get daily usage P1 Gas Meter
Posted: Wednesday 30 November 2016 7:29
by dutchdevil83
In domoticz there are 2 values for gas usage, 1 is total gas consumption the other one (in the right corner of the "sensor") is daily usage. How can i get that value in LUA? When i want to get the value with:
i only get the total consumption. I want to have daily consumption....
Re: LUA: Get daily usage P1 Gas Meter
Posted: Wednesday 30 November 2016 10:26
by stlaha2007
When i
Re: LUA: Get daily usage P1 Gas Meter
Posted: Wednesday 30 November 2016 10:26
by stlaha2007
When i do a jsonnrequest in my browser i'll get a replay with counter and countertoday...
It looks like the ''default'' lua command replies with the counter. Maybe (i don't have it at the moment) you need to form an alternative command...
Take a look at the wiki scripts/examples. There are some that doing simular things [Mindergas or Daily Notification Energy Usage]
Re: LUA: Get daily usage P1 Gas Meter
Posted: Wednesday 30 November 2016 11:03
by dutchdevil83
stlaha2007 wrote:When i do a jsonnrequest in my browser i'll get a replay with counter and countertoday...
It looks like the ''default'' lua command replies with the counter. Maybe (i don't have it at the moment) you need to form an alternative command...
Take a look at the wiki scripts/examples. There are some that doing simular things [Mindergas or Daily Notification Energy Usage]
Looked into that but this works with JSON. Is there anyway to do this with using LUA only without using a curl command?
Re: LUA: Get daily usage P1 Gas Meter
Posted: Wednesday 30 November 2016 14:15
by stlaha2007
Sorry to reply again. This time with a link:
http://domoticz.com/wiki/Smart_Lua_Scripts
Check the part of the WeatherStation Readout....
It explains (sample code) how it works to get multiple values from 1 sensor. Basicly the P1Meter Electricity or P1Meter Gas are also devices with MultiValue Properties.
I do write scripts, and can read them, but not doing it with LUA.
I would suggest, like earlier, with json what are the values on the device, with named value contains the value you want, and adapt modify it to your needs.
As i think the code for Weatherstation will help you exactly with your request...
Re: LUA: Get daily usage P1 Gas Meter
Posted: Wednesday 30 November 2016 15:11
by dutchdevil83
Thanx for trying to help me, no need to sorry!
For P1 meter Electricity this works out, had already done that. For Gas Meter (also P1) i can`t get multiple values with LUA... Only get the total usage as svalue
Re: LUA: Get daily usage P1 Gas Meter
Posted: Wednesday 30 November 2016 19:11
by stlaha2007
Need to say sorry. Apparently i misunderstood what LUA is capable of sending.
Now i have reread the discription. My convlusion it only sends the data in the counter part.
What i do, and probebly why i'm not using Lua, is read data like an array and split that through json with Perl/PHP and most of the times with bash.
So i guess you cant get other values through svalue send into your script with Lua.
A few days ago someone pointed out you have the ability to 'embed' function libraries.
Perhaps somebody wrote a json library to get the other data?
Re: LUA: Get daily usage P1 Gas Meter
Posted: Wednesday 30 November 2016 20:31
by jvdz
This is an LUA script which will retrieve the last 8 days data as used by the Week graph and shows the 8 values and today's value.
It requiers some generic LUA libraries as also used by DTGBOT (see wiki in case they are missing)
Code: Select all
-- LUA to get GASMETER usage
--###############################
-- Load necessary Lua libraries
--###############################
http = require "socket.http";
socket = require "socket";
https = require "ssl.https";
JSON = require "JSON";
--Get values of previous 8 days
local t, jresponse, status, decoded_response,idx
idx=376 -- IDX of the GASMETER
t = "http://192.168.0.xx:8080/json.htm?type=graph&sensor=counter&range=week&idx="..tostring(idx)
jresponse, status = http.request(t)
decoded_response = JSON:decode(jresponse)
result = decoded_response["result"]
--
-- List all data
--
for i = 1, #result do
record = result[i]
if type(record) == "table" then
day = record["d"]
value = record["v"]
print(os.date("%X").." "..i.." Gebruik dag="..day.." gebruik="..value)
end
end
--
-- Todays data
--
print(os.date("%X").." vandaag="..result[8]["d"].." gebruik="..result[8]["v"])
Jos
Re: RE: Re: LUA: Get daily usage P1 Gas Meter
Posted: Wednesday 30 November 2016 22:55
by stlaha2007
jvdz wrote:
json library
Jos
Jos, Thanks for pointing at this...
TP has a few samples to build his script.
Maybe I need to re-investigate one of my wishes, as that resulted to bash and python scripts for now. Had to build a few 'time-based'.
Especialy the event-driven part that comes with lua, would make a difference.
Re: LUA: Get daily usage P1 Gas Meter
Posted: Thursday 01 December 2016 9:13
by dutchdevil83
Thnx Jos for sharing the code!
So i have to do this definitely with JSON. I was hoping i could do it directly with LUA without including libraries. On other hand with this script i can also get history values from other sensors right?
Many thanx for sharing again.
Re: LUA: Get daily usage P1 Gas Meter
Posted: Thursday 01 December 2016 22:25
by jvdz
dutchdevil83 wrote:On other hand with this script i can also get history values from other sensors right?
Any device that generates a set of graphs should work.
Jos
Re: LUA: Get daily usage P1 Gas Meter
Posted: Sunday 11 December 2016 21:56
by edraket
Hi Jos,
Excellent piece of code, thanks for sharing.
I was hoping that I can use this code in the Domoticz Lua editor (is that the socalled database Lua?). Can I include libraries in this way or only in file based LUA?
I assume that it works as well with the degree days calculation of Domoticz, because that's what I want to do: create a LUA scripts that calculate the daily gas consumption based on the degree days and put that in a counter
Where can I find the libraries?
Thanks, Ed
Re: LUA: Get daily usage P1 Gas Meter
Posted: Sunday 11 December 2016 22:38
by jvdz
I am not using the internal editor but would think it should work as well. Just give it a try and let us know.
The libraries can be found here:
https://www.domoticz.com/wiki/Remote_Co ... _Libraries
Jos
Re: RE: Re: LUA: Get daily usage P1 Gas Meter
Posted: Monday 19 December 2016 17:55
by jake
edraket wrote:Hi Jos,
Excellent piece of code, thanks for sharing.
...
I assume that it works as well with the degree days calculation of Domoticz, because that's what I want to do: create a LUA scripts that calculate the daily gas consumption based on the degree days and put that in a counter
Thanks, Ed
I would like to do the same and I have seen this degrees days in the settings, but have no idea where Domoticz outputs that.
When you have a working script, please share.
Re: LUA: Get daily usage P1 Gas Meter
Posted: Wednesday 15 February 2017 10:11
by SilentNL
I created a LUA script for daily gas consumption based on the degree days. See:
viewtopic.php?f=61&t=16124
Perhaps it is useful for you