It has been a long wait to have automatic dust extraction on my PrintNC. It comprises of two elements: An extractor – to replace the 20-30 year old Vax/Bunnings bucket combo, and a smart plug to have it automatically turning it on and off.
The Extractor

The extractor was purchased second hand at a great price ($50AUD). The 5 inch nozzle was reduced to 4 inches, mainly because of the price of 5 inch PVC pipe. The flexible tube is 100mm Ag pipe. I had initially planned to use all Ag pipe, but there was performance issues during testing when using long lengths of it.
Automation – Tuya Smart Plug
To turn the extractor on and off I purchased a Powertech Smart Plug from Jaycar on sale ($19AUD). My researched shows it was based on the Tuya eco system. I could have opened it to check to see if it was running an ESP32 and flash it accordingly, but I was looking for an off-the-shelf solution and it’s more likely than not that it’s a newer model that has a different chipset. I set it up in HomeAssistant running LocalTuya.
To automate the smart plug, I leveraged the HomeAssistant API and 2 custom M-Codes: M100 (on) M101 (off). To make the changes in LinuxCNC, there is some small modifications needed.
my-mill.ini
...
[DISPLAY]
PROGRAM_PREFIX = <LinuxCNC my-mill Directory>
...
In the my-mill directory create 2 case sensitive files M100 and M101 (no file extensions). This page from the LinuxCNC manual was very informative for troubleshooting.
M100
#!/bin/bash
#Used to turn the Extractor ON
curl -k -X POST -H "Authorization: Bearer <API KEY>" \
-H "Content-Type: application/json" -d '{"entity_id": "switch.extractor"}' \
http://homeassistant:8123/api/services/switch/turn_on
exit 0
M101
#!/bin/bash
#Used to turn the Extractor OFF
curl -k -X POST -H "Authorization: Bearer <API KEY>" \
-H "Content-Type: application/json" -d '{"entity_id": "switch.extractor"}' \
http://homeassistant:8123/api/services/switch/turn_off
exit 0
Made the two files executable using ‘chmod +x M100’ and ‘chmod +x M101’. I executed them from the command line and they were both successful.
Restart LinuxCNC, Home the CNC axis’s and try to manually run M100 on the MDI [F5] tab. The extractor turns on with M100 and M101 turns it off.
In Estlcam I added the M100 code to Setup –>CNC Programs –>Texts –> Program start, and M101 to Program end. To test, I created a small v-carve action and imported the g-code into LinuxCNC. It started the extractor, then spindle, then fake milled the air. Then turned the spindle and extractor off again. Despite the annoying delays while it communicates with HomeAssistant, then HomeAssistant turns it on, it works perfectly.
An extra bonus, the smart plug can be manually turned on and off for the times I wish to vacuum the spoil board and surrounds.
Update – Added Extractor Buttons to Axis GUI
In the main ini file I added the MDI commands, HAL file and PYVCP file:
[DISPLAY]
PYVCP = AXIS_Buttons.xml
[HALUI]
MDI_COMMAND = M100
MDI_COMMAND = M101
[HAL]
POSTGUI_HALFILE = AXIS_Buttons.hal
Added the buttons to AXIS_Buttons.xml:
<pyvcp>
...
<button>
<relief>RAISED</relief>
<bd>3</bd>
<halpin>"ext-on"</halpin>
<text>"Extractor On"</text>
<font>("Helvetica",12)</font>
</button>
<button>
<relief>RAISED</relief>
<bd>4</bd>
<halpin>"ext-off"</halpin>
<text>"Extractor Off"</text>
<font>("Helvetica",12)</font>
</button>
...
</pyvcp>
In the AXIS_Buttons.hal I mapped the pins to the halpins in the XML file:
#set up the extractor buttons
# ON
net exctractoron halui.mdi-command-00 <= pyvcp.ext-on
# OFF
net exctractoroff halui.mdi-command-01 <= pyvcp.ext-off

Caveat – The CNC most be turned on and homed to use the MDI_COMMANDs. I hope to migrate the buttons to running bash scripts directly, then it wont need these requirements.