Custom button, that fires an html command

I'm new to Octopi and 3D printing, so i guess i should say "Hi Everyone".
I have a Anycubic i3 Mega printer, and i (of course) have an Octopi running on a Raspi3B+. Works very fine from the very first moment. Thanks for that!

My printer (not the Rapsi) is hooked to web-accessible poweroutlet (in fact it belongs to my home-automation,... but in the end i can switch that outlet via a html-request).

So... what i want: One button in my octopi-gui to switch that outlet on. Hitting that button octopi should issue an html-request in background. No need for errorhandling, just fire that command via curl or wget.

Not quite sure which add-on i should use for that. Found a custom command plugin, and if i get it right it should be able to fire up a bashscript via gcode? Is that right?

Any other ideas to get that working?

Thanks,
Sven

Hi, and welcome.

I'd be interested in how you do that. I have a similar thread running that involves using a smart plug but they usually require a phone app or other form of remote control.

It's a home-automation/smart-home plug, belonging to a brand called "Homematic" sold mainly in germany, but also available throughout europe. The central is hooked to the network, and communication to the plug is via 868 MHz. The plug also measures the power used, so my central is turning of my printer automaticly half a hour after the poweruseage droped below 20 Watt.
I can send a web-request to the central for turning the plug on.

Would be a bit oversized if you buy everything involved just for the printer, but i allready spend a lot of money in that system, so in fact that plug lay there just waiting for a new task.

Thanks for that. Amazon do sell some of it in the UK but I'm heavily invested in Hue, Alexa and Arlo home automation. I do have Sonoff devices and a TP-Link smart plug with another on order so will stick with what I know for now. Thanks again.

So basically, I'd:

  1. Create a shell script touch ~/scripts/plug-on.sh
  2. Edit that nano ~/scripts/plug-on.sh # magic happens here
  3. Adjust it so that it can run chmod a+x ~/scripts/plug-on.sh
  4. Edit the config to put a button on the Control tab nano ~/.octoprint/config.yaml # more magic
  5. Restart OctoPrint
  6. Visit Control tab
  7. Push new button

Obviously, some details are missing here. You mentioned that your web-accessible power outlet can be controlled but you didn't mention anything more.

It could be as simple as:

...but this is unlikely from the standpoint of security. But if this were the case, then the shell script would be something like:

push-on.sh:

#!/usr/bin/sh

curl http://ipaddress/api/on

...and you're done.


Details on the make/model of that power outlet and perhaps we could get a little closer.

1 Like

The OctoPrint-ShutdownPrinter plugin now allows for custom "API" calls which is just a web request. It unfortunately doesn't have the button like my other Tasmota/TPLink-SmartPlug plugins do. However, since you are using a home automation system it may support MQTT, which you could utilize my OctoPrint-MQTTPublish plugin.

I also forgot my OctoPrint-Domoticz which integrates with the Domoticz home automation server.

There is a PLUG IN for the TP-Link Smart plug in the plugin repo. I never used one before as I am heavily vested in the Wemo stuff.

Either way I bought one of the TP-Link plugs just for my printer and it works great, bot via the Octo webpage and the iOS app.

1 Like

I've seen the wemo stuff is pretty popular. I could potentially create a new plugin to support that if there is any possibility of working directly with that system via web calls or MQTT since i already have a lot of the framework in place. I started with the TPLink and it just grew from there.

I LOVE wemo stuff. Here is my issue with wemo. You must have all your plugs on the "same network". I have all my wemo stuff at home and I have my printer at work.

I bought a wemo plug at first and was just gonna use the iOS app to control it. I then learned that I can not have wemo plugs at home AND one at work.

Its a common complaint from people that have a vacation home or two locations ETC.

There is no fix currently.

I returned that one wemo and bought the TP-Link because there was already an octoprint plug in for it. It works perfectly. I will not be buying any other TP-Link suttf so this solution works for me.

Such a shame wemo...such a shame.

Yeah, I just saw something about that in the ouimeax python library. I think I might still make one, since like you said I LOVE wemo stuff seems pretty popular. Would probably just integrate my plugin framework with pywemo.

More power to you! I would love to seem more wemo support anywhere...even if unfortunately I can not use it myself.

PS - thank you very much for the TP-Link one. I use it every single day; really.

Just realized that my tasmota plug has wemo emulation, so I enabled that and am able to toggle it from python command line. It won't be difficult for me to integrate this into a plugin at all I don't think. I'd be curious if a set ip address vs discovery would bypass your vpn situation?

1 Like

Its the iOs app that seems to get confused. Once you have plugs on that "network" if you try to set up a new plug on a different one...it blows out the current config of plugs you have.

Interesting. From what I can tell it seems like this pywemo library will be able to communicate directly with the devices themselves. At least that's how I assume this is working. It's hard to tell since the tasmota plug I have is emulating a device. Not sure what the actual units will do if you start talking to them directly, but I would assume it wouldn't cause any issues. I've already started the fork and have the initial framework in place. Now I just have to go through and get the pywemo imported and change up all the commands to use this new library.

So it went much faster than anticipated. Probably will require some tweaking to work with real WeMo devices, but without one available to me I have to assume my emulated version on the tasmota device is the same.

OctoPrint-WemoSwitch

Wohooo! Thanks for that much input. You're great!

I'll go for OutsourceGurus solution.
My central doesn't understand MQTT without plugins, and, yeah, it is that easy, without any authorization, as it is all within it's own network.

Thanks everyone!

Uh... my config.yaml is really short compared to the stuff from the docs.

http://docs.octoprint.org/en/master/features/custom_controls.html#sec-features-custom-controls
Says i should have (create?) a section "controlls", and show's a nice example. But all i see is about gcode commands send to the printer... so i don't see how i get a shellscript run from here.
Ether i'm missing something, or it is more easy than what i can think of... any ideas where to look?

Custom controls on the "Control" tab indeed can't fire shell scripts (at least now without writing a plugin that provides custom controls that does that through JS... but I digress). However, something like outlet switching actually sounds more like something that should go into the System Menu only available to admins anyhow, and that does allow adding shell scripts. Take a look at that section in the docs instead.

Or alternatively install the PSU Control plugin by @kantlivelong and have that take care of everything for you.

Thanks! I'l have a look at the system menu section.