mainsail-crew / mainsail

Mainsail is the popular web interface for managing and controlling 3D printers with Klipper.
https://docs.mainsail.xyz
GNU General Public License v3.0
1.66k stars 348 forks source link

feat(history): add support for Moonraker sensor history_fields #1884

Closed meteyou closed 3 months ago

meteyou commented 3 months ago

Description

This PR will add the support for Moonraker sensors with history_fields in the print history.

Related Tickets & Documents

This FR comes via discord. Here is the link to post from the user "beavis": https://discord.com/channels/758059413700345988/1239686378678128650

and this was his config example:

[mqtt]
address:192.168.0.54
enable_tls: False
username: tasmota
password: **************

[power printer]
type:tasmota
initial_state: on
off_when_shutdown: False
locked_while_printing: True
address: 192.168.0.96
#off_when_shutdown_delay: 120
bound_services: klipper

[sensor tasmota_power]
type: mqtt
state_topic: tele/tasmota_voronv02/SENSOR
state_response_template:
  {% set resp = payload|fromjson %}
  {% set edata = resp["ENERGY"] %}
  {set_result("energy", edata["Total"])}
  {set_result("voltage", edata["Voltage"])}
  {set_result("power", edata["Power"])}
  {set_result("current", edata["Current"])}
history_field_energy_consumption:
  parameter=energy
  desc=Printer energy consumption
  strategy=delta
  units=kWh
  init_tracker=true
  precision=6
  exclude_paused=false
  report_total=true
  report_maximum=true
history_field_average_current:
  parameter=current
  desc=Average current draw
  strategy=average
  units=A
  report_total=false
  report_maximum=true
# Mulitple history fields may track the same sensor parameter:
history_field_max_current:
  parameter=current
  desc=Maximum current draw
  strategy=maximum
  units=A
  init_tracker=true
  report_total=false
  report_maximum=false

Mobile & Desktop Screenshots/Recordings

in the print history list: image

in the job details: image

and you can also hide these cols in this list: image

[optional] Are there any post-deployment tasks we need to perform?

beavis69 commented 3 months ago

Hi, it works for me, great job Screenshot from 2024-05-18 01-47-23