taxilian / OctoPrint-Twilio

Octoprint plugin for print completion notifications using Twilio (for free w/ trial account)
GNU Affero General Public License v3.0
5 stars 9 forks source link

Feature Request: SMS on Paused #12

Open vietquocnguyen opened 6 years ago

vietquocnguyen commented 6 years ago

I have the Multi Colors plugin which pauses the print at certain layer heights. It would be nice to get a SMS notification to know when the print pauses.

BTW, thank you very much for this plugin, its awesome!

taxilian commented 6 years ago

Hmm; if there is a way to detect this it would be useful for a lot of things. Filament sensors that pause the print when they detect filament running out, for example.

I don't know how to do it is the only issue I see =]

shadycuz commented 6 years ago

I'm guessing they use some kinda event bus. I'll take a look at how they read from it and see what it would take to add feature.

On Wed, Jul 25, 2018, 1:34 PM Richard Bateman notifications@github.com wrote:

Hmm; if there is a way to detect this it would be useful for a lot of things. Filament sensors that pause the print when they detect filament running out, for example.

I don't know how to do it is the only issue I see =]

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/taxilian/OctoPrint-Twilio/issues/12#issuecomment-407886370, or mute the thread https://github.com/notifications/unsubscribe-auth/AQTJt3R6UOO7hQ9ZDRXvq4UMKAyX1B-Vks5uKNY8gaJpZM4VgwOg .

taxilian commented 6 years ago

It looks like there is a PrinterStateChanged event which gets fired whenever the state changes. Looking at the valid list of states it appears that PAUSED is one of them -- hard to be certain if this would cover it, but it seems likely.

I don't have time to try it myself, but it looks to me like you would probably just need to change the code path which currently triggers only on PrintDone and add PrinterStateChanged and check payload['state_id'] for PAUSED.

The one trick with this is that I'm pretty sure it would trigger if you manually pause as well -- in fact, it's probably more likely to trigger on a manual pause, it's possible octoprint wouldn't recognize a pause from GCODE, though I would think anything that you can continue from by clicking "resume" in the UI would qualify.

Someone would need to do some serious experimenting and I just don't have the time right now. Perhaps @shadycuz would be interested? I'd also look at source code for other notify plugins, there are many newer than this one and some may (likely) have had more thought put into them than I put into this one initially when I forked the emailnotifier.

shadycuz commented 6 years ago

Yeah I'll also look into it and share what I find. I'm traveling for work currently so no timeline.

vietquocnguyen commented 6 years ago

I came up with my own work around. Less than ideal, but it works for now. https://medium.com/@viet_73374/octoprint-sms-notifications-when-paused-or-any-event-5f2634d0a393

shadycuz commented 3 years ago

I think it would be useful to expand the current events we send notifications for. I'm not sure the best approach and I'm not very good at creating the gui setting page.

We could use a list of events that the user checks in the gui, but then we would really only be able to supply a limited number of events. We could also do something like a comma separated list of event names similar to how we do the multiple numbers.

The only downside being that if you checked the take a picture option you would get a picture with every event.

shadycuz commented 3 years ago

@vietquocnguyen I have implemented this feature in #25 , could you please test?

You can install the new version to your printer using this url https://github.com/taxilian/OctoPrint-Twilio/archive/events.zip. To do that just go into plugin manager and then click get more. Then find the ... from URL section.

image

Then just click install. Octoprint will ask you to reload and then it should work. Sometimes when you open the settings page for plugin that changes the GUI you might have to shift + f5 and/or restart your OctoPrint server (to force it to rebundle the frontend).

If you need help just let me know.

enderjones commented 3 years ago

@shadycuz so I updated to this new version and added a "PrintPaused" event under the plugin. I have the message configured as following "Prusa #5 job PAUSED: {name} paused printing". However the plugin never did kick out a message when the printer was paused. This is what my log file says:

2021-07-02 17:27:23,863 - octoprint.plugin - ERROR - Error while calling plugin smsnotifier Traceback (most recent call last): File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/plugin/init.py", line 271, in call_plugin result = getattr(plugin, method)(*args, *kwargs) File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/util/init.py", line 1890, in wrapper return f(args, **kwargs) File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_smsnotifier/init.py", line 131, in on_event return self._send_txt(event_config, payload, snapshot) File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_smsnotifier/init.py", line 172, in _send_txt payload['time'] = octoprint.util.get_formatted_timedelta(datetime.timedelta(seconds=payload["time"])) KeyError: u'time'

shadycuz commented 3 years ago

@enderjones Thanks for letting me know. I think you are the first user. Thats why it was never merged.

I will have to get my test machine out and take a look at it. My first thought is that the settings migration has failed 🤔 but I did test it very thoroughly for both 2.7 and 3.X.

If you don't mind losing your settings for OctoPrint-Twilio you could completely delete the plugin and all settings and try from scratch?

Do you know what version of octoprint you are on?

shadycuz commented 3 years ago

@enderjones Okay so this was a good find. It is a bug in the code. I use a virtual printer with a virtual file and I only tested with printstart and printdone events.

It turns out the time is not available on every event. The payload per event is different 🤔 https://docs.octoprint.org/en/master/events/index.html

I will fix this but might take me a day or two. WIll update you when I'm done.

shadycuz commented 3 years ago

@enderjones It's fixed, I hope ;). I think you will have to uninstall the plugin and reinstall. Thats because the version isn't actually changing. You should not lose your settings as long as you dont purge the plugin.

enderjones commented 3 years ago

@shadycuz sounds good I will give it a try on a single printer and see how it goes. Thanks for fixing it so fast!

shadycuz commented 3 years ago

@enderjones I'm going to tweak a few other things but feel free to give it a spin. I just tried a print pause and it worked fine 🎉

Mainly in the GUI I state you can use certain variables like {time} etc, but it's not true. You can use any of the variables that show up in the payload of the event you are targeting https://docs.octoprint.org/en/master/events/index.html

Edit: I'm a goof, the message in the GUI explains it perfectly, the only other change I'm going to make is a change to how much it is logging.

shadycuz commented 3 years ago

All good. We support any payload from the event docs including dot notation like position.f.

Screenshot_20210703-015955.png

@enderjones what I was hoping to have some one test is the upgrade and downgrade.

Did any of your printers already have a working Octoprint-twilio working?

It would be great if you could upgrade to the new plugin and see if it still works. Then reinstall the official version and see if it still works.

I tested it on my machine and it worked but I would like some confirmation before I release a new version.

enderjones commented 3 years ago

@shadycuz Success! That worked great, I went from stable to the new version that you just updated and it worked great. I will next test uninstalling and then reinstalling to this new version on one of my printers that was not working. Thanks again!

enderjones commented 3 years ago

@shadycuz Unfortunately just uninstalling and reinstalling did not work. I will try to clear the data and see if that helps at all.

enderjones commented 3 years ago

@shadycuz So I have this working on all my printers now. It was a little strange, after remove the plugin and clearing the data, I had to do a hard reboot on octoprint, otherwise the network connection would not reach the internet for some reason... I had this happen on multiple printers. Good news is that it is all working now! Thank you for your help and contribution!

shadycuz commented 3 years ago

Hmm strange. Not sure @enderjones

I would like to get one more person to try out the plugin and then I would feel good releasing this new version