jneilliii / OctoPrint-TasmotaMQTT

18 stars 16 forks source link

Possible to use this in a different plugin? #40

Closed Andoramb closed 4 years ago

Andoramb commented 4 years ago

Hi @jneilliii, thanks for the plugin, it helps a lot!

I started developing a touchscreen interface for Nextion displays, and I would like to add this plugin as a toggle button to my interface. (this is the part where I should mention that I have little programming experience, but I #tryhard) :D

How would it be possible to implement in python a toggle button of this plugin? My example: I have a Tasmota device with MQTT set up. I can toggle the switch via GCode (M80...M81) but that requires the name of the device as well - and thus it cannot be 'universal'.

My current interface looks like this - the "Turn off Printer" button should toggle the PSU/Tasmota image

Thanks 👍

jneilliii commented 4 years ago

So because the plugin support more than one relay it has to be able to identify them. You may want to look into how fieldOfView has implemented this in Cura's OnctoPrint Connection plugin, as it pulls in all known registered power control devices and has all the logic already worked out for powering on printers. The tasmota MQTT specific stuff can be found here and you'd just have to change the API command from turnOn to turnOff. Which leads me to the second option, you could just import all the MQTT related stuff, establish the connection to the same broker as the relay is configured for and send the commands via MQTT directly, which would require also knowing the topic, etc.

The only other option I could think of is adding an allOf/allOn API command to the plugin, that would just do that for all added/configured relays in the plugin.

Andoramb commented 4 years ago

Right, I don't think it necessary to pull all the available devices and select from them (atm... in a first version) - I wouldn't complicate it too much 😄 Maybe a first device that is on the list? or an allOFF/allON switch as you mentioned (but I also don't wanna complicate your plugin) I can see that you've got a lot of fun stuff in here: OctoPrint-Tasmota uses a similar aproach? Or do you know if there is a general "toggle PSU" command? It would be possible to do: self._printer.commands("M80 "+str(psu_name)here)+ " 1") locally, but that's just for one user. Feel free to close this topic, so you won't have +1 open item. Thanks again 😄

jneilliii commented 4 years ago

Yes, all my power related ones use the same approach because they have the ability to manage multiple devices. The PSUControl plugin is made for a single device and I think you can have it trigger a system command. It has api calls available to it as well, check out its wiki.