Last known state sensor

Hi

I have a 3d printer that does not support standby mode so when the printer is off the sensors in home assistant becomes unavailable

Is there an easy way to create a sensor to keep the last known value and ignore the unavailable or unknown state?

One option would be to use a trigger-based template sensor with a State trigger that only listens for your desired states.

template:
  - trigger:
      - trigger: state
        entity_id: sensor.printer_mode_example
        to:
          - 'on'
          - printing
          - idle
    sensor:
      - name: 3D Printer Mode
        state: "{{ trigger.to_state.state }}"

Or instead of the to: section you could use

not_to:
  - unavailable