Code: Select all
commandArray = {}
if (devicechanged['Badrum-Motion'] == 'Motion' and otherdevices['Badrum-Belysning'] == 'Off') then
commandArray['Badrum-Belysning']='On'
end
print('Badrum-Belysning on!')
return commandArray
Moderator: leecollings
Code: Select all
commandArray = {}
if (devicechanged['Badrum-Motion'] == 'Motion' and otherdevices['Badrum-Belysning'] == 'Off') then
commandArray['Badrum-Belysning']='On'
end
print('Badrum-Belysning on!')
return commandArray
Code: Select all
commandArray = {}
if (devicechanged['Badrum-Motion'] == 'On' and otherdevices['Badrum-Belysning'] == 'Off') then
commandArray['Badrum-Belysning']='On'
print('Badrum-Belysning on!')
End
return commandArray
Code: Select all
commandArray = {}
if (devicechanged['Badrum-Motion'] and otherdevices['Badrum-Belysning'] == 'Off') then
commandArray['Badrum-Belysning']='On'
print('Badrum-Belysning on!')
End
return commandArray
Code: Select all
commandArray = {}
hour = (os.date('%H'))
if (devicechanged['Badrum-Motion'] == 'On' and (hour >= 23 or hour < 8) and otherdevices['Badrum-Belysning'] == 'Off') then
commandArray['Badrum-Belysning']='Set Level 50'
print("Badrum Belysning on 50%")
else
commandArray['Badrum-Belysning']='Set Level 100'
print('Badrum Belysning on 100%')
end
return commandArray
Code: Select all
-- the script turns on the dimmer for 5 minutes, the level during daytime is 100 and night 50
commandArray = {}
h = tonumber((os.date('%H')))
if (h >= 8 and h < 23) then
x = 'Set Level 100 FOR 5'
else
x = 'Set Level 50 FOR 5'
end
if (devicechanged['Badrum-Motion'] == 'On' and otherdevices['Badrum-Belysning'] == 'Off') then
commandArray['Badrum-Belysning']= x
print(x)
end
Code: Select all
print('this will end up in the domoticz log')
commandArray = {}
if (devicechanged['OcchioMagicoFibaro-PIR'] == 'On' then
commandArray['Switch1']='On'
end
return commandArray
You are missing a closing bracket on your if line:cpighin wrote: I'm going to insert my issue into this topic instead of creating a new one
As a first step for learing LUA funcionality I would light a lamp connected to a FibaroSwitch (Switch1) when my Fibaro Motion Sensor (OcchioMagicoFibaro-PIR) detects a movement.
I have created a simple lua file script_device_LightOnAfterMovement.luaand the lamp does not light when moving in front of the MotionSensor.Code: Select all
print('this will end up in the domoticz log') commandArray = {} if (devicechanged['OcchioMagicoFibaro-PIR'] == 'On' then commandArray['Switch1']='On' end return commandArray
Where am I wrong?
Claudio
Code: Select all
commandArray = {}
if (devicechanged['OcchioMagicoFibaro-PIR'] == 'On') then
print('Motion detected')
commandArray['Switch1']='On'
end
return commandArray
I corrected my error and tested the file which now works quite fine lighting the lamp.simonrg wrote:You are missing a closing bracket on your if line:cpighin wrote: I'm going to insert my issue into this topic instead of creating a new one
As a first step for learing LUA funcionality I would light a lamp connected to a FibaroSwitch (Switch1) when my Fibaro Motion Sensor (OcchioMagicoFibaro-PIR) detects a movement.
I have created a simple lua file script_device_LightOnAfterMovement.luaand the lamp does not light when moving in front of the MotionSensor.Code: Select all
print('this will end up in the domoticz log') commandArray = {} if (devicechanged['OcchioMagicoFibaro-PIR'] == 'On' then commandArray['Switch1']='On' end return commandArray
Where am I wrong?
ClaudioCode: Select all
commandArray = {} if (devicechanged['OcchioMagicoFibaro-PIR'] == 'On') then print('Motion detected') commandArray['Switch1']='On' end return commandArray
Not wishing to repeat myself, but you now seem to be trying to do exactly what the Smart Lua Scripts were designed for so have a look at http://www.domoticz.com/wiki/Smart_Lua_ ... _Smart_PIR, basically will keep a light on for a defined length of time after last motion detection and can be configured by the way you name the PIR in Domoticz.cpighin wrote:After learning how to use a LUA script , I would like to improve it to ensure that the lamp comes on when the sensor detects motion and stays on unless no movements are detected for 2 minutes.
Tanks simongsimonrg wrote:Not wishing to repeat myself, but you now seem to be trying to do exactly what the Smart Lua Scripts were designed for so have a look at http://www.domoticz.com/wiki/Smart_Lua_ ... _Smart_PIR, basically will keep a light on for a defined length of time after last motion detection and can be configured by the way you name the PIR in Domoticz.
Should I understand to create a new "virtual" device (if so please instruct me on haw to) or Should I rename my actual device "OcchioMagicoFibaro-PIR" in "PIR-OcchioMagicoFibaro" (or something else)?Adding Turning Off Functionality[edit]
First in Domoticz add a new Siemens PIR and call it after a light in your house, say the "Study" light, so the PIR is named "PIRStudy", make its device type "Motion Sensor". Then add the scripts described below.
You are going to rename your actual device, the idea is that then the script will know that this is a PIR just from its name and so will pick up any PIRs not just a single 1.cpighin wrote:Should I understand to create a new "virtual" device (if so please instruct me on haw to) or Should I rename my actual device "OcchioMagicoFibaro-PIR" in "PIR-OcchioMagicoFibaro" (or something else)?Adding Turning Off Functionality[edit]
First in Domoticz add a new Siemens PIR and call it after a light in your house, say the "Study" light, so the PIR is named "PIRStudy", make its device type "Motion Sensor". Then add the scripts described below.
Thanks simonrg Since i would prefer to avoid the renaming of devices, is it possible to modify your scriptsimonrg wrote: You are going to rename your actual device, the idea is that then the script will know that this is a PIR just from its name and so will pick up any PIRs not just a single 1.
Code: Select all
-- ~/domoticz/scripts/lua/script_device_PIRs.lua
commandArray = {}
tc=next(devicechanged)
v=tostring(tc)
if (v:sub(1,3) == 'PIR') then
c=v:sub(4)
commandArray[c] = 'On'
tmess = c..' On - time 0'
print(tmess)
end
return commandArray
You can modify it however you like - .cpighin wrote:Thanks simonrg Since i would prefer to avoid the renaming of devices, is it possible to modify your script in order to consider only a device with a specific name (for example OcchioMagicoFibaro-PIR)?
Code: Select all
-- ~/domoticz/scripts/lua/script_device_PIRs.lua
commandArray = {}
tc=next(devicechanged)
v=tostring(tc)
-- Look for a device name which ends in PIR
if (v:sub(-3,-1) == 'PIR') then
-- Remove -PIR from the device name and then turn that device on
c=v:sub(1, -5)
commandArray[c] = 'On'
tmess = c..' On - time 0'
print(tmess)
end
return commandArray
Simonrg, few days ago you corrected my LUA file that now works fine lighting On my lamp after a motion detection.simonrg wrote:cpighin wrote: You are missing a closing bracket on your if line:Code: Select all
commandArray = {} if (devicechanged['OcchioMagicoFibaro-PIR'] == 'On') then print('Motion detected') commandArray['Switch1']='On' end return commandArray
and I understand that I can use the LUA file you corrected as the one that turns On the light and a new script_time_name.lua which turns the light Off when the last update was 120 minutes ago, eventually using parts of your article mentioned above.simonrg wrote:Alternatively just write yourself from scripts from scratch, a script_device_name.lua which turns on the light whenever the PIR is detected, then a script_time_name.lua which turns the light off when the last update was x minutes ago. How to do this is in the more flexible scripts.
Claudio, yes you can use your original script to turn the light on:cpighin wrote:You corrected my LUA file that now works fine lighting On my lamp after a motion detection.
Now I would like to improve the system to ensure that the lamp comes On when the sensor detects motion and stays On unless no movements are detected for x time (120 sec. as an example).
You have just wroteand I understand that I can use the LUA file you corrected as the one that turns On the light and a new script_time_name.lua which turns the light Off when the last update was 120 minutes ago, eventually using parts of your article mentioned above.simonrg wrote:Alternatively just write yourself from scripts from scratch, a script_device_name.lua which turns on the light whenever the PIR is detected, then a script_time_name.lua which turns the light off when the last update was x minutes ago. How to do this is in the more flexible scripts.
Am I right?
Claudio
Code: Select all
-- ~/domoticz/scripts/lua/script_device_occhio.lua
commandArray = {}
if (devicechanged['OcchioMagicoFibaro-PIR'] == 'On') then
print('Motion detected')
commandArray['Switch1']='On'
end
return commandArray
Users browsing this forum: Bing [Bot] and 1 guest