Hi,
on Friday I installed my air purifier and was surprised how loud (and strong) it is.
Because I’m afraid it would be too loud, I try to search how to switch it on only, when needed. And I don’t want to tinker every time with the g-code. Therefore I try to find a smart solution.
And in best case it is only switched on at a suitable daytime.
My solution is based on placeholders in the gcodes defined within PrusaSlicer and the function “physical printer” in PrusaSlicer. In the “End G-code” I added the following lines:
;{if physical_printer_preset=~/.*LIGHTS-OFF.*/}
;M1010 S3 P0 ;shut down lights (not used right now)
;{endif}
{if physical_printer_preset=~/.*FILTER-ON-PLANNED.*/}
;
;REPLACEDHEREFILTER
;
{endif}
{if physical_printer_preset=~/.*FILTER-ON.*/}
M1011 F1 S1 ;Purifier 1 gear working. Use S1 to force power up and run in this gear.
M1010 S4 P100 ;set exhaust fan to 100%
G4 S180 ;180sec filtering
M1010 S4 P0 ;set exhaust fan to 0%
M1011 F0 ;Purifier 1 gear working. Use S1 to force power up and run in this gear.
{endif}
{if physical_printer_preset=~/.*SHUTDOWN-ON.*/}
M107 ; turn off the fan
M1010 S3 P0 ;shut down lights
M1010 S4 P0 ;shut down exhaust fan
M1011 ; turn off air purifier
M81 ;power off printer after print (not working with SM2)
M112 ;emergency shutdown
{endif}
;End of Gcode
PrusaSlicer checks now for the name of the chosen physical printer and modifies the g-code. E.g. if the Name of the physical printer includes “FILTER-ON” the gcode snippet is added that turns on the Air purifier for 90 seconds. I hope you got the idea.
Afterwards you just have to add physical printers (Hint: Don’t use “:” in the Name!). My physical printers look now (Oh, I see there are still some errors )
The blue arrow marks the button to add physicals printer. You see also I have combined versions with filter and shutdown.
The last (and biggest) challenge was to start it only at certain time.
My solution is partly already shown above. If there is “FILTER-ON-PLANNED” in the name an additional placeholder (“;REPLACEDHEREFILTER”) is added. This placeholder is modified via a external python script to add several G04 (dwell) commands before the air purifier is switched on.
The python script has to be added here and is used automatically:
You have to link to python and tell python where the script is:
C:\Users\Sightz\AppData\Local\Programs\Python\Python310\python.exe D:\stefan\1030_Bastelprojekte\Snapmaker\sleep_filter_until_defined_clocktime.py;
And of course you need to have the script there
#!/usr/bin/env python3
import re, sys
import datetime as dt
script_filename = sys.argv[0]
gcode_filename = sys.argv[1]
#Nur zum Debuggen
#script_filename = "script"
#gcode_filename = "X:\\test.gcode"
print("Script:")
print(script_filename)
print("GCode:")
print(gcode_filename)
print("\n")
waitintervall = 3600;
totaltime_regex = r'estimated printing time \(normal mode\) = (\d+)h (\d+)m (\d+)s'
replacer_regex = ';REPLACEDHEREFILTER'
notreplacer_regex = '(end_gcode = .*)(;REPLACEDHEREFILTER)(.*)'
gcode_file = open(gcode_filename, 'r')
gcode = gcode_file.read()
gcode_file.close()
group = re.findall(totaltime_regex, gcode)
stunden = int(group[0][0])
minuten = int(group[0][1])
sekunden = int(group[0][2])
print("Stunden:")
print(stunden)
print("Minuten:")
print(minuten)
print("Sekunden:")
print(sekunden)
print("\n")
startdatum = dt.datetime.now()
dauer = dt.timedelta(days=0, seconds=sekunden, microseconds=0, milliseconds=0, minutes=minuten, hours=stunden, weeks=0)
enddatum = startdatum + dauer
earliestfilter = dt.datetime.combine(dt.date.today(), dt.time(9, 00, 0))
sleeptime = earliestfilter - enddatum
if sleeptime <= dt.timedelta(0,0,0,0,0,0,0):
sleeptime = earliestfilter + dt.timedelta(days=1, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) - enddatum
waitseconds = int(sleeptime.total_seconds())
waitintervalls_num = int(round(waitseconds / waitintervall, 0))
waitintervallrest = int(waitseconds % waitintervall)
print("Startdatum:")
print(startdatum)
print("Enddatum:")
print(enddatum)
print("Filter startet um:")
print(earliestfilter)
print("Sleeptime:")
print(sleeptime)
print("\n")
print("Sleeptime:")
print(sleeptime)
print("\n")
print("Neues Startdatum:")
print(enddatum + sleeptime)
print("Wartesekunden:")
print(waitseconds)
print("In " + str(waitintervalls_num) + " Intervallen a " + str(waitintervall) + " Sekunden und einer Restzeit von " + str(waitintervallrest) + " Sekunden.")
print("\n")
addgcode = ""
for x in range(waitintervalls_num):
addgcode = addgcode + 'G4 S' + str(waitintervall) + " ; " + str(x+1) + ". Stunde gewartet" + '\n'
addgcode = addgcode + 'G4 S' + str(waitintervallrest) + '\n'
#notreplacer_regex
with open(gcode_filename, 'w') as gcode_file:
gcode_file.write('; post-processed by ' + script_filename + ' to append wait time for filter (start not at night)\n')
new_gcode = re.sub(notreplacer_regex, '\\1\\3', gcode, 1)
gcode = new_gcode
new_gcode = re.sub(replacer_regex, addgcode, new_gcode, 1)
gcode_file.write(new_gcode)
gcode_file.close()
print("GCode added:")
print(addgcode)
print("\n")
I have to admit this is still work in progress. But it should work so far. No warranty!
A solution to switch off the printer completely would be welcome(?)
Greetings
Stefan