3D printer Shutdown Script help needed with "wait_for_trigger"

Hi All,

ok, I had an idea for a shutdown script for my 3d printer and came on here to find out where to start making it happen please see post here.

this is where I am now though… if I press the button (in lovelace) and the printer is printing, I want it to wait untill the conditions are true then turn off.

here is what I have done so far…

I created a sensor with a template

template:
  - sensor:
    - name: Ender Safe Shutdown
      state: >
        {% if is_state('switch.3d_printer', 'off') %}
          Off
        {% elif is_state('sensor.octoprint_current_state', 'Printing') %}
          Not Safe 
        {% elif states('sensor.octoprint_actual_tool0_temp')|int <= 29 %}
          Safe
        {% else %} 
          Not Safe
        {% endif %}

and a script

  alias: Ender 5 Safe Switch
  mode: single
  icon: mdi:printer-3d-nozzle
  sequence:
  - choose:
    - conditions:
      - condition: state
        entity_id: sensor.ender_safe_shutdown
        state: 'Off'
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.3d_printer
      - delay: 5
      - service: switch.turn_on
        target:
          entity_id: switch.octoprint_connect_to_printer
    - conditions:
      - condition: state
        entity_id: sensor.ender_safe_shutdown
        state: Safe
      sequence:
      - service: switch.turn_off
        target:
          entity_id: switch.3d_printer
    - conditions:
      - condition: state
        entity_id: sensor.ender_safe_shutdown
        state: Not safe
      sequence:
      - wait_for_trigger:
        - platform: state
          entity_id: sensor.ender_safe_shutdown
          to: "Safe"
          for: 10
      - service: switch.turn_off
        target:
          entity_id: switch.3d_printer

everything works except the “wait_for_trigger” part…

can anyone help me in where I am going wrong?

thanks for your help

Robin

You are using some states with speech marks and some with apostrophe and some with none.

If the only part of the automation that does not work is the wait for trigger then for me the obvious difference here is the use of speech marks on the state.

Got it… it was a typing error on my part.

@rossk Thank you for pointing out the variations with the states, it led me to go over every word and check that I hadn’t made a silly error ( which I did) . it wasn’t the quotes around the states but that I had missed a capital letter from one and had it as lowercase.

incase anyone else is reading this later and would like to use it, here is what I have working…

I have a Template sensor set in my Configuration.yaml as

template:
  - sensor:
    - name: Ender Safe Shutdown
      state: >
        {% if is_state('switch.3d_printer', 'off') %}
          Off
        {% elif is_state('sensor.octoprint_current_state', 'Printing') %}
          Not Safe 
        {% elif states('sensor.octoprint_actual_tool0_temp')|int >= 29 %}
          Not Safe
        {% else %} 
          Safe
        {% endif %}

and a Script set in my configuration.yaml as

  script:
    alias: Ender 5 Safe Switch
    mode: single
    icon: mdi:printer-3d-nozzle
    sequence:
    - choose:
      - conditions:
        - condition: state
          entity_id: sensor.ender_safe_shutdown
          state: 'Off'
        sequence:
        - service: switch.turn_on
          target:
            entity_id: switch.3d_printer
        - delay:
            seconds: 5
        - service: switch.turn_on
          target:
            entity_id: switch.octoprint_connect_to_printer
      - conditions:
        - condition: state
          entity_id: sensor.ender_safe_shutdown
          state: Safe
        sequence:
        - service: switch.turn_off
          target:
            entity_id: switch.3d_printer
      - conditions:
        - condition: state
          entity_id: sensor.ender_safe_shutdown
          state: Not Safe
        sequence:
        - wait_for_trigger:
          - platform: state
            entity_id: sensor.ender_safe_shutdown
            to: Safe
            for:
              seconds: 10
        - service: switch.turn_off
          target:
            entity_id: switch.3d_printer

I then have a button on my lovelace which is a toggle to the Script

and it works a charm!

Robin

1 Like