cmroche / OctoPrint-HomeAssistant

Home Assistant plugin for OctoPrint, enabling MQTT discovery of you device and sensors
112 stars 18 forks source link

How to send Gcode comands #28

Closed Sleeepy2 closed 4 years ago

Sleeepy2 commented 4 years ago

I just want to be able to send M80 and M81 for PSU control but I can't figure out how to send these.

cmroche commented 4 years ago

Consider this example, which calls an MQTT service to publish a command to the homing topic.

type: entity-button
name: Home all axes
tap_action:
  action: call-service
  service: mqtt.publish
  service_data:
    topic: octoprint/virtual_p/hassControl/home
    payload: '["x", "y", "z"]'

The only change here is that you want to send raw gcode commands to octoprint/virtual_p/hassControl/commands, the payload field will be a string with your gcode commands, ie: payload: "M80"

Sleeepy2 commented 4 years ago

Right sorry, it was late when I sent this. It's the topic that I am not sure of. Is this topic default for everyone or is the "virtual_p" part unique to the printer? I have my button set like this, it just doesn't do anything.

type: entity-button
tap_action:
  action: call-service
  service: mqtt.publish
  service_data:
    topic: octoprint/virtual_p/hassControl/commands
    payload: '["M80"]'
cmroche commented 4 years ago

Yeah that wouldn't work :P

The octoprint/virtual_p part is going to depend on your MQTT setup. I think the default from the MQTT plugin is just octoPrint to you would change that to octoPrint/hassControl/commands

If you have the OctoPrint-MQTT plugin configuration, you will see an option for the base topic

image

This is what you will need to use.

cmroche commented 4 years ago

One more note, send "M80" not "[M80]", input needs to be a simple string, not an array.

Sleeepy2 commented 4 years ago

It's still not working. I am missing something stupid, I know it. image

image

image

cmroche commented 4 years ago

Your topic needs to be octoPrint not octoprint also I'm not sure you should use the quotations in the UI, it might try to escape them which would not work.

The command should show up in the terminal tab of octoprint itself, you can check their to confirm that it received something.

Sleeepy2 commented 4 years ago

Well there's my problem... I can send the Power off command M81 no problem but it looks like it's not listening when it's in the "power off" state so, M80 does nothing... I had assumed that since Octopi was running it would always be listening to MQTT and I could send M80 but I guess it's not. Sorry to bother you with this.

cmroche commented 4 years ago

I'm not familiar with what OctoPrint does after the power-off command, it may be ignoring or rejecting the commands issued at that point--especially if the printer is disconnected.

This plugin doesn't care much though, and I think that the MQTT plugin is still listening in that case. Unless all your sensors read as "unavailable" the MQTT channel is still working.

Sleeepy2 commented 4 years ago

Yeah I am not sure either and I am not sure if MQTT is still listening or not as it sill shows binary_sensor.a10m_connected is still connected with the power off.

Either way this is not your issue. Thanks for your plugin and for you time.