LUA命令:修订间差异

来自Domoticz
(创建页面,内容为“ = LUA commands and variables list for use in Domoticz = This page is created to give an overview of all the possible commands and variables in Lua that can be used...”)
 
第1行: 第1行:


= LUA commands and variables list for use in Domoticz =
= Domoticz中的Lua命令及变量列表 =
This page is created to give an overview of all the possible commands and variables in Lua that can be used in Domoticz.
创建此页面以概述可在Domoticz中使用的Lua中的所有可能的命令和变量。
There is already a lot of information available on the forum, but this is scattered throughout. Next to that, the syntax is not always clear.
论坛上已经有很多资料可供参考,但是都是分散的而且语法并不是很清楚。


THIS PAGE IS STILL UNDER CONSTRUCTION
THIS PAGE IS STILL UNDER CONSTRUCTION




== General ==
== 基本 ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">


第30行: 第30行:
</syntaxhighlight>
</syntaxhighlight>


=== Update multiple devices in one pass ===
=== 在一次提交中更新多个设备 ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
commandArray = {}
commandArray = {}
第43行: 第43行:
</syntaxhighlight>
</syntaxhighlight>


== Debugging ==
== 调试 ==


=== Function to dump all variables supplied to the script ===
=== 用于列出所有可用变量的方法 ===


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
第63行: 第63行:
</syntaxhighlight>
</syntaxhighlight>


== Date and Time ==
== 日期和时间 ==


=== Funtion to calculate the time difference ===
=== 用于计算时差的方法 ===


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
第75行: 第75行:
end</syntaxhighlight>
end</syntaxhighlight>


=== Time of day ===
=== 白天还是晚上 ===
Check if it is daytime or nighttime
检查当前时间是白天还是晚上
 
Example:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
if (timeofday['Daytime']) then ...
if (timeofday['Daytime']) then ...


or
或者


if (timeofday['Nighttime']) then ...
if (timeofday['Nighttime']) then ...
</syntaxhighlight>
</syntaxhighlight>


== Devices ==
== 设备 ==


[[Category:Domoticz]]
[[Category:Domoticz]]

2017年5月27日 (六) 09:10的版本

Domoticz中的Lua命令及变量列表

创建此页面以概述可在Domoticz中使用的Lua中的所有可能的命令和变量。 论坛上已经有很多资料可供参考,但是都是分散的而且语法并不是很清楚。

THIS PAGE IS STILL UNDER CONSTRUCTION


基本

commandArray = {}
if (devicechanged['MyDeviceName'] == 'On' and otherdevices['MyOtherDeviceName'] == 'Off') then
   commandArray['MyOtherDeviceName1']='On'
   commandArray['MyOtherDeviceName2']='On'
   commandArray['MyOtherDeviceName3']='Off'
   commandArray['MyOtherDeviceName4']='On FOR 10' -- minutes
   commandArray['MyOtherDeviceName5']='Off RANDOM 30' -- random within x minutes
   commandArray['Scene:MyScene']='On'
   commandArray['Group:MyGroup']='Off AFTER 30' -- seconds
   commandArray['SendNotification']='subject#body#extraData#priority#sound'
   commandArray['OpenURL']='www.yourdomain.com/api/movecamtopreset.cgi' 
   commandArray['SendEmail']='subject#body#to'
   commandArray['Variable:MyVar']='Some value'
   commandArray['SetSetPoint:MySetPointIdx']='20.5'
   commandArray['UpdateDevice']='idx|nValue|sValue' -- for updating Dummy devices e.g. '96|0|Hello World'
end
return commandArray

在一次提交中更新多个设备

commandArray = {}
local function update(idx, value1, value2)
    local cmd = string.format("%d|0|%.2f;%.2f", idx, value1, value2)
    table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end

update (16, 320, 0)
update (19, 4, 25)
return commandArray

调试

用于列出所有可用变量的方法

function LogVariables(x,depth,name)
    for k,v in pairs(x) do
        if (depth>0) or ((string.find(k,'device')~=nil) or (string.find(k,'variable')~=nil) or 
                         (string.sub(k,1,4)=='time') or (string.sub(k,1,8)=='security')) then
            if type(v)=="string" then print(name.."['"..k.."'] = '"..v.."'") end
            if type(v)=="number" then print(name.."['"..k.."'] = "..v) end
            if type(v)=="boolean" then print(name.."['"..k.."'] = "..tostring(v)) end
            if type(v)=="table" then LogVariables(v,depth+1,k); end
        end
    end
end
-- call with this command
LogVariables(_G,0,'');

日期和时间

用于计算时差的方法

function timedifference(s)
  y, m, d, H, M, S = timestamp:match("(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)")
  difference = os.difftime(os.time(), os.time{year=y, month=m, day=d, hour=H, min=M, sec=S})
  return difference
end

白天还是晚上

检查当前时间是白天还是晚上

if (timeofday['Daytime']) then ...

或者

if (timeofday['Nighttime']) then ...

设备