Door Switch -- Variable help needed

Hello!

Need a little help with variables. Is there a way to check what the current state of a variable is over console? It seems like dooropen is not getting set back to 0 when the door is shut even down the macros are running.

Attached is a door_switch.cfg with code to work with a door safety switch. Everything works except when it’s time to resume the print, it just keeps running door_open_state2.

door_switch.cfg (1.7 KB)

[gcode_macro RESUME]
description: Resume the actual running print
rename_existing: RESUME_BASE
gcode:
{% if dooropen == 0 %} # check to see if door is open - requires [virtual_sdcard]
G28 X
G28 Y
##### read extrude from _TOOLHEAD_PARK_PAUSE_CANCEL macro #####
{% set extrude = printer[‘gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL’].extrude %}
#### get VELOCITY parameter if specified ####
{% if ‘VELOCITY’ in params|upper %}
{% set get_params = (‘VELOCITY=’ + params.VELOCITY) %}
{%else %}
{% set get_params = “” %}
{% endif %}
##### end of definitions #####
{% if printer.extruder.can_extrude|lower == ‘true’ %}
M83
G1 E{extrude} F2100
{% if printer.gcode_move.absolute_extrude |lower == ‘true’ %} M82 {% endif %}
{% else %}
{action_respond_info(“Extruder not hot enough”)}
{% endif %}
RESUME_BASE {get_params}
{% else %}
door_open_state2
{% endif %}

Hello @chhhris !

Maybe this helps a bit:

Thanks for the info but not really. I can already check the gcode_button state. It’s not setting dooropen to 0 when the door is shut but the rest of the release code runs.

[gcode_macro door_open_state1]
variable_dooropen: 0
gcode: 
  {% if dooropen == 0 %} # requires [virtual_sdcard]  
      PAUSE # call printer pause macro
      SIREN
      M118 CLOSE DOOR THEN PRESS RESUME
  {% else %}
  {% endif %}

[gcode_macro door_open_state1]
gcode:
  SIREN
  M118 CLOSE DOOR THEN PRESS RESUME
  UPDATE_DELAYED_GCODE ID=set_dooropenbusy DURATION=2.5 # timing must be set to clear delay plus 0.5s.

There is door_open_state1 defined twice?

Yes, I sent that before corrected but even after changing the second one to state2, still does not work.

I’ve narrowed it down to the resume macro not reading the state of the variable. I need a work around and I’m thinking about using an open output pin as a dummy just to be able to use the pin state.

You might need to read the pin state in an own macro as the resume macro is evaluated completely at start, so it does not “see” the change

Updated the file in the original post. Can you explain this more? Not sure how to callback the pin state in this case (variable_dooropen).

No matter what, in current configuration, Resume results in below.

{action_respond_info(“Door is still open”)}

For more context, KlipperScreen is being used and the goal is to keep the user from resuming if the door is open.

[gcode_macro RESUME]
description: Resume the actual running print
rename_existing: RESUME_BASE
gcode:
    get_door_open
[gcode_macro get_door_open]
{% if dooropen == 0 %} # check to see if door is open - requires [virtual_sdcard]
G28 X
G28 Y
##### read extrude from _TOOLHEAD_PARK_PAUSE_CANCEL macro #####
{% set extrude = printer[‘gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL’].extrude %}
#### get VELOCITY parameter if specified ####
{% if ‘VELOCITY’ in params|upper %}
{% set get_params = (‘VELOCITY=’ + params.VELOCITY) %}
{%else %}
{% set get_params = “” %}
{% endif %}
##### end of definitions #####
{% if printer.extruder.can_extrude|lower == ‘true’ %}
M83
G1 E{extrude} F2100
{% if printer.gcode_move.absolute_extrude |lower == ‘true’ %} M82 {% endif %}
{% else %}
{action_respond_info(“Extruder not hot enough”)}
{% endif %}
RESUME_BASE {get_params}
{% else %}
door_open_state2
{% endif %}

Maybe something like this. But no warranty whatsoever.

@Sineos thanks! That still results in it running the else statement in both pin states. @koconnor how can we use a gcode button variable as a dependency?

Trying something new… Using filament sensor switch

How to only allow resume if filament is detected?
door_switch_new.cfg (632 Bytes)

IT WORKS! I just wish there was an alternative so object naming was door switch instead of filament runout since there is also a filament runout sensor in there for logging purposes.

gcode:
{% if printer[“filament_switch_sensor door_closed”].filament_detected == True %}
G28 X
G28 Y
##### read extrude from _TOOLHEAD_PARK_PAUSE_CANCEL macro #####
{% set extrude = printer[‘gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL’].extrude %}
#### get VELOCITY parameter if specified ####
{% if ‘VELOCITY’ in params|upper %}
{% set get_params = (‘VELOCITY=’ + params.VELOCITY) %}
{%else %}
{% set get_params = “” %}
{% endif %}
##### end of definitions #####
{% if printer.extruder.can_extrude|lower == ‘true’ %}
M83
G1 E{extrude} F2100
{% if printer.gcode_move.absolute_extrude |lower == ‘true’ %} M82 {% endif %}
{% else %}
{action_respond_info(“Extruder not hot enough”)}
{% endif %}
RESUME_BASE {get_params}
{% else %}
door_open_pause
{% endif %}