How to query a gcode_button in a macro

Basic Information:

Printer Model:
MCU / Printerboard:
Host / SBC
klippy.log

Fill out above information and in all cases attach your klippy.log file (use zip to compress it, if too big). Pasting your printer.cfg is not needed
Be sure to check our “Knowledge Base” Category first. Most relevant items, e.g. error messages, are covered there

Describe your issue:

Hi, I need some help. I want to use the state of a (gcode_button), for example, capture the output of QUERY_BUTTON button=MY_BUTTON, which will generate an output of “PRESSED” or “RELEASED”. I want to make a macro that checks the state of that button and depending on its state, do something. For example, something like:

{% if MY_BUTTON == “PRESSED” %}
do something…
{% else %}
do something…
{% endif %}

Please attach it to your next post.

1 Like

I’m sorry I didn’t attach it because I don’t have any errors with my configuration, I’m just thinking about making a macro that does what I mentioned above.

See Status reference - Klipper documentation

Example:

{% if printer["gcode_button MY_BUTTON"].state == "PRESSED" %}
do something...
{% else %}
do something else...
{% endif %}

Perfect, thanks bro.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.