25.11.2018, 23:42
Hello, need a little help.
Task - storage room light control.
I have 19 storage boxes. (my script prepared for 3 boxes now for testing). Boxes with movement detector. When motion in storage is detected - group is true, if off - then false. For every box I need time light is ON (5-30 min) and light value (30-80%). Every storage box has 2 light group. I tried to use irrigation script found at forum, but something i doing not a right way. Need advice.
output 0/2/0 - Box1 group1 light value (in %, (object data type - 5 - 1 byte unsigned integer)
outputa 0/2/1 - Box1 group2 light value (settings) (in %, (object data type - 5 - 1 byte unsigned integer)
timer 1/2/1 - Box1 light is On time in minutes (5-30 min) (object data type - 5 - 1 byte unsigned integer)
enable 1/0/0 Box1 movement sensor status (object data type - 01.002 - Boolean)
level 1/1/1 Box1 lighting level in % for box1 lamp group1 and group2, (object data type - 05.001 - Scale)
Questions:
1. I think not correct data types for my groups.
2. Is possible to use such construction: grp.write(item.output, item.level) - in cycle ?? I think i need convert data formats before.
3. How log in one line time, and light level used (i mean 2 or more data in one log line?)
4. How at visu I can show time till light will be off (If I set timer as example for 5 minutes for box 1. Just put time to storage and compare it with system time and show difference at visu?)
Any advises will be super For correcting my errors. If i use grp.write(item.output, 80) At least light is on for 80% value for box1 1st group
Script:
mintimer = 1 -- minimum timer value in minutes
maxtimer = 30 -- maximum timer value in minutes
objects = {
{
output = '0/2/0',
outputa = '0/2/1',
timer = '1/2/1',
enable = '1/0/0',
level = '1/1/1',
},
{
output = '0/2/2',
outputa = '0/2/3',
timer = '1/2/2',
enable = '1/0/1',
level = '1/1/2',
},
{
output = '0/2/4',
outputa = '0/2/5',
timer = '1/2/3',
enable = '1/0/2',
level = '1/1/3',
}
}
log(level)
function dosleep(obj)
local timer = grp.getvalue(obj)
timer = tonumber(timer)
log(timer)
if timer then
if timer < mintimer then
timer = mintimer
elseif timer > maxtimer then
timer = maxtimer
end
log(timer)
sleep(timer * 60) -- minutes -> seconds
end
end
for _, item in ipairs(objects) do
if grp.getvalue(item.enable) then
grp.write(item.output, item.level)
grp.write(item.outputa, item.level)
dosleep(item.timer)
grp.write(item.output, 0)
grp.write(item.outputa, 0)
end
end
Task - storage room light control.
I have 19 storage boxes. (my script prepared for 3 boxes now for testing). Boxes with movement detector. When motion in storage is detected - group is true, if off - then false. For every box I need time light is ON (5-30 min) and light value (30-80%). Every storage box has 2 light group. I tried to use irrigation script found at forum, but something i doing not a right way. Need advice.
output 0/2/0 - Box1 group1 light value (in %, (object data type - 5 - 1 byte unsigned integer)
outputa 0/2/1 - Box1 group2 light value (settings) (in %, (object data type - 5 - 1 byte unsigned integer)
timer 1/2/1 - Box1 light is On time in minutes (5-30 min) (object data type - 5 - 1 byte unsigned integer)
enable 1/0/0 Box1 movement sensor status (object data type - 01.002 - Boolean)
level 1/1/1 Box1 lighting level in % for box1 lamp group1 and group2, (object data type - 05.001 - Scale)
Questions:
1. I think not correct data types for my groups.
2. Is possible to use such construction: grp.write(item.output, item.level) - in cycle ?? I think i need convert data formats before.
3. How log in one line time, and light level used (i mean 2 or more data in one log line?)
4. How at visu I can show time till light will be off (If I set timer as example for 5 minutes for box 1. Just put time to storage and compare it with system time and show difference at visu?)
Any advises will be super For correcting my errors. If i use grp.write(item.output, 80) At least light is on for 80% value for box1 1st group
Script:
mintimer = 1 -- minimum timer value in minutes
maxtimer = 30 -- maximum timer value in minutes
objects = {
{
output = '0/2/0',
outputa = '0/2/1',
timer = '1/2/1',
enable = '1/0/0',
level = '1/1/1',
},
{
output = '0/2/2',
outputa = '0/2/3',
timer = '1/2/2',
enable = '1/0/1',
level = '1/1/2',
},
{
output = '0/2/4',
outputa = '0/2/5',
timer = '1/2/3',
enable = '1/0/2',
level = '1/1/3',
}
}
log(level)
function dosleep(obj)
local timer = grp.getvalue(obj)
timer = tonumber(timer)
log(timer)
if timer then
if timer < mintimer then
timer = mintimer
elseif timer > maxtimer then
timer = maxtimer
end
log(timer)
sleep(timer * 60) -- minutes -> seconds
end
end
for _, item in ipairs(objects) do
if grp.getvalue(item.enable) then
grp.write(item.output, item.level)
grp.write(item.outputa, item.level)
dosleep(item.timer)
grp.write(item.output, 0)
grp.write(item.outputa, 0)
end
end