# Define one or more moonraker power devices that turn on/off with the screensaver (CSV list)
# screen_on_devices: example1, example2
# screen_off_devices: example1, example2
This is what I have for my case lights(and yes they can be toggled on/off and even does some dimming by heating up and cooling, all on the printers screen as well. But i never really use it from the printer’s screen) I use the slider on mainsail dashboard. Can’t take credit for this i found it on the interwebs a while back and have been using it on all my vorons
Thanks for the tip. Not really what I was hoping for, but I’ll consider that the fallback position.
My attempt above didn’t work. It resulted in an error message from Moonraker: Failed to load power device [power Printer_Lights] Klipper object must be either ‘output_pin’ or ‘gcode_macro’ for option ‘object_name’ in section [power Printer_Lights]
I tried renaming “led” to “output_pin” and a few other alternatives before deciding to attempt the ‘gcode_macro’ alternative.
Clicking the Mainsail LED slider “-” icon sends “SET_LED LED=Printer_Lights WHITE=0.00 SYNC=0 TRANSMIT=1” to the printer and the lights turn off. Conversely, clicking the “+” icon sends “SET_LED LED=Printer_Lights WHITE=1.00 SYNC=0 TRANSMIT=1”. So I thought I was armed with the requisite information to create a ‘g-code_macro’ object in printer.cfg. I added:
… and was quite successful in bricking my printer.
I had to ssh into the printer and remove the entries from all 3 files (I think it was the moonraker.conf that was actually the problem). I had about a 30 second window before the printer would kick me out each time so that took a couple of tries. I obviously don’t know what I’m doing here and think I better duplicate my eMMC before going any further in these attempts.
To get this working you need to make a couple of changes, your names are fine, these are the ones I used. You don’t need the LIGHTS_ON/OFF macros.
Put this in your moonraker.conf file:
[power Auto Lights]
type: klipper_device
object_name: gcode_macro SET_AUTO_LIGHTS
locked_while_printing: True
Put this in your KlipperScreen.conf file:
[main]
screen_on_devices: Auto Lights
screen_off_devices: Auto Lights
Then this goes in your My_Macros.cfg file:
[gcode_macro SET_AUTO_LIGHTS]
# The variable below should be initialized to the startup value. If your
# device is configured to be on at startup use "variable_value: 1"
variable_value: 1
gcode:
{% if 'VALUE' not in params %}
{action_raise_error("Parameter 'VALUE' missing from 'SET_AUTO_LIGHTS'")}
{% endif %}
{% set state = params.VALUE|int %}
{% if state %}
# turn the LED on
SET_LED LED=Printer_Lights WHITE=1.00 SYNC=0 TRANSMIT=1
{% else %}
# turn the LED off
SET_LED LED=Printer_Lights WHITE=0.00 SYNC=0 TRANSMIT=1
{% endif %}
# Update the state of our variable. This will inform Moonraker that
# the device has changed its state.
SET_GCODE_VARIABLE MACRO=SET_AUTO_LIGHTS VARIABLE=value value={state}
Dang. It’s like watching a magician: you know he’s doing something but darned if you can quite catch the details… One detail that might not be immediately apparent to the next confused fellow: I am using 3DPD’s DKEU macro pack. After many, many more failed attempts (AFTER backing up my eMMC) to figure this out I approached him for some advice via his Discord channel. Within hours he whipped this up – and those hours included a good night’s sleep. The reference to “My_Macros.cfg” is part of his DKEU setup and is included in printer.cfg. If you are not using DKEU (and if not, check it out, it’s a great set of really useful macros) then just put that part in printer.cfg and I believe it should work.
Note that for some reason I do not fully understand, it did NOT work after a simple “Restart firmware”. But it works perfectly after a power cycle. When the screensaver kicks in, the lights go out. Touch the screen and both screen and lights return. Perfect.
Thanks very much! I don’t think I would ever have got this on my own. Now I’ve got to watch this repeatedly in slow motion and see if I can spot the trick…
EDIT: on further study, I believe the code above will not work verbatim without DKEU installed. The line:
``SET_LED LED=Printer_Lights WHITE=1.00 SYNC=0 TRANSMIT=1```
comes from replacing the stock macros.cfg with his macro pack and would probably have to be replaced with whatever command your console shows when you toggle your printer light from the Mainsail interface. Possibly
``SET_PIN PIN=main_led VALUE=1``
You’re too kind, tbh this was not something I had looked into before now so it was an interesting little exercise.
Once you edit either of the moonraker.conf & KlipperScreen.conf files the respective software needs to be restarted for changes to take effect, just as we do with Klipper, & as we’re using Moonraker, KlipperScreen & Klipper all at once to accomplish this a simple Klipper restart will have brought the SET_AUTO_LIGHTS macro into the system but not the other two parts we need. So be sure to restart all 3 software applications before use.
Yes, you’re indeed correct if anyone wishes to make use of this you’ll need to adjust the LED name or fill in the correct pin to use on your system.
Change lines 12 & 15 in the above example I posted of the SET_AUTO_LIGHTS macro to suit your needs.
Just incase anyone is wondering the macro pack can be found here….
I know this is Klipperscreen and not Klipper, but it would kind of fit in with the general theme of an overall set of useful macros. If you knew of any. Just sayin…