Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to power off a power device when operating system shutdown. #856

Open
jhorn70 opened this issue May 15, 2024 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@jhorn70
Copy link

jhorn70 commented May 15, 2024

Is your feature request related to a problem? Please describe

I am new to Klipper/Moonraker/Mainsail and recently set up a power device for my printer which separates the PI and MCU power control. My device is a shelly device, but others should work the same way in my opinion. Intuitively, I expected when a host shutdown was issued in Mainsail that it would power off the printer device. Typically, when I am shutting down the Pi I am looking to shut down the entire machine.

Describe the solution you'd like

I would like a config option for a power device that is "off_when_host_shutdown". The machine.shutdown command should look at any power devices with "off_when_host_shutdown" is set to true and power them off prior to issuing the shutdown command to the operating system.

Describe alternatives you've considered

Using Home Assistant or some external solution to see if the pi is shutdown and shutting down the printer power.

Additional information

No response

@jhorn70 jhorn70 added the enhancement New feature or request label May 15, 2024
@AndreKR
Copy link

AndreKR commented Jun 16, 2024

I have exactly the same requirement. I tried setting off_when_shutdown: True but that doesn't seem to work. When I issue a host shutdown, the device isn't powered off. This could be because Moonraker is immediately stopped before it has time to send the (in my case) HTTP request, in which case the solution would probably have to be to delay the shutdown for a second or two, depending on the power devices that need to be notified.

@Laikulo
Copy link

Laikulo commented Jun 24, 2024

As a cheapshot workaround, if you are using systemd, you could add an ExecStop to some script that does whatever is needed. Since Moonraker itself won't receive a TERM until all the last one it should allow for most anything.

# Open an editor to an automatically created override
% sudo systemctl edit moonraker.service
[Service]
# The '-' below causes systemd to ignore failures, if MR is unable to process this
# Might be better to use the socket for this
ExecStop=-/usr/bin/http POST http://localhost:7125/machine/device_power/device?device=my_thingey&action=off
# This won't be needed if the above is sync
ExecStop=/usr/bin/sleep 1
# Replicate the default stop behavior (SIGTERM)
ExecStop=/usr/bin/kill 15 $MAINPID
% sudo systemctl daemon-reload

Adding an on_exit to power, and possibly an off_when_exiting parameter feels like an option to do this the real way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants