M118 publish to MQTT

Something like this?

[gcode_macro MYMESSAGE]
variable_my_msg: None
gcode:
  SET_GCODE_VARIABLE MACRO=MYMESSAGE VARIABLE=my_msg VALUE="'Hello World'"
  send_my_message
  
[gcode_macro MYMESSAGE2]
variable_my_msg: None
gcode:
  SET_GCODE_VARIABLE MACRO=MYMESSAGE VARIABLE=my_msg VALUE={printer.heater_bed.temperature}
  send_my_message

[gcode_macro send_my_message]
gcode:
  {% set temp = printer['gcode_macro MYMESSAGE'].my_msg | string %}
  PUBLISH_ALERT PAYLOAD="{temp}"

Beware:

  • I’m not a Klipper macro wizard
  • Most likely there is a more elegant / more “correct” way
1 Like