lua基础脚本 - 通过某一设备的状态来联动其它设备

文档:
https://en.domoticz.cn/wiki/DzVents:_ne ... _scripting
回复
头像
DT27
帖子: 345
注册时间: 周四 3月 30, 2017 08:54
Gender:

lua基础脚本 - 通过某一设备的状态来联动其它设备

帖子 DT27 »

代码中
OnePlus3 是我的手机对应的虚拟开关,通过linux系统监测wifi设备在线脚本来更改虚拟开关状态。
两条横线 是注释。
timeofday['Nighttime'] 代表从太阳落山到太阳升起之间的时间。
事件编辑器中要选择Device。

代码: 全选

commandArray = {}
if devicechanged['OnePlus3'] then
    --
    -- 晚上到家
    --
    if(otherdevices["OnePlus3"] == "On" and timeofday['Nighttime']) then
        -- print("晚上到家,开灯")
        if(otherdevices["客厅灯"]=="Off") then
            commandArray['客厅灯'] = "On"
        end
        if(otherdevices["卧室灯"]=="Off") then
            commandArray['卧室灯'] = "On"
        end
    end

    --
    -- 离家
    --
    if (otherdevices["OnePlus3"] == "Off") then
        -- print("离家")
        if(otherdevices["卧室灯"]=="On") then
            commandArray['卧室灯'] = "Off"
        end
        if(otherdevices["客厅灯"]=="On") then
            commandArray['客厅灯'] = "Off"
        end
        if(otherdevices["s1"]=="On") then
            commandArray['s1'] = "Off"
        end
        if(otherdevices["s2"]=="On") then
            commandArray['s2'] = "Off"
        end
        --if(otherdevices["电热毯(s3)"]=="On") then
        --    commandArray['电热毯(s3)'] = "Off"
        --end
        --if(otherdevices["显示器(s4)"]=="On") then
        --    commandArray['显示器(s4)'] = "Off"
        --end
    end
end

return commandArray
屏幕快照 2017-06-07 14.36.41.jpg
屏幕快照 2017-06-07 14.36.41.jpg (61.96 KiB) 查看 16943 次
blindlight
帖子: 98
注册时间: 周四 3月 30, 2017 00:03

Re: lua基础脚本 - 通过某一设备的状态来联动其它设备

帖子 blindlight »

可以不用循环扫设备 直接devicechanged就可以了
头像
DT27
帖子: 345
注册时间: 周四 3月 30, 2017 08:54
Gender:

Re: lua基础脚本 - 通过某一设备的状态来联动其它设备

帖子 DT27 »

blindlight 写了: 周三 6月 07, 2017 13:57 可以不用循环扫设备 直接devicechanged就可以了
:D 改成devicechanged了
kingmos
帖子: 23
注册时间: 周六 5月 20, 2017 00:58

Re: lua基础脚本 - 通过某一设备的状态来联动其它设备

帖子 kingmos »

看起来好简单啊~~
头像
DT27
帖子: 345
注册时间: 周四 3月 30, 2017 08:54
Gender:

Re: lua基础脚本 - 通过某一设备的状态来联动其它设备

帖子 DT27 »

kingmos 写了: 周三 6月 07, 2017 16:59 看起来好简单啊~~
本来lua就挺简单的。研究一两天就能自己写了。
blindlight
帖子: 98
注册时间: 周四 3月 30, 2017 00:03

Re: lua基础脚本 - 通过某一设备的状态来联动其它设备

帖子 blindlight »

还不够简单 8-)

代码: 全选

if devicechanged['OnePlus3'] == "On" and timeofday['Nighttime'] then
 ......
回复