Page 1 of 1
Set Temperature using Lua
Posted: Sunday 08 November 2015 5:10
by thebeetleuk
I want to set the temperature of a virtual device using something like...
commandArray['Temperature House'] = tostring(current)
.. which doesn't work. How can I do this without using the IDX?
Re: Set Temperature using Lua
Posted: Sunday 08 November 2015 18:59
by oeildefeu
why without IDX ?
Re: Set Temperature using Lua
Posted: Sunday 08 November 2015 20:45
by thebeetleuk
Because I want to define the dummy temperature device by name (as a variable), and don't want to have to specify the IDX as well.
Re: Set Temperature using Lua
Posted: Tuesday 10 November 2015 21:44
by thebeetleuk
anyone?
Re: Set Temperature using Lua
Posted: Friday 13 November 2015 9:50
by zofiel
Think that this option can't be enabled at the moment in lua.
you have to use the idx format
Re: Set Temperature using Lua
Posted: Friday 13 November 2015 16:07
by jvdz
This is an example of a script that can retrieve the IDX for a devicename which you then can use to set an device with its IDX:
Code: Select all
commandArray = {}
-- Load necessary Lua libraries
http = require "socket.http";
JSON = require "JSON";
server_url="http://192.168.0.xx:8080"
-- Function to retrieve the IDX for a DeviceName
function GetDeviceIDX(DeviceName)
-- get device IDX from Domotics
local DeviceIDX,result,record
DeviceIDX = 99999
DeviceURL="type=devices&order=name&used=true"
t = server_url.."/json.htm?" .. DeviceURL
jresponse, status = http.request(t)
decoded_response = JSON:decode(jresponse)
result = decoded_response['result']
for i = 1, #result do
record = result[i]
if record['Name'] == DeviceName then
DeviceIDX=record['idx']
break
end
end
return DeviceIDX
end
DeviceName="ThermostaatHK"
DeviceIDX = GetDeviceIDX(DeviceName)
if DeviceIDX == 99999 then
print(" DeviceName "..DeviceName.." not found.")
else
print(" DeviceName "..DeviceName.." DeviceIDX="..DeviceIDX)
end
return commandArray
The required libraries and how to install can be found in the DTGBOT wiki.
Jos
Re: Set Temperature using Lua
Posted: Monday 16 November 2015 21:51
by thebeetleuk
thanks!!