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
#3
(16.03.2022, 09:25)admin Wrote: Can you post the scripts that you are using now?

Thanks for the question and apologies for not responding sooner. I did not notice your response.

I created two different scripts. The first one responds to the PIR. For that, I modified the beautiful Staircase logic. See my explanation in the script. I added a lot of logs to find for myself why it doesn't work properly.

With the second script I want to achieve that if the lamp is turned off (manually or by a program or by another script), that the running first script then stops, that the lamp goes off, and the next time it comes on again dimmed.

In practice, it works well, until we go to bed. Usually the lamp goes off first and then on again. Also, regularly the lamp goes directly on at the brighter setting. So then the brighter setting is the same as the standard setting.

It would be best if this could work with just 1 script. I would like to use this script in more places in the house (and especially outside).

Here are the scripts:

SCRIPT 1:
Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
-- Note that at 3/0/7 there is also a script, which should stop this staircase if the lamp is turned on/off. -- Only react to PIR going on, not going off: inputvalue = event.getvalue if (event.getvalue() == false or event.getvalue() == 0) then   return end -- ** Staircase logic with external time object and retriggering on input object Version 3.1 ** -- -- ****************************** Created by Erwin van der Zwart **************************** -- -- ************************************** SET PARAMETERS ************************************ -- -- Set input address AddressInput = '9/0/1' -- Set output address AddressOutput = '1/1/7' -- Set unique name for staircase timer (to avoid same storage name usage) StaircaseName = 'PIR_LAMP_HAL' -- Set external time address (optional) AddressExternalTime = '' -- Use time left indication UseTimeLeft = false -- Set to true if time left indication will be used -- Set feedback adress of time left indication (optional) AddressTimeLeft = '' -- Set time delay (Used when external time is not available) SetDelay = 15 -- Seconds or Minutes SetSec = true-- Set to false for Minutes -- Set factor delay (Multiplies Delay) SetFac = 1 -- Logic can be turned of by value 0 Off_by_Value_Zero = false -- Additions for brightening the lamp on motion dd 14-01-2022: Schemer = grp.getvalue('6/0/6') -- If it is dusk, this is set to 1. AanStandHal = grp.getvalue('3/0/7') -- This indicates whether lamp is on when the script starts. DimStandHal = grp.getvalue('3/2/7') -- This is the dimming value at the start of the script. AdressOpgeslagenBeginStandHal = '1/2/7'-- Dim value field especially for this script to save initial state (I don't manage to keep this in memory) OpgeslagenBeginStandHal = grp.getvalue(AdressOpgeslagenBeginStandHal) TijdelijkHarderHal = grp.getvalue('39/1/1') -- This contains the (brighter) dimming value that the lamp should temporarily be at (e.g. 90%) -- If DimStandHal is set to 0, the lamp is off, and nothing needs to happen. Nothing needs to happen when there is no twilight either. if (DimStandHal) == 0 or (Schemer) == false then   --log('return because hall lamp not on or no dusk')   return end -- If DimStandHal == TemporaryHarderHal, then the script has run before. Then nothing should happen. Otherwise save current value. if DimStandHal == TijdelijkHarderHal then   --log ('DimStandHal gelijk aan TijdelijkeHarderHal')   --log ('OpgeslagenBeginStandHal is'..OpgeslagenBeginStandHal)   --log ('TijdelijkHarderHal is'..TijdelijkHarderHal)   -- do nothing   else   grp.write(AdressOpgeslagenBeginStandHal, DimStandHal)   OpgeslagenBeginStandHal = grp.getvalue(AdressOpgeslagenBeginStandHal)   --log ('Nieuwe start script (Else)')   --log ('OpgeslagenBeginStandHal is'..OpgeslagenBeginStandHal)   --log ('DimStandHal is'..DimStandHal)   --log ('TijdelijkHarderHal is'..TijdelijkHarderHal) end -- ************************************** END PARAMETERS ************************************ -- -- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ -- inputvalue = event.getvalue if Off_by_Value_Zero == false and (event.getvalue() == false or event.getvalue() == 0) then   -- Exit script   return end ValueInput = grp.getvalue(AddressInput) ValueOutput = grp.getvalue(AddressOutput) ValueExternalTime = grp.getvalue(AddressExternalTime) if SetSec == true then   SetSeconds = 1 else   SetSeconds = 60 end if ValueExternalTime == nil then ValueExternalTime = 0 end if ValueExternalTime > 0 then   StairCaseTime = ValueExternalTime * SetSeconds * SetFac else   StairCaseTime = SetDelay * SetSeconds * SetFac end if ValueInput == true then   --check for earlier started scrips   --check storage for stpid value   stpid = storage.get(StaircaseName)    --check if stpid has a value   if stpid == nil then      pid = os.getpid()      storage.set(StaircaseName, pid)   else      -- kill earlier running script         os.kill(stpid, signal.SIGKILL)      -- create new pid for next time to kill      pid = os.getpid()         storage.set(StaircaseName, pid)   end   if ValueOutput < TijdelijkHarderHal then     grp.write(AddressOutput, TijdelijkHarderHal)     ValueOutput = true   end   -- Check time left indication is used   if UseTimeLeft == true then     if StairCaseTime > 0 then         grp.update(AddressTimeLeft, StairCaseTime)         repeat           StairCaseTime = StairCaseTime - 1           grp.update(AddressTimeLeft, StairCaseTime)           os.sleep(1)         until StairCaseTime == 0     end      else     os.sleep(StairCaseTime)   end   ValueOutput = grp.getvalue(AddressOutput)   if ValueOutput == TijdelijkHarderHal then     ValueInput = grp.getvalue(AddressInput)     if ValueInput == true then         grp.write(AddressInput, false)       ValueInput = false     end     if Off_by_Value_Zero == false then       if ValueOutput == TijdelijkHarderHal then             grp.write(AddressOutput, OpgeslagenBeginStandHal) -- value here was 0, but to OpgeslagenBeginStandHal to set it back to this position.         ValueOutput = 0           end     else       -- Do nothing, this will trigger else condition below on next run       end   end else   --check for earlier started scrips   --check storage for stpid value   stpid = storage.get(StaircaseName)    --check if stpid has a value   if stpid == nil then   else     -- kill earlier running script        os.kill(stpid, signal.SIGKILL)     grp.update(AddressTimeLeft, 0)     pid = nil     storage.set(StaircaseName, pid)   end     -- Terugschrijven naar beginstand   if ValueOutput == TijdelijkHarderHal then     --log ('ValueOutput == TijdelijkHarderHal')     grp.write(AddressOutput, OpgeslagenBeginStandHal)   end end


SCRIPT 2:

Code:
123456789101112131415
--When switching this lamp, any running script on the hall PIR (9/0/1) is stopped. --This script is activacted at 3/0/7 and 0/1/1 (group lighting downstairs) StaircaseName = 'PIR_LAMP_HAL' stpid = storage.get(StaircaseName) os.kill(stpid, signal.SIGKILL) grp.update(AddressTimeLeft, 0) pid = nil storage.set(StaircaseName, pid) -- If script is turned off, while the lamp is louder during the PIR script, then the "old" DimValue must be written over the feedback. -- The idea is that the lamp then starts up the next time with the harder setting (on which it went out) and then automatically dims back to the old dimming value. OpgeslagenDimWaarde = grp.getvalue('1/2/7') grp.write('3/2/7', OpgeslagenDimWaarde)
Reply


Messages In This Thread
RE: Staircase script with dimming option - by Dirk79 - 19.05.2022, 18:52

Forum Jump: