Logic Machine Forum
Swimming pool Scheduled script - Printable Version

+- Logic Machine 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: Swimming pool Scheduled script (/showthread.php?tid=4292)



Swimming pool Scheduled script - Shimaa - 11.10.2022

Hello everyone, 
hope you're doing well. 
If I have a swimming pool with 2 motors (M1, M2) and I need to make the following: 
-Weekly only 1 motor works. (ex: Week 1 --> M1, week 2 -->M2, etc)
-In Summer: ON for 1 hour,  off for 1 hour then repeat till the end of the day. 
-In winter: ON for 1 hour,  off for 2 hours then repeat till the end of the day. 

I already make it with the schedulers but I couldn't make it with scripting!
any ideas, please? 
Thanks for your time.


RE: Swimming pool Scheduled script - admin - 11.10.2022

How is winter/summer mode set? Via an object or calculated based on current date?


RE: Swimming pool Scheduled script - Shimaa - 11.10.2022

(11.10.2022, 13:01)admin Wrote: How is winter/summer mode set? Via an object or calculated based on current date?

Thanks for your reply,It will be based on the current date.


RE: Swimming pool Scheduled script - admin - 11.10.2022

So which months should be included in the summer mode? June-August or something else?


RE: Swimming pool Scheduled script - Shimaa - 11.10.2022

(11.10.2022, 13:19)admin Wrote: So which months should be included in the summer mode? June-August or something else?
yes from June to September.


RE: Swimming pool Scheduled script - admin - 13.10.2022

Create a scheduled script that runs once every hour:
Code:
addr1 = '1/1/1'
addr2 = '1/1/2'

week = tonumber(os.date('%W'))
hour = tonumber(os.date('%H'))
month = tonumber(os.date('%m'))

-- swap outputs on even weeks
if week % 2 == 0 then
  addr2, addr1 = addr1, addr2
end

-- summer mode (June 1st to August 31st)
if 6 <= month and month <= 8 then
  on = hour % 2 == 0
else
  on = hour % 3 == 0
end

grp.write(addr1, on)
grp.write(addr2, false)



RE: Swimming pool Scheduled script - Shimaa - 13.10.2022

(13.10.2022, 06:48)admin Wrote: Create a scheduled script that runs once every hour:
Code:
addr1 = '1/1/1'
addr2 = '1/1/2'

week = tonumber(os.date('%W'))
hour = tonumber(os.date('%H'))
month = tonumber(os.date('%m'))

-- swap outputs on even weeks
if week % 2 == 0 then
  addr2, addr1 = addr1, addr2
end

-- summer mode (June 1st to August 31st)
if 6 <= month and month <= 8 then
  on = hour % 2 == 0
else
  on = hour % 3 == 0
end

grp.write(addr1, on)
grp.write(addr2, false)
Thanks for your reply, It's working well, but I need to study it!
Thanks again for your support.