LUA: Get daily usage P1 Gas Meter

Moderator: leecollings

Post Reply
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

LUA: Get daily usage P1 Gas Meter

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

Code: Select all

otherdevices_svalues['Gas Meter']
i only get the total consumption. I want to have daily consumption....
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post by stlaha2007 »

When i
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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]
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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?
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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...
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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?
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: RE: Re: LUA: Get daily usage P1 Gas Meter

Post 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.
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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.
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
edraket
Posts: 3
Joined: Friday 08 January 2016 0:13
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: RE: Re: LUA: Get daily usage P1 Gas Meter

Post 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.
SilentNL
Posts: 6
Joined: Thursday 25 June 2015 10:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: LUA: Get daily usage P1 Gas Meter

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest