This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Staircase script with dimming option
#4
This is easier to do via a resident script (0 sleep time).

Single script can be used for multiple timers by adding more entries to the timers table. The script uses current dimmer control value to determine what level to set, only values set by other sources (not the script itself) are used. There are two points - high and low, if the current value is less than low then low value is used, otherwise high value is used. The status value cannot be used here because it's impossible to tell who change the value that caused the status update.

An alternative solution is to create a day/night object to have two different sets of values for movement/no movement.
Code:
if not client then   timers = {     {       input = '1/1/1', -- binary PIR status       output = '1/1/3', -- dimmer control (0..100%)       onvaluehigh = 90, -- high output value in %       onvaluelow = 30, -- low output value in %       timeout = 60, -- in seconds     }   }   function setinputvalue(timer, event)     local value = busdatatype.decode(event.datahex, dt.bool)     if not value then       return     end     if timer.outvalue < timer.onvaluelow then       value = timer.onvaluelow     elseif timer.outvalue < timer.onvaluehigh then       value = timer.onvaluehigh     else       value = nil     end     if not timer.ticks and value then       grp.write(timer.output, value, dt.scale)     end     timer.ticks = timer.timeout   end   function setoutputvalue(timer, event)     timer.outvalue = busdatatype.decode(event.datahex, dt.scale)     timer.ticks = nil -- stop timer   end   for _, timer in ipairs(timers) do     timer.outvalue = grp.getvalue(timer.output)   end   sender = 'tm'   grp.sender = sender   client = require('localbus').new(0.1)   client:sethandler('groupwrite', function(event)     if event.sender == sender then       return     end     for _, timer in ipairs(timers) do       if timer.input == event.dst then         setinputvalue(timer, event)       elseif timer.output == event.dst then         setoutputvalue(timer, event)       end     end   end) end client:loop(1) for _, timer in ipairs(timers) do   if timer.ticks then     timer.ticks = timer.ticks - 1     if timer.ticks == 0 then       grp.write(timer.output, timer.outvalue, dt.scale)       timer.ticks = nil     end   end end
Reply


Messages In This Thread
RE: Staircase script with dimming option - by admin - 20.05.2022, 12:40

Forum Jump: