LogicMachine Forum
Resident script pump circulation - 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: Resident script pump circulation (/showthread.php?tid=1279)

Pages: 1 2 3 4


Resident script pump circulation - Domoticatorino - 07.03.2018

Hi,
I did a resident script that every minute checks the status of 2 valves and when one of them goes ON, a pump has to be start after 5 minutes. 

Instead if valves are both OFF pump has to be stop immediately.

Considering that I have to use a os.sleep() command, I would like to avoid to run many script in parallel.

What do you suggest?

Thanks.


RE: Resident script pump circulation - Erwin van der Zwart - 07.03.2018

yHi,

Resident scripts don’t run in parallel, only event based do that.

BR,

Erwin


RE: Resident script pump circulation - Domoticatorino - 08.03.2018

Do you mean that if script starts every minute and inside it there's a os.sleep() of 5 minutes, the second script doesn't start? Thanks


RE: Resident script pump circulation - admin - 08.03.2018

Scripts never block each other. You can safely use os.sleep in resident scripts. Though for larger delays I recommend using scheduled scripts.


RE: Resident script pump circulation - Domoticatorino - 08.03.2018

Hi Admin,
You're right but I cannot use a scheduled script. Otherwise I risk to want 10 minutes before starting the pump.
I need to don't run a script if the previous one is running. What do you suggest??
Thanks.


RE: Resident script pump circulation - admin - 08.03.2018

1. Add tag valve to your valve objects. Create an event script that is mapped to valve tag:
Code:
-- get OR'ed value of all tagged objects value = false objects = grp.tag('valve') for _, object in ipairs(objects) do   value = value or object.value end if value then   -- save pump timer if timer has not been started yet   time = storage.get('pump_on_time', 0)   if time == 0 then     storage.set('pump_on_time', os.time())   end else   -- turn pump off   storage.set('pump_on_time', 0)   grp.checkwrite('pump', false) end

2. Create either a resident script with large sleep time or a scheduled script that runs every minute:
Code:
-- turn pump on when time delta >= 5 minutes time = storage.get('pump_on_time', 0) if time > 0 then   delta = os.time() - time   if delta >= 5 * 60 then     grp.checkwrite('pump', true)   end else   grp.checkwrite('pump', false) end

In both scripts replace pump with pump object name or group address.


RE: Resident script pump circulation - Domoticatorino - 08.03.2018

Code:
-- check if previous script needs to be killed script_pompa_circolazione_notte = 'Pompa_circolazione_notte' pompa_notte_pid = storage.get(script_pompa_circolazione_notte)   if pompa_notte_pid == nil then    pompa_notte_pid_os = os.getpid()    storage.set(script_pompa_circolazione_notte, pompa_notte_pid_os) else    pompa_notte_pid_os = os.getpid()      storage.set(script_pompa_circolazione_notte, pompa_notte_pid_os)      os.kill(pompa_notte_pid, signal.SIGKILL) end -- put here your script with os.sleep Valvola_zona_notte = grp.getvalue('2/0/106') os.sleep(0.5) Valvola_bagno_zona_notte = grp.getvalue('2/0/105') if Valvola_zona_notte or Valvola_bagno_zona_notte == true then    os.sleep(360) -- attendi 360 secondi poi avvia la pompa di zona grp.write('2/0/3', true) else  grp.write('2/0/3', false) end -- end of your scrript -- clean up storage storage.delete(script_pompa_circolazione_notte)

Surfing on the forum I found an instruction to avoid to add running script. Here above what I did.

It seems working. What I would like to do is kill the os.sleep time (360 seconds) if in the meanwhile logic OR is false.

I hope I have been cleared.

Thanks.


RE: Resident script pump circulation - admin - 09.03.2018

You script is not fully correct. Each telegram sent to valve objects will reset wait timer. In some egde cases pump can never be turned on.


RE: Resident script pump circulation - Domoticatorino - 09.03.2018

Hi Admin, you,'re right. In fact this morning pump did not srart. Can you suggest me how to update the script?
Thanks.


RE: Resident script pump circulation - buuuudzik - 09.03.2018

You can do it also as resident and use tag 'circulation_pump' for valves:
Code:
valveStatesTag = 'circulation_pump' pumpGA = '1/1/10' opened, first_timestamp = false, 0 valveStates = grp.tag(valveStatesTag) for v = 1, #valveStates, 1 do  valveState = valveStates[v]  if valveState.value then     opened = true     if first_timestamp > 0 then         if first_timestamp > valveState.updatetime then first_timestamp = valveState.updatetime end     else         first_timestamp = valveState.updatetime     end  end end if opened then     opened_5_minutes = (os.microtime() - first_timestamp) >= 600     if opened_5_minutes then         grp.checkwrite(pumpGA, true)     else         grp.checkwrite(pumpGA, false)     end else     grp.checkwrite(pumpGA, false) end



RE: Resident script pump circulation - Domoticatorino - 09.03.2018

Thank you. Which resident time do you suggest?


RE: Resident script pump circulation - buuuudzik - 09.03.2018

For such think I like use 1 minute interval but if you want better reaction you can set less time like 30 or 15s oryou can adjust further this script e.g. you can choose Resident 0s and create auto adjusting the time for next calculation like below:

Code:
valveStatesTag = 'circulation_pump' pumpGA = '1/1/10' opened, first_timestamp = false, 0 valveStates = grp.tag(valveStatesTag) for v = 1, #valveStates, 1 do  valveState = valveStates[v]  if valveState.value then    opened = true    if first_timestamp > 0 then        if first_timestamp > valveState.updatetime then first_timestamp = valveState.updatetime end    else        first_timestamp = valveState.updatetime    end  end end if opened then    opened_5_minutes = (os.microtime() - first_timestamp) >= 300    if opened_5_minutes then        grp.checkwrite(pumpGA, true)         nextCalculationAfter = 30    else        grp.checkwrite(pumpGA, false)         nextCalculationAfter = 301 - (os.microtime() - first_timestamp) -- run a little after possible change    end else    grp.checkwrite(pumpGA, false)     nextCalculationAfter = 301 end log('Next calculation after: ' .. nextCalculationAfter .. 's.') os.sleep(nextCalculationAfter)


You can also disable this script if heating controller is off.


RE: Resident script pump circulation - Domoticatorino - 10.03.2018

Cool, in which way I can disable the script?

Thanks


RE: Resident script pump circulation - buuuudzik - 10.03.2018

(10.03.2018, 08:05)Domoticatorino Wrote: Cool, in which way I can disable the script?

Thanks

By use such command:
Code:
script.disable(script_name)



RE: Resident script pump circulation - Domoticatorino - 10.03.2018

Obviously in a different script?


RE: Resident script pump circulation - buuuudzik - 10.03.2018

(10.03.2018, 14:12)Domoticatorino Wrote: Obviously in a different script?

Yes, but you can also take all script in 1 if statement and check the status of controller. Enjoy?


RE: Resident script pump circulation - Domoticatorino - 10.03.2018

Code:
valveStatesTag = 'pompa_circolazione_giorno' pumpGA = '2/0/1' opened, first_timestamp = false, 0 valveStates = grp.tag(valveStatesTag) for v = 1, #valveStates, 1 do  valveState = valveStates[v]  if valveState.value then    opened = true    if first_timestamp > 0 then        if first_timestamp > valveState.updatetime then first_timestamp = valveState.updatetime end    else        first_timestamp = valveState.updatetime    end  end end if opened then    opened_5_minutes = (os.microtime() - first_timestamp) >= 120    if opened_5_minutes then        grp.checkwrite(pumpGA, true)    else        grp.checkwrite(pumpGA, false)    end else    grp.checkwrite(pumpGA, false) end

Hi, I use this script above and it seems does not work. I use 120 sec to check without loosing too time. Unfortunately Pump does not start.
What do you think?
Thanks.


RE: Resident script pump circulation - buuuudzik - 10.03.2018

Please check the updated version.


RE: Resident script pump circulation - Domoticatorino - 10.03.2018

It is a Schneider HL 2.0.1


RE: Resident script pump circulation - buuuudzik - 10.03.2018

(10.03.2018, 17:14)Domoticatorino Wrote: It is a Schneider HL 2.0.1

I mean updated version of above scriptWink I've adjusted it to be more universal, added new variables:
Code:
valveStatesTag = 'circulation_pump' pumpGA = '1/1/10' openingValveTime = 300 -- time for fully open the valve (maximum time for next calculation) minInterval = 30 -- minimum offset for next calculation opened, firstTimestamp = false, 0 valveStates = grp.tag(valveStatesTag) for v = 1, #valveStates, 1 do  valveState = valveStates[v]  if valveState.value then    opened = true    if firstTimestamp > 0 then        if firstTimestamp > valveState.updatetime then firstTimestamp = valveState.updatetime end    else        firstTimestamp = valveState.updatetime    end  end end if opened then    fullyOpened = (os.microtime() - firstTimestamp) >= openingValveTime    if fullyOpened then        grp.checkwrite(pumpGA, true)        nextCalculationAfter = minInterval    else        grp.checkwrite(pumpGA, false)        nextCalculationAfter = openingValveTime + 1 - (os.microtime() - firstTimestamp) -- run a little after possible change    end else    grp.checkwrite(pumpGA, false)    nextCalculationAfter = openingValveTime + 1 end log('Next calculation after: ' .. nextCalculationAfter .. 's.') os.sleep(nextCalculationAfter)