Jump to content

HOWTO: Pushover notifications for completed prints to your phone


DennisM
 Share

Recommended Posts

 

UPDATE: I feel like geekandi's moonraker integration is much simpler and more versatile that my solution,
so I recommend scrolling down and trying that method first. I'm going to do the same myself 🙂

 

Hello!

I thought I'd write up how I got pushover notifications working to my iPhone so I'd know when the Voron was finishing printing. You can, of course, expand this out even more to notify you of all sorts of things including when the printer is paused (for a filament change) or if some other condition requires it you to know about it. I just wanted to know when it was done so I could work on the next project, and I didn't always want to watch the klipper web UI for the job status.

It might seem like a lot of steps but bear with me, it's worth it once it's set up!
 

Configure pushover account/device/application token

  • you'll need to set up a free pushover account (I think it's free, if not it's a one-time charge per device or something like that) at pushover.net
  • if you are NEW to pushover you'll need to set up at least one device, which will include installing an APP on your phone and linking it to your account
  • make note of the device name when you are done setting up the device you want to use
  • generate a new application key and call it something useful. I used "Voron2.4" for my application name and left my description blank
  • you can leave the "URL" part of the app key generation blank, but I recommend uploading a Voron logo (see my phone screenshot)
  • copy down the API token, and from the main page also copy down your USER TOKEN somewhere

Set up some scripts for klipper

  • you'll need to install the gcode_shell_command.py script from this site. I just copied it all, then from a shell to my Rpi on the Voron I pasted it into a new file.
     
  • in case you need help on how to do that, follow these steps:
    • ssh into your pi (pi/raspberry) then cd /home/pi/klipper/scripts to get into the correct directory
    • using your favorite editor make the file (i.e. "vi gcode_shell_command.py", then "i", then paste in the text (in putty: right click), then esc, ZZ to save)
    • you might be able to create a local gcode_shell_command.py file and upload it via klipper's web UI but I'm not sure if you can navigate to the right directory in mainsail or fluidd
    • make it executable: chmod a+x gcode_shell_command.py

      Warning: The gcode_shell_command.py script could potentially cause issues if exploited since it can run arbitrary shell commands on the host controller. Be careful if you happen to have an internet-connected printer! I didn't write the script and don't take any responsibility for it, I just use it here.
       
  • next, create a shell script that does the actual pushover notification in the same directory as above
    • call this one pushover.sh and update the <> bracketed parts with your keys and device name.
       
    • #!/bin/bash
      
      TITLE="Voron 2.4 Print Completed"
      MESSAGE=$1
      DEVICE="<device name>"
      
      APP_TOKEN="<app token>"
      USER_TOKEN="<user token>"
      
      curl -s \
        --form-string "token=$APP_TOKEN" \
        --form-string "user=$USER_TOKEN" \
        --form-string "message=$MESSAGE" \
        --form-string "device=$DEVICE" \
        --form-string "title=$TITLE" \
        https://api.pushover.net/1/messages.json

      Make it executable as well "chmod a+x pushover.sh", then test it right now with "./pushover.sh "Test message" and see if you get a notification on your phone. My setup has about a 3-5 second delay but I do get the message on my phone. If you don't get it, then there's some work that needs to be done here before you can continue. This part needs to work, so double check your keys and device name (all from the pushover.net web UI).
       

Set up the gcode macros

In your printer.cfg or macros.cfg (if you have that) add these lines:

#####################################################################
##   Pushover notifications for completed print jobs
#####################################################################

[gcode_shell_command pushover_notify]
command: sh /home/pi/klipper/scripts/pushover.sh
timeout: 10.
verbose: True

[gcode_macro NOTIFY_PRINT_DONE]
gcode:
    {% if printer.print_stats.filename %}
    {% set fname = printer.print_stats.filename %}
    {% endif %}
    RUN_SHELL_COMMAND CMD=pushover_notify PARAMS={fname}

Finally, add this to your PRINT_END macro. Here's a snippet of mine:

    ...snip
    TURN_OFF_HEATERS
    RESTORE_GCODE_STATE NAME=STATE_PRINT_END

    ##  Oct 2022 -- Pushover notification of print complete
    NOTIFY_PRINT_DONE

 

That's about it!

Note that the NOTIFY_PRINT_DONE will crash klipper if there is no filename being processed, so I check for the existence of a filename before actually retrieving it from "printer.print_stats.filename". So if you call NOTIFY_PRINT_DONE somewhere or manually when no printing is happening, it will not have a filename.

Here's the link to the klipper printer variables available to use in your gcode macros.

Also, here's where I saw an example of how to pass information to the shell script: this page

 

Good luck!

Dennis

 

P.S. Please tell me if there is an easier way to get notifications on your phone from the Voron. I looked around and some something about using a messenger service (via moonraker) and maybe even a discord server option, but I was looking for something more in line with how pushover works. I use it for smarthome notifications anyway so it was an easy push to add this for the Voron setup.

IMG_8394.jpg

Edited by DennisM
not ready yet
  • Like 3
Link to comment
Share on other sites

I used to use the shell command way of doing things but now I do it directly within moonraker:

# https://moonraker.readthedocs.io/en/latest/configuration/#notifier
# https://github.com/caronc/apprise/wiki

[notifier pushover_error]
url: pover://{secrets.pushover_creds.user}@{secrets.pushover_creds.token}/{secrets.pushover_creds.device}?priority=emergency&expire=3600&retry=300&sound=alien
events: error
title: voron3: EMERG - {event_args[1].filename}
body: {event_name}: {event_args[1].message}
attach: http://localhost/webcam/?action=snapshot

[notifier pushover_cancel]
url: pover://{secrets.pushover_creds.user}@{secrets.pushover_creds.token}/{secrets.pushover_creds.device}?priority=emergency&sound=siren
events: cancelled
title: voron3: EMERG - {event_args[1].filename}
body: {event_name}: {event_args[1].message}
attach: http://localhost/webcam/?action=snapshot


[notifier pushover_pause]
url: pover://{secrets.pushover_creds.user}@{secrets.pushover_creds.token}/{secrets.pushover_creds.device}?priority=high&expire=1800&retry=180&sound=tugboat
events: pause
title: voron3: HIGH - {event_name}d
body: {event_name}d: {event_args[1].filename}
attach: http://localhost/webcam/?action=snapshot

[notifier pushover_resume]
url: pover://{secrets.pushover_creds.user}@{secrets.pushover_creds.token}/{secrets.pushover_creds.device}?priority=high&sound=tugboat
events: resume
title: voron3: HIGH - {event_name}d
body: {event_name}d: {event_args[1].filename}
attach: http://localhost/webcam/?action=snapshot


[notifier pushover_start]
url: pover://{secrets.pushover_creds.user}@{secrets.pushover_creds.token}/{secrets.pushover_creds.device}
events: started
title: voron3: Starting to print
body: Printing: {event_args[1].filename}

[notifier pushover_complete]
url: pover://{secrets.pushover_creds.user}@{secrets.pushover_creds.token}/{secrets.pushover_creds.device}
events: complete
title: voron3: Print completed
body: Completed: {event_args[1].filename}
attach: http://localhost/webcam/?action=snapshot

My ~/.moonraker_secrets looks like:

[pushover_creds]
token: aqt2a[redacted]
user: u7vmb[redacted]
device: [device_name]

Hope this is helpful to others!

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Useful! I myself use the Telegram integration and like it a lot. It sends photos, progress, makes a timelaps at the end, and all kind of notifications...

And you can cancel, pause, etc from Telegram itself if you like to.

Edited by Buurman
Link to comment
Share on other sites

@geekandi Thank you for the awesome moonraker info -- I am very interesting in trying out your method as it seems like a great way to do this.

And I'm glad I sorted out the way I did it as I learned a lot of things including "jinja2" and how that scripting language works, along with a better understanding of klipper macros & variables.

  • Like 1
Link to comment
Share on other sites

23 minutes ago, DennisM said:

@geekandi Thank you for the awesome moonraker info -- I am very interesting in trying out your method as it seems like a great way to do this.

Very glad I could help, or at least offer hints.

I had spent some time doing things via the shell command gcode but if it is a long running (think of TCP handshake and remote site being slow or internet is down) means you could lock up your klippy process waiting on the command to finish and get a print failure. Then I found the hints I needed to implement in Moonraker instead.

Link to comment
Share on other sites

2 hours ago, geekandi said:

I used to use the shell command way of doing things but now I do it directly within moonraker:

Doing this within moonraker looks interesting.  I tried configuring this, and with some reading to get a better idea of how apprise works and Notifier, I **think** I configured it correctly, and I don't have errors when I restart moonraker and klipper.   I setup a test gcode macro [gcode_macro pushover_test] that calls Notify to use the [notifier pushover] I configured in moonraker as per the moonraker documentation, but if I try to call pushover_test from the gcode console in klipper, nothing happens.  no errors, but nothing happens.  And nothing goes into the logs beyond bits that suggest that it accepted my actual config.   I tried testing apprise from the command line and it works, so I know the apprise/pushover piece is working.   Any suggestions?  In my moonraker.conf I have:

 

[notifier pushover]
url: pover://{secrets.pushover_creds.user}@{secrets.pushover_creds.token}/{secrets.pushover_creds.device}
events: gcode
title: rue: Message
body: Message: Test hello
attach: http://localhost/webcam/?action=snapshot
 
And my macro is:
 
[gcode_macro pushover_test]
gcode:
{action_call_remote_method("notify",
name="pushover",
message="Test Pushover Message Successful!")}

This is of course assuming I correctly have my secrets setup (which I believe I do since I initially had it incorrectly setup and klipper complained bitterly).

After restarting, from the gcode console i just type "pushover_test", and nothing happens.  No errors, no nothing.   Ideas? If you'd rather take this offline (or not at all), that's cool too - I just figured other's are probably interested.....

Paul

 
 
 

 

 

Link to comment
Share on other sites

Hey Paul, I'm sort of in the same boat. I can't get it working via moonraker either but haven't had a lot of time to diagnose.

One thing I wanted to look into is how the secrets file gets "included" or "loaded" -- I don't see it referenced in the code above so I wanted to make sure the path and filename are correct to ensure it's loading.

When I download moonraker's log file from the mainsail UI, it doesn't mention notifications at all so I'm also wondering if there's some notifications module/script that needs to be installed as well?

Link to comment
Share on other sites

assumptions are made, take it ss you will 🙂

Create ~/.moonraker_secrets as I mentioned before.

In moonraker.conf:

 

[secrets]
secrets_path: ~/.moonraker_secrets

[include moonraker-notifications.conf]

and moonraker-notifications.conf is as I have given it above.

This has Moonraker to send the notifications, not a gcode call.

Once you have restarted everything go ahead and start a print, and you should get a notice that printing has started. Let it start then issue a CANCEL_PRINT and you should get a cancellation notification. Or a PAUSE!

 

Link to comment
Share on other sites

Ok, so I'm working, in fact I believe I was working when I posted above, but I was trying to test using a gcode call rather than just an actual print event.   Exactly as @geekandi suggested, after restarting, go ahead and start a print and see if it works.   Where I was getting hung up is that I was focusing on trying to use a gcode macro to test if things were working.  my gcode_macro above is still not working, but that doesn't appear to be a apprise/pushover issue.    I am interested in trying to get arbitrary gcode notifications working as it would be useful to be able to send messages via pushover via gcode, rather than only doing so for print events......

Link to comment
Share on other sites

@geekandi Thanks! I literally just scrolled down through the docs and saw the [secrets] section so that'll probably explain what's happening for me. I assume I had no need for a secrets file before, and didn't have that as part of my initial configs for the printer, so I understand why I didn't have that in place. Paul seems to have that part, or knew to add it 🙂

I'll try it when my current print is done and see how it goes, thanks again!

Link to comment
Share on other sites

6 minutes ago, DennisM said:

@geekandi Thanks! I literally just scrolled down through the docs and saw the [secrets] section so that'll probably explain what's happening for me. I assume I had no need for a secrets file before, and didn't have that as part of my initial configs for the printer, so I understand why I didn't have that in place. Paul seems to have that part, or knew to add it 🙂

I'll try it when my current print is done and see how it goes, thanks again!

GOOD LUCK!

Link to comment
Share on other sites

Woohoo! That's what it needed. Works like a charm.

I will say, however, that this expands my realm of possibilities since I read that there are both homeassistant device control options and even MQTT pub/sub options. I already run homeassistant and the mosquito broker for MQTT, so I can also pub/sub data to it from the Voron via these features.

From there I can do my own notifications from HA, which is even better!

Thanks again for all the help, and thanks for your contributions to making this set of features even better for everyone!

Dennis

moonraker_notify.jpg

Link to comment
Share on other sites

Paul, did you see the section in the doc called "Notifying from Klipper" ?

In case you wanted to also create gcode macros; not sure if it can call these pushover events directly or not, however. Their example uses telegram:

# printer.cfg

[gcode_macro NOTIFY_FILAMENT_CHANGE]
gcode:
  {action_call_remote_method("notify",
                             name="telegram",
                             message="Filament change needed!")}

 

Link to comment
Share on other sites

1 hour ago, DennisM said:

Paul, did you see the section in the doc called "Notifying from Klipper" ?

In case you wanted to also create gcode macros; not sure if it can call these pushover events directly or not, however. Their example uses telegram:

# printer.cfg

[gcode_macro NOTIFY_FILAMENT_CHANGE]
gcode:
  {action_call_remote_method("notify",
                             name="telegram",
                             message="Filament change needed!")}

Yeah, that's where I got the idea to try it from.  My code posted further back is taken from this, with small changes.   This is the piece I haven't been able to get working yet.... 😕

Link to comment
Share on other sites

19 hours ago, Paul Fielding said:

Yeah, that's where I got the idea to try it from.  My code posted further back is taken from this, with small changes.   This is the piece I haven't been able to get working yet.... 😕

Wouldn't the PAUSE event be enough from Moonraker?

Link to comment
Share on other sites

12 hours ago, geekandi said:

Wouldn't the PAUSE event be enough from Moonraker?

I'm not sure I follow your question.  The code I posted earlier is an attempt to send arbitrary messages to pushover via gcode, as opposed to messages sent as a result of specific print events.   I've got the specific print events working, but not doing a remote call from arbitrary gcode, which I think would be useful to be able to do.  I don't have a specific scenario for it yet, but I may as well make the functionality work if I can, so that when I need it, I've just got it.....

Link to comment
Share on other sites

10 hours ago, Paul Fielding said:

I'm not sure I follow your question.  The code I posted earlier is an attempt to send arbitrary messages to pushover via gcode, as opposed to messages sent as a result of specific print events.   I've got the specific print events working, but not doing a remote call from arbitrary gcode, which I think would be useful to be able to do.  I don't have a specific scenario for it yet, but I may as well make the functionality work if I can, so that when I need it, I've just got it.....

Legit! Sorry, guess I lost context part way through

Link to comment
Share on other sites

  • 4 weeks later...

I've been struggling trying to get PAUSE notifications to work. So far no luck - hoping for some tips here as I continue experimenting.

Here's what I have that isn't working for some reason:

[notifier pushover_pause]
url: pover://{secrets.pushover_creds.user}@{secrets.pushover_creds.token}/{secrets.pushover_creds.device}
events: pause
title: Voron2.4: Paused
body: Print paused: {event_args[1].filename}

The print complete notifications work great. I wonder if the event name is something other than "pause"

Link to comment
Share on other sites

Hmm... found this in the docs. I think it should be "paused" -- I'm going to try it out and see if that's it.

Quote

 

events: *
#   The events this notifier should trigger to. '*' means all events.
#   You can use multiple events, comma separated.
#   Valid events:
#      started
#      complete
#      error
#      cancelled
#      paused
#      resumed

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...