25.08.2020, 09:07
(This post was last modified: 25.08.2020, 13:32 by davidchispas.)
(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 Smile](https://forum.logicmachine.net/images/smilies/smile.png)
In the end it has remained like that, I share it in case someone is of help.
Code:
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:
--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)