I just started using Domoticz. The version and hardware I use:
Raspberry PI 2 B
Jessie lite Raspbarian
Domoticz: Version: 3.8153 / Build Hash: 494fff7
Fibaro Motion Sensor V2
AEON labs zwave USB gen5
I have almost no experience with LUA but I used the available examples I found online and the script is working for me.
There is just some things I would like to add.
The script I use need to turn on the light when movement is detected on specified time. For the specified time i use (2 diffirent) virtual switches, named "schema1" and "schema2"
In the bedrooms (slaapkamer) and hallways (gang) I only need to switch a single light based on a single motion detector. In the living room i have a group that I need to switch. I want that the script checks if the light is already on before it takes any action. I would also prefer that the script that turns the lights of checks if the lights are on before is switches off.
My first question: is it possible to check if a group is switched on (or mixed). And how can I do this?
My second question: is it a problem the script I use to switch off the light when no movement detected for xx minutes does not check if the lights are on?
The script I use to turn the lights (group) on (livingroom with more than 1 light):
Code: Select all
-- script_device_motion.lua
local motion_switch = 'WoonkamerPIR'
local status_switch = 'schema2'
commandArray = {}
if devicechanged[motion_switch] then
if otherdevices[motion_switch] == 'On' and otherdevices[status_switch] == 'On' then
commandArray['Group:Woonkamer']='On'
end
end
return commandArray
Code: Select all
-- script_time_nomotion.lua
local motion_switch = 'WoonkamerPIR'
local nomotion_uservar = 'nomotionCounter'
local status_switch = 'Group:Woonkamer'
commandArray = {}
no_motion_minutes = tonumber(uservariables[nomotion_uservar])
if (otherdevices[motion_switch] == 'Off') then
no_motion_minutes = no_motion_minutes + 1
--print('<font color="red">No motion has been detected for: ' ..no_motion_minutes.. ' minutes</font>')
else
no_motion_minutes = 0
end
commandArray['Variable:' .. nomotion_uservar] = tostring(no_motion_minutes)
if no_motion_minutes > 30 then --change the 30 to the amount of minutes you prefer
commandArray['Group:Woonkamer']='Off'
end
return commandArray
Code: Select all
-- gangb_motion_device.lua
local motion_switch = 'gangbPIR'
local status_switch = 'hue_gang_beneden'
local time_switch = 'schema1'
commandArray = {}
if devicechanged[motion_switch] then
if otherdevices[motion_switch] == 'On' and otherdevices[status_switch] == 'Off' and otherdevices[time_switch] == 'On' then
commandArray[status_switch]='Set Level 66'
end
end
return commandArray
Code: Select all
-- gangb_time_nomotion.lua
local motion_switch = 'gangbPIR'
local nomotion_uservar = 'gangbnomotion'
local status_switch = 'hue_gang_beneden'
commandArray = {}
no_motion_minutes = tonumber(uservariables[nomotion_uservar])
if (otherdevices[motion_switch] == 'Off') then
no_motion_minutes = no_motion_minutes + 1
--print('<font color="red">No motion has been detected for: ' ..no_motion_minutes.. ' minutes</font>')
else
no_motion_minutes = 0
end
commandArray['Variable:' .. nomotion_uservar] = tostring(no_motion_minutes)
if no_motion_minutes > 3 then --change the 30 to the amount of minutes you prefer
commandArray[status_switch]='Off'
end
return commandArray
Regards,
Jesse