LogicMachine Forum
event script e os.sleep - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: event script e os.sleep (/showthread.php?tid=2991)



event script e os.sleep - Frank68 - 18.11.2020

Hello
I am trying with an event-based script when the value of a byte changes, to send mail, the byte can have value 0,1,2 my problem ache inside the script I should delay sending the mail for a time and re-read the value, as it takes time to pass between the various values, I tried with os.sleep () and to read the value after the time but it doesn't work, is there another way to do this function?

thanks a lot


RE: event script e os.sleep - admin - 18.11.2020

Are you using event.getvalue()? You should use grp.getvalue(event.dst) after sleep.


RE: event script e os.sleep - Frank68 - 18.11.2020

(18.11.2020, 10:20)admin Wrote: Are you using event.getvalue()? You should use grp.getvalue(event.dst) after sleep.
Hi

I use grp.getvalue(event.dst) this is my code
Code:
-- INDICAZIONI COMUNI -- get current data as table now = os.date('*t') TS=' del '..now.day..'/'..now.month..'/'..now.year..' alle '..now.hour..':'..now.min..':'..now.sec..'.' -- recupero indirizzo mail e telefono principali DestGen  = grp.getvalue('32/1/1') NumTel  = grp.getvalue('32/1/2') -- INDIRIZZI MAIL SECONDARI DestMail1  = grp.getvalue('32/1/10') DestMail2  = grp.getvalue('32/1/11') DestMail3  = grp.getvalue('32/1/12') DestMail4  = grp.getvalue('32/1/13') DestMail5  = grp.getvalue('32/1/14') DestMail6  = grp.getvalue('32/1/15') -- NUMERI TELEFONO SECONDARI NumTel1  = grp.getvalue('32/1/20') NumTel2  = grp.getvalue('32/1/21') NumTel3  = grp.getvalue('32/1/22') NumTel4  = grp.getvalue('32/1/23') NumTel5  = grp.getvalue('32/1/24') NumTel6  = grp.getvalue('32/1/25') -- recupero tag per destinazione FLT_TAG1 = grp.getvalue('32/1/30') FLT_TAG2 = grp.getvalue('32/1/31') FLT_TAG3 = grp.getvalue('32/1/32') FLT_TAG4 = grp.getvalue('32/1/33') FLT_TAG5 = grp.getvalue('32/1/34') FLT_TAG6 = grp.getvalue('32/1/35') id=event.dst -- wait forseconds os.sleep(15) --recupero  STATO INTERUTTORE value = grp.getvalue(id) -- recupero descrizione name = grp.alias(id) ------- retry TAGS for mailing dest tbl = grp.gettags(name) strTAGS = table.concat(tbl, ', ') -- last val memory OldVal=grp.getvalue('32/1/55') -- setc current val to OldVal object grp.write('32/1/55', value) -- cambio del valore rispetto giro precedente if(value~=OldVal) then --casistica valori   if (value==1) then     log('valore 1')     subject = 'Commutazione selettore UTI'     message = 'Stato  ID  - '.. id .. ' - ' .. name  ..'  Posizione 1  ' .. TS     mail(DestGen, subject, message)     alert(message)     ALM = false   end        if (value ==2) then     log('valore 2')     subject = 'Commutazione selettore UTI'     message = 'Stato  ID  - '.. id .. ' - ' .. name  ..'  Posizione 2  ' .. TS     mail(Dest1, subject, message)     alert(message)     ALM = false     end        if (value ==0) then     subject = 'Commutazione selettore UTI'     message = 'Stato  ID  - '.. id .. ' - ' .. name  ..'  Posizione Sconosiuta  ' .. TS     mail(Dest1, subject, message)     log( 'valoer 0')     alert(message)     ALM = true     end end ------------------------------------------------------------------------------------

in my code I would like, if possible, that only after a certain period, depending on the value 0,1,2, delel actions were performed, but unfortunately seeing from the log ('value n'), 0 is always also executed without taking into account the time 15 cesondi, in this period the value has changed state and is no longer 0, in practice only if I have 0 after a certain period I have to perform an action.

available for clarification

thanks


RE: event script e os.sleep - admin - 18.11.2020

You have this check: if(value~=OldVal) then but you say you want to execute a certain action only when a value has not changed in the past 15 seconds.
I think an event script is not a ideal solution here because each value change will trigger another script. How often does this value change? You can try a resident script that checks the object value every second and resets/increases a timer variable depending whether the value has changed or not.