查看“LUA命令”的源代码
←
LUA命令
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
= Domoticz中的Lua命令及变量列表 = 创建此页面以概述可在Domoticz中使用的Lua中的所有可能的命令和变量。 论坛上已经有很多资料可供参考,但是都是分散的而且语法并不是很清楚。 THIS PAGE IS STILL UNDER CONSTRUCTION == 基本 == <syntaxhighlight lang="lua"> 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 </syntaxhighlight> === 在一次提交中更新多个设备 === <syntaxhighlight lang="lua"> 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 </syntaxhighlight> == 调试 == === 用于列出所有可用变量的方法 === <syntaxhighlight lang="lua"> 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,''); </syntaxhighlight> == 日期和时间 == === 用于计算时差的方法 === <syntaxhighlight lang="lua"> --timedifference("2017-05-27 14:43:54") function timedifference(timestamp) 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</syntaxhighlight> 用法<syntaxhighlight lang="lua"> s = otherdevices_lastupdate['mydevice'] if(otherdevices['mydevice']=='On' and timedifference(s) > 600) then commandArray['mydevice']='Off' end</syntaxhighlight> === 白天还是晚上 === 检查当前时间是白天还是晚上 <syntaxhighlight lang="lua"> if (timeofday['Daytime']) then ... 或者 if (timeofday['Nighttime']) then ... </syntaxhighlight> == 设备 == [[Category:Domoticz]] [[Category:手册]] [[Category:设置]] [[Category:脚本]] [[Category:Lua]]
返回
LUA命令
。
导航菜单
个人工具
登录
命名空间
页面
讨论
大陆简体
查看
阅读
查看源代码
查看历史
更多
搜索
导航
Wiki首页
Domoticz 中文站
Domoticz 论坛
Domoticz Github
随机页面
特殊页面
特殊页面
所有页面
分类
最近更改
工具
链入页面
相关更改
特殊页面
页面信息