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.

cyclic time generator
#1
Hello,

I need to create a script that when '1/1/1' is "on" it starts a cyclic generator of time of 'on' and 'off' parameterizable.
When '1/1/1' is Off, the cyclic generator is reset and the output is Off.
Reply
#2
Hi
Use event script on 1/1/1 to enable/disable a resident script which will send what you need.
BR
------------------------------
Ctrl+F5
Reply
#3
(24.08.2020, 07:10)Daniel. Wrote: Hi
Use event script on 1/1/1 to enable/disable a resident script which will send what you need.
BR
Thanks Daniel, you can provide me with an example that I did not find in the search engine, or help me with the script.
1/1/1 - Activate sequence
1/1/2 - Time value activated
1/1/3 - Time value disabled
1/1/4 - Output object
Reply
#4
What does the tow objects:
1/1/2 - Time value activated
1/1/3 - Time value disabled
Supposed to be doing?
------------------------------
Ctrl+F5
Reply
#5
(24.08.2020, 10:50)Daniel. Wrote: What does the tow objects:
1/1/2 - Time value activated
1/1/3 - Time value disabled
Supposed to be doing?
In these integer value objects, I enter a time in minutes.

I need to create a cyclic send of different on / off values. For example, 10 minutes on / 30 minutes off. This sequence is continuous while 1/1/1 is enabled, when changing everything is off.
Reply
#6
Event script attached to 1/1/1

Code:
1234567
value = event.getvalue() if value then   script.enable('cycle_scriptname') else   script.disable('cycle_scriptname') end
cycle_scriptname replace with a name of resident script.

Resident script of interval 60s
Code:
123456789101112131415161718192021222324252627
timerOn = grp.getvalue('1/1/2') timerOff = grp.getvalue('1/1/3') onCounter = storage.get('onCounter', 0) offCounter = storage.get('offCounter', 0) onCounter = onCounter +1 offCounter = offCounter +1 log(onCounter,offCounter) if onCounter >= timerOn then   grp.write('1/1/4', true)   storage.set('onCounter', 0) else storage.set('onCounter', onCounter) end if offCounter >= timerOff then   grp.write('1/1/4', false)   storage.set('offCounter', 0) else   storage.set('offCounter', offCounter) end

BR
------------------------------
Ctrl+F5
Reply
#7
Code:
1234567
value = event.getvalue() if value then   script.enable('cycle_scriptname') else   script.disable('cycle_scriptname') end



Code:
123456789101112131415161718192021222324252627
timerOn = grp.getvalue('1/1/2') timerOff = grp.getvalue('1/1/3') onCounter = storage.get('onCounter', 0) offCounter = storage.get('offCounter', 0) onCounter = onCounter +1 offCounter = offCounter +1 log(onCounter,offCounter) if onCounter >= timerOn then   grp.write('1/1/4', true)   storage.set('onCounter', 0) else storage.set('onCounter', onCounter) end if offCounter >= timerOff then   grp.write('1/1/4', false)   storage.set('offCounter', 0) else   storage.set('offCounter', offCounter) end

Thanks Daniel, I'm testing it but I can't get it to work properly. I have set 1 minute on and 2 minute off.

I have temporarily changed 1/1/4 to 0/5/3.

   
Reply
#8
I left you the log which shows the counting for on and off. For testing change the script interval to 10. It will then run tomerOn x 10s instead of 60s. Make sure you change 1/1/4 in both places.

Add to event script under else condition
storage.set('offCounter', 0)
storage.set('onCounter', 0)

so the counter is rested after disabling it.
------------------------------
Ctrl+F5
Reply
#9
(24.08.2020, 16:40)Daniel. Wrote: I left you the log which shows the counting for on and off.  For testing change the script interval to 10.  It will then run tomerOn x 10s instead of 60s. Make sure you change 1/1/4 in both places.

Add to event script under else condition
storage.set('offCounter', 0)
storage.set('onCounter', 0)

so the counter is rested after disabling it.

Hi Daniel, I had to modify in the resident script to send the opposite value for it to work correctly.
if onCounter> = timerOn then
  grp.write ('1/1/4', false)
  storage.set ('onCounter', 0)

Anyway, I would like to thank you for your indications that have been of great help to me!  Smile

In the end it has remained like that, I share it in case someone is of help.

Code:
1234567891011121314151617181920212223242526272829303132
AddressOutput = '1/1/4'  -- 01. 1 bit (boolean) StatusCounterOn = '1/1/5' --05. 1 byte unsigned integer StatusCounterOff = '1/1/6' --05. 1 byte unsigned integer CounterOn = 'onCounter_Test' CounterOff = 'offCounter_Test' Script = 'Test' ---------------------------------------------------------------------------------- value = event.getvalue() if value then   script.enable(Script) else   script.disable(Script)   sleep(2)   grp.checkwrite(AddressOutput, false)   storage.set(CounterOn, 0)   storage.set(CounterOff, 0)   grp.checkwrite(StatusCounterOn, 0)   grp.checkwrite(StatusCounterOff, 0) --Opcional   sleep(2)   storage.delete(CounterOn)   storage.delete(CounterOff) end



Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445
--Script resident (60s) AddressInput= '1/1/1' -- 01. 1 bit (boolean) timerOn = '1/1/2' --05. 1 byte unsigned integer timerOff = '1/1/3' --05. 1 byte unsigned integer AddressOutput= '1/1/4' -- 01. 1 bit (boolean) StatusCounterOn = '1/1/5' --05. 1 byte unsigned integer StatusCounterOff = '1/1/6' --05. 1 byte unsigned integer ---------------------------------------------------------------------------- onCounter = storage.get('onCounter_' .. _SCRIPTNAME, 0) offCounter = storage.get('offCounter_' .. _SCRIPTNAME, 0) if grp.getvalue(AddressInput) and grp.getvalue(AddressOutput) then onCounter = onCounter +1 end if grp.getvalue(AddressInput) and not grp.getvalue(AddressOutput) then offCounter = offCounter +1 end log(onCounter,offCounter) if onCounter >= grp.getvalue(timerOn) then   grp.write(AddressOutput, false)   storage.set('onCounter_' .. _SCRIPTNAME, 0) else   storage.set('onCounter_' .. _SCRIPTNAME, onCounter) end if offCounter >= grp.getvalue(timerOff) then   grp.write(AddressOutput, true)   storage.set('offCounter_' .. _SCRIPTNAME, 0) else   storage.set('offCounter_' .. _SCRIPTNAME, offCounter) end   grp.checkwrite(StatusCounterOn, onCounter) grp.checkwrite(StatusCounterOff, offCounter)
Reply


Forum Jump: