Scene Timers Read in LUA

Must be cleaned all topics go to the right subforum
Post Reply
TimH
Posts: 14
Joined: Friday 11 November 2016 9:56
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Location: Germany
Contact:

Scene Timers Read in LUA

Post by TimH » Monday 12 December 2016 13:10

Hi,

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

Thanks

TimH

User avatar
jvdz
Posts: 1064
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Scene Timers Read in LUA

Post by jvdz » Monday 12 December 2016 18:51

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

TimH
Posts: 14
Joined: Friday 11 November 2016 9:56
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Location: Germany
Contact:

Re: Scene Timers Read in LUA

Post by TimH » Tuesday 13 December 2016 11:49

Thank you. I will try it the next days.

TimH
Posts: 14
Joined: Friday 11 November 2016 9:56
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Location: Germany
Contact:

Re: Scene Timers Read in LUA

Post by TimH » Tuesday 13 December 2016 13:10

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!

User avatar
jvdz
Posts: 1064
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Scene Timers Read in LUA

Post by jvdz » Tuesday 13 December 2016 13:39

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

TimH
Posts: 14
Joined: Friday 11 November 2016 9:56
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Location: Germany
Contact:

Re: Scene Timers Read in LUA

Post by TimH » Wednesday 14 December 2016 9:46

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?

User avatar
jvdz
Posts: 1064
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Scene Timers Read in LUA

Post by jvdz » Wednesday 14 December 2016 16:31

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

TimH
Posts: 14
Joined: Friday 11 November 2016 9:56
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Location: Germany
Contact:

Re: Scene Timers Read in LUA

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

wervisser
Posts: 21
Joined: Monday 28 November 2016 19:38
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Scene Timers Read in LUA

Post by wervisser » Tuesday 21 March 2017 0:47

Bump...

Did you by any chance got this fixed ?

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests