marcolivierarsenault / moonraker-home-assistant

Home Assistant integration for Moonraker, Klipper and Mainsail
https://moonraker-home-assistant.readthedocs.io
MIT License
237 stars 26 forks source link

Dashboard for different printer status #306

Closed BeHappy2021 closed 6 months ago

BeHappy2021 commented 6 months ago

Hi,

I'm using version 1.1.1 of the integration in HA 2024.3.3.

I've just created a dashboard that uses sensor.printer_current_print_state to decide what to display. Screengrabs are attached.

Would you like the code to go along with it as an example dashboard?

Off off Standy standby Printing printing Complete finished

marcolivierarsenault commented 6 months ago

yeah, that is quite cool, I would love to add that in the doc

BeHappy2021 commented 6 months ago

Here is everything for it. It was of course inspired by the one you already have in the docs.

Note: You need to create the input_text helpers for job filament, total filament and total jobs. They get set by the automation. This dashboard uses the new sections feature so you can arrange the cards by drag and drop after creating them. Remember to change all the entity names to match yours - search for 3dprinter and replace all with your printer name.

Uses the following custom cards installed through HACS: apexcharts-card state-switch mushroom-entity-card, mushroom-template-card bar-card

icon: mdi:printer-3d
type: sections
sections:
icon: mdi:printer-3d
type: sections
sections:
  - type: grid
    cards:
      - type: custom:state-switch
        entity: sensor.3dprinter_current_print_state
        transition: flip-x
        states:
          unavailable:
            type: vertical-stack
            cards:
              - type: custom:mushroom-entity-card
                entity: input_text.job_filament
                name: Filament used in last job
                layout: vertical
                tap_action:
                  action: none
                hold_action:
                  action: none
                double_tap_action:
                  action: none
              - type: custom:mushroom-entity-card
                entity: input_text.total_filament
                name: Total Filament Used
                layout: vertical
                tap_action:
                  action: none
                hold_action:
                  action: none
                double_tap_action:
                  action: none
              - type: custom:mushroom-entity-card
                entity: input_text.total_jobs
                name: Total Jobs
                layout: vertical
                tap_action:
                  action: none
                hold_action:
                  action: none
                double_tap_action:
                  action: none
              - type: custom:mushroom-entity-card
                entity: input_text.total_time
                name: Total Time
                layout: vertical
                tap_action:
                  action: none
                hold_action:
                  action: none
                double_tap_action:
                  action: none
          standby:
            type: custom:mushroom-template-card
            primary: Printer is standing by
            layout: vertical
            tap_action:
              action: url
              url_path: http://moonraker_url #This will only work over LAN you need e.g Letsencrypt for access via internet
            hold_action:
              action: none
            double_tap_action:
              action: none
            icon_color: yellow
            icon: mdi:printer-3d
          printing:
            type: vertical-stack
            cards:
              - type: custom:mushroom-template-card
                secondary: >-
                  Current filename - {{
                  states('sensor.3dprinter_filename') }}
                fill_containter: true
                multiline_secondary: true
                layout: vertical
                tap_action:
                  action: url
                  url_path: http://moonraker_url
                hold_action:
                  action: none
                double_tap_action:
                  action: none
                icon_color: green
                icon: mdi:printer-3d
              - type: horizontal-stack
                cards:
                  - type: custom:mushroom-entity-card
                    entity: sensor.3dprinter_current_print_state
                    name: Status
                    layout: vertical
                    tap_action:
                      action: none
                    hold_action:
                      action: none
                    double_tap_action:
                      action: none
                  - type: custom:mushroom-entity-card
                    entity: sensor.3dprinter_print_duration
                    name: Elapsed
                    layout: vertical
                    tap_action:
                      action: none
                    hold_action:
                      action: none
                    double_tap_action:
                      action: none
                  - type: custom:mushroom-entity-card
                    entity: sensor.3dprinter_print_eta
                    name: Completion
                    layout: vertical
                    tap_action:
                      action: none
                    hold_action:
                      action: none
                    double_tap_action:
                      action: none
                  - type: custom:mushroom-entity-card
                    entity: binary_sensor.3dprinter_filament_sensor
                    name: Filament
                    layout: vertical
                    tap_action:
                      action: none
                    hold_action:
                      action: none
                    double_tap_action:
                      action: none
          complete:
            type: custom:mushroom-template-card
            Primary: Printing has finished
            layout: vertical
            fill_containter: true
            tap_action:
              action: url
              url_path: http://moonraker_url
            hold_action:
              action: none
            double_tap_action:
              action: none
            icon_color: green
            icon: mdi:printer-3d
      - type: custom:state-switch
        entity: sensor.3dprinter_current_print_state
        transition: flip-x
        states:
          printing:
            type: vertical-stack
            cards:
              - type: custom:bar-card
                name: Print progress..
                icon: mdi:clock-end
                color: blue
                entity: sensor.3dprinter_progress
              - type: custom:bar-card
                name: Fan speed
                icon: mdi:fan
                color: blue
                entity: sensor.3dprinter_nozzle_fan
              - type: tile
                name: Filament used
                tap_action:
                  action: none
                icon_tap_action:
                  action: none
                entity: sensor.3dprinter_filament_used
              - type: picture-entity
                show_state: false
                show_name: false
                camera_view: auto
                name: Thumbnail
                tap_action:
                  action: none
                icon_tap_action:
                  action: none
                entity: camera.3dprinter_thumbnail
          complete:
            type: vertical-stack
            cards:
              - type: custom:bar-card
                name: Print progress..
                icon: mdi:clock-end
                color: blue
                entity: sensor.3dprinter_current_print_state
              - type: tile
                name: Filament used
                tap_action:
                  action: none
                icon_tap_action:
                  action: none
                entity: input_text.job_filament
          standby:
            type: vertical-stack
            cards:
              - type: custom:mushroom-template-card
                primary: Job progress will appear here
                layout: vertical
                tap_action:
                  action: url
                  url_path: http://moonraker_url
                hold_action:
                  action: none
                double_tap_action:
                  action: none
                icon_color: yellow
                icon: mdi:printer-3d
              - type: tile
                name: Filament used in last job
                vertical: true
                tap_action:
                  action: none
                icon_tap_action:
                  action: none
                entity: input_text.job_filament
    title: 3D Printer
  - type: grid
    cards:
      - type: custom:state-switch
        entity: sensor.3dprinter_current_print_state
        transition: flip-x
        states:
          unavailable:
            type: custom:mushroom-template-card
            primary: Printer turned off
            layout: vertical
            tap_action:
              action: none
            hold_action:
              action: none
            double_tap_action:
              action: none
            icon_color: red
            icon: mdi:printer-3d
          printing:
            type: horizontal-stack
            cards:
              - type: custom:button-card
                name: Pause
                tap_action:
                  action: toggle
                entity: button.3dprinter_pause_print
              - type: custom:button-card
                name: Resume
                tap_action:
                  action: toggle
                entity: button.3dprinter_resume_print
              - type: custom:button-card
                name: Cancel
                tap_action:
                  action: toggle
                entity: button.3dprinter_cancel_print
              - type: custom:button-card
                name: Emergency
                tap_action:
                  action: toggle
                color: red
                confirmation:
                  text: This will REBOOT the printer. Are you sure?
                entity: button.3dprinter_emergency_stop
          standby:
            type: custom:mushroom-template-card
            primary: Controls will appear here
            layout: vertical
            tap_action:
              action: url
              url_path: http://moonraker_url
            hold_action:
              action: none
            double_tap_action:
              action: none
            icon_color: yellow
            icon: mdi:printer-3d
      - square: true
        type: grid
        cards:
          - type: conditional
            conditions:
              - condition: state
                entity: sensor.3dprinter_current_print_state
                state: printing
            card:
              type: custom:apexcharts-card
              graph_span: 1h
              span:
                start: hour
                offset: "-10min"
              header:
                show: true
                title: Temperatures
                show_states: true
                colorize_states: true
              now:
                show: true
                label: Now
                color: "#00ff00"
              all_series_config:
                show:
                  legend_value: false
                float_precision: 0
              apex_config:
                legend:
                  show: false
              series:
                - entity: sensor.3dprinter_extruder_temperature
                  name: Nozzle
                  opacity: 0.4
                - entity: sensor.3dprinter_extruder_target
                  name: Nozzle target
                  opacity: 0.4
                - entity: sensor.3dprinter_bed_temperature
                  name: Bed
                  opacity: 0.4
                - entity: sensor.3dprinter_bed_target
                  name: Bed target
                  opacity: 0.4
                - entity: sensor.3dprinter_mcu_temp
                  name: MCU
                  opacity: 0.4
          - type: conditional
            conditions:
              - condition: state
                entity: sensor.3dprinter_current_print_state
                state: standby
            card:
              type: custom:mushroom-template-card
              primary: Temperatures will appear here
              layout: vertical
              tap_action:
                action: url
                url_path: http://moonraker_url
              hold_action:
                action: none
              double_tap_action:
                action: none
              icon_color: yellow
              icon: mdi:printer-3d
        columns: 1
    title: " "
cards: []

Automation to set input_text values

alias: Set printer variables on start up.
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.3dprinter_printer_state
    to: ready
    for:
      hours: 0
      minutes: 1
      seconds: 0
    from: null
  - platform: state
    entity_id:
      - sensor.3dprinter_current_print_state
    from: printing
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - service: input_text.set_value
    data:
      value: >-
        {{
        states.sensor.3dprinter_totals_filament_used.state_with_unit
        }}
    target:
      entity_id: input_text.total_filament
  - service: input_text.set_value
    data:
      value: "{{ states.sensor.3dprinter_totals_jobs.state_with_unit }}"
    target:
      entity_id: input_text.total_jobs
  - service: input_text.set_value
    data:
      value: >-
        {{ states.sensor.3dprinter_totals_print_time.state_with_unit
        }}
    target:
      entity_id: input_text.total_time

Automation for when printing is finished - also sends a notification via the mobile app. I've set it to be 98% completion as sometimes it doesn't fire at 99 or 100% if it is a quick print.

alias: Printer finished
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.3dprinter_progress
    to: "98"
condition: []
action:
  - service: input_text.set_value
    data:
      value: "{{ states.sensor.3dprinter_filament_used.state_with_unit }}"
    target:
      entity_id: input_text.job_filament
  - service: notify.mobile_app
    data:
      message: TTS
      title: Printing complete
      data:
        tts_text: Print job is complete
  - service: notify.mobile_app
    data:
      title: πŸ–¨ Printer finished
      message: Printer job has finished
      data: {}
mode: single

Optional automation to reload the automation when you turn on the printer or it finishes printing:

alias: Reload Printer data
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.3dprinter_printer_state
    from: unavailable
  - platform: state
    entity_id:
      - sensor.3dprinter_current_print_state
    from: printing
condition: []
action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      device_id: #whatever your printer device_id is
marcolivierarsenault commented 6 months ago

added in the doc.

Novocaine85 commented 5 months ago

automation to obtain input_text.job_filament is missing. Could you please provide it?

marcolivierarsenault commented 5 months ago

Not sure I fully follow what is missing right now

BeHappy2021 commented 5 months ago

automation to obtain input_text.job_filament is missing. Could you please provide it?

It is in the 'Automation to set input_text values' The bit of code that starts:

alias: Set printer variables on start up.
Novocaine85 commented 5 months ago

There are 4 input_text on the dashboard script

total_job total_filament total_time job_filament

But the automation sets up just the first three on the list.

BeHappy2021 commented 5 months ago

@Novocaine85 you're right! Sorry I forgot the other automation. I've edited the code and added the automation that does that bit. It is the bit for when printing is finished.

Novocaine85 commented 5 months ago

@Novocaine85 you're right! Sorry I forgot the other automation. I've edited the code and added the automation that does that bit. It is the bit for when printing is finished.

No problem!

Thank you for adding the automation and for all the script. It's pretty cool. ☺️☺️

BeHappy2021 commented 5 months ago

Is it all working for you now?

Novocaine85 commented 5 months ago

Let you know asap

Il Mer 24 Apr 2024, 09:06 BeHappy2021 @.***> ha scritto:

Is it all working for you now?

β€” Reply to this email directly, view it on GitHub https://github.com/marcolivierarsenault/moonraker-home-assistant/issues/306#issuecomment-2074225315, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWVCTKEE3OFMIOX2DIYPLTY65KZBAVCNFSM6AAAAABFMUSI4CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZUGIZDKMZRGU . You are receiving this because you were mentioned.Message ID: <marcolivierarsenault/moonraker-home-assistant/issues/306/2074225315@ github.com>

Novocaine85 commented 5 months ago

yep, it works πŸ‘πŸ‘

marcolivierarsenault commented 5 months ago

Re-adjusting official doc

BeHappy2021 commented 5 months ago

Sorry for the extra hassle.

marcolivierarsenault commented 5 months ago

haha please don't be sorry for contributing to an open source project.

Thanks for sharing actually

BeHappy2021 commented 5 months ago

The the status while printing the following will add a card with the layer status:

      - type: custom:mushroom-template-card
        primary: >-
          Layer:
          {{states("sensor.3dprinter_current_layer")}}/{{states("sensor.3dprinter_total_layer")}}
        secondary: ''
        icon: mdi:layers-triple
        layout: horizontal
        fill_container: true

On mine I've inserted this in the horizontal stack after the Fan Speed and above the Filament Used