Sensors with "Flags" in Automation

For turning it off, I ended up giving up on trying the “Finishing” flag, and switch it to the “Is the Printing Printing or not”

alias: Turn Off 3d Printer on Completion
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.octoprint_print_progress
    above: '99'
    attribute: completion
condition:
  - condition: state
    entity_id: binary_sensor.octoprint_printing
    state: 'off'
  - condition: numeric_state
    entity_id: sensor.octoprint_bed_temperature
    below: '100'
action:
  - type: turn_off
    device_id: 52827340280a69b02c7f20ba34739891
    entity_id: switch.14606200f4cfa200b680
    domain: switch
mode: single

I doing a test print right now to see if it works.

But I’d still love to maybe setup automations to change the Color of the light to indicate stuff like Paused, or Error and stuff.

That’s an interesting one because it has attributes and sub-attributes. A way of testing to work out the correct syntax would be to write templates to try and extract the attribute and test them in the template dev tool.

ie: does something like this work or not-
state_attr('sensor.octoprint_print_status', 'finishing')

If that gives an error then the way of extracting that attribute needs to be altered, otherwise it should give a true or false based on what your printer is actually doing.

I know this thread is a few months old, but just wanted to add for anyone else, that the state_attr for the flags would look like this;

"{{state_attr('sensor.octoprint_print_status', 'flags').finishing }}"

I built a template sensor to show the flags so I could use them to do automations from state changes;

template:
  - sensor:
      - name: "Printer State"
        state: >
          {% if state_attr('sensor.octoprint_print_status', 'flags').closedOrError %}
            closedOrError
          {% elif state_attr('sensor.octoprint_print_status', 'flags').printing %}
            printing
          {% elif state_attr('sensor.octoprint_print_status', 'flags').ready %}
            ready
          {% elif state_attr('sensor.octoprint_print_status', 'flags').cancelling %}
            cancelling
          {% elif state_attr('sensor.octoprint_print_status', 'flags').finishing %}
            finishing
          {% elif state_attr('sensor.octoprint_print_status', 'flags').operational %}
            operational
          {% elif state_attr('sensor.octoprint_print_status', 'flags').paused %}
            paused
          {% elif state_attr('sensor.octoprint_print_status', 'flags').pausing %}
            pausing
          {% elif state_attr('sensor.octoprint_print_status', 'flags').resuming %}
            resuming
          {% elif state_attr('sensor.octoprint_print_status', 'flags').sdReady %}
            sdReady
          {% else %}
            none
          {% endif %} 
2 Likes