Page 1 of 1

Scene Timers Read in LUA

Posted: Monday 12 December 2016 13:10
by TimH
Hi,

it is possible to read out the Timers of a Scene in LUA and the Command(On/Off)?

Thanks

TimH

Re: Scene Timers Read in LUA

Posted: Monday 12 December 2016 18:51
by jvdz
This is a way to do a JSON call and translate the returned data:

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 Scene Timers
local t, jresponse, status, decoded_response,idx
-- ### update the next 2 lines ##########################################
idx=9     -- IDX of the Scene
t = "http://192.168.xx.xx:8080/json.htm?type=scenetimers&idx="..tostring(idx)
-- ###################################################################
jresponse, status = http.request(t)
decoded_response = JSON:decode(jresponse)
result = decoded_response["result"]
--
-- List all SceneTimers
--
if result == nil then
	print(os.date("%X").." No scene timers found for IDX "..idx)
else
	for i = 1, #result do
	record = result[i]
		if type(record) == "table" then
			day = record["d"]
			value = record["v"]
			print(os.date("%X").." "..i..
			"  Active="..record["Active"]..
			"  Cmd="..record["Cmd"]..
			"  Date="..record["Date"]..
			"  Hue="..record["Hue"]..
			"  Level="..record["Level"]..
			"  Randomness="..record["Randomness"]..
			"  Time="..record["Time"]..
			"  Type="..record["Type"]..
			"  idx="..record["idx"]
			)
		end
	end
end
Jos

Re: Scene Timers Read in LUA

Posted: Tuesday 13 December 2016 11:49
by TimH
Thank you. I will try it the next days.

Re: Scene Timers Read in LUA

Posted: Tuesday 13 December 2016 13:10
by TimH
Hello,

i have tried your Script but i got some failure with the libraries.
I use a Synology Diskstation to run Domoticz and this don't have the libraries.
Searching the Internet don't look good for Synology Lua Libraries.

Have anybody the right libraries or a idea where i can fount them?

Thanks!

Re: Scene Timers Read in LUA

Posted: Tuesday 13 December 2016 13:39
by jvdz
The libraries can be found here: https://www.domoticz.com/wiki/Remote_Co ... _Libraries
This is a description for a Raspberry Pi so might need tweaking.

Jos

Re: Scene Timers Read in LUA

Posted: Wednesday 14 December 2016 9:46
by TimH
Hi,

thank you for the Link.
I tried to translate it to Synology but i get failure.

Where are defined the Folder, where the location of the Libraries?

Re: Scene Timers Read in LUA

Posted: Wednesday 14 December 2016 16:31
by jvdz
I think the error message, you get about not being able to find the require("LIB"), is telling you in which directories it was looking for these functions? at least that is what I seem to remember happening for me on a raspberry.

Jos

Re: Scene Timers Read in LUA

Posted: Wednesday 14 December 2016 19:38
by TimH
HI.
error Message in domoticz:

Code: Select all

2016-12-14 08:14:03.753 Error: EventSystem: in READOUT: [string "-- LUA to get GASMETER usage..."]:3: module 'socket.http' not found:
no field package.preload['socket.http']
no file '/usr/local/share/lua/5.2/socket/http.lua'
no file '/usr/local/share/lua/5.2/socket/http/init.lua'
no file '/usr/local/lib/lua/5.2/socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http/init.lua'
no file './socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket/http.so'
no file '/usr/local/lib/lua/5.2/socket.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket.so'
I have unpack the Files as indicated in the instructions and in the existing LUA-Folder from the Diskstation.
But i Think i must change the locating Folder for the Library.

Re: Scene Timers Read in LUA

Posted: Tuesday 21 March 2017 0:47
by wervisser
Bump...

Did you by any chance got this fixed ?

Re: Scene Timers Read in LUA

Posted: Tuesday 15 May 2018 21:24
by niki_lauda
TimH wrote:
Wednesday 14 December 2016 19:38
HI.
error Message in domoticz:

Code: Select all

2016-12-14 08:14:03.753 Error: EventSystem: in READOUT: [string "-- LUA to get GASMETER usage..."]:3: module 'socket.http' not found:
no field package.preload['socket.http']
no file '/usr/local/share/lua/5.2/socket/http.lua'
no file '/usr/local/share/lua/5.2/socket/http/init.lua'
no file '/usr/local/lib/lua/5.2/socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http/init.lua'
no file './socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket/http.so'
no file '/usr/local/lib/lua/5.2/socket.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket.so'
I have unpack the Files as indicated in the instructions and in the existing LUA-Folder from the Diskstation.
But i Think i must change the locating Folder for the Library.
Did you fix it?

Re: Scene Timers Read in LUA

Posted: Tuesday 15 May 2018 21:29
by niki_lauda
wervisser wrote:
Tuesday 21 March 2017 0:47
Bump...

Did you by any chance got this fixed ?
Did you fix it?