marcolivierarsenault / moonraker-home-assistant

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

No sensors being created (buttons, macros, and camera created) #112

Closed greendog99 closed 1 year ago

greendog99 commented 1 year ago

Version of the moonraker integration

0.8

Describe your setup

Voron 2.4R2 with Klipper 0.11.0, Moonraker 0.8.0, Mainsail, RPi3, PrusaSlicer, Home Assistant 2023.4.2.

Describe the bug

Home Assistant only creates printer controls (buttons and macros) and the Crow's Nest camera. No sensor entities are created (printer status, fan speed, etc.).

From the Traceback in the log below, it looks like data["first_layer_height"] and data["layer_height"] don't exist (NoneType), which causes all sensor setup to fail.

The full log is below, but the relevant error excerpt is:

  File "/config/custom_components/moonraker/sensor.py", line 531, in calculate_current_layer
    (data["status"]["toolhead"]["position"][2] - data["first_layer_height"])
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

which relates to:

https://github.com/marcolivierarsenault/moonraker-home-assistant/blob/f61c4eef47356c675761f86bb09512617904c3eb/custom_components/moonraker/sensor.py#L530-L534

I've recently switched from SuperSlicer to PrusaSlicer, so perhaps these variables are coded differently in PS? The debug log shows the Query Object gcode output does show the layer heights, but I'm not sure how the integration reads those:

2023-04-12 11:46:57.447 DEBUG (MainThread) [custom_components.moonraker] {'size': 8285384, 'modified': 1681308929.4305804, 'uuid': 'c1886d73-8bb0-4680-9c51-ff101a593169', 'slicer': 'PrusaSlicer', 'slicer_version': '2.6.0-alpha6+MacOS-arm64', 'gcode_start_byte': 43153, 'gcode_end_byte': 8275420, 'object_height': 31.8, 'estimated_time': 9457, 'nozzle_diameter': 0.4, 'layer_height': 0.3, 'first_layer_height': 0.3, 'first_layer_extr_temp': 200.0, 'first_layer_bed_temp': 60.0, 'filament_name': 'MDF PLA Voron', 'filament_type': 'PLA', 'filament_total': 26609.82, 'filament_weight_total': 65.92, 'thumbnails': [{'width': 32, 'height': 32, 'size': 1773, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-32x32.png'}, {'width': 300, 'height': 300, 'size': 28910, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-300x300.png'}], 'print_start_time': 1681308929.7732337, 'job_id': '00006C', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode'}

Love the integration, thanks for putting it together! Let me know if I can provide any additional data or do any testing.

Moonraker Logs

2023-04-12 11:46:55.616 DEBUG (MainThread) [custom_components.moonraker] loading moonraker init
2023-04-12 11:46:55.634 DEBUG (MainThread) [custom_components.moonraker.api] Stated changed to {ws_connecting}
2023-04-12 11:46:55.965 DEBUG (MainThread) [custom_components.moonraker.api] Stated changed to {ws_connected}
2023-04-12 11:46:56.199 DEBUG (MainThread) [custom_components.moonraker] {'state': 'ready', 'state_message': 'Printer is ready', 'hostname': 'clu', 'klipper_path': '/home/pi/klipper', 'python_path': '/home/pi/klippy-env/bin/python', 'log_file': '/home/pi/printer_data/logs/klippy.log', 'config_file': '/home/pi/printer_data/config/printer.cfg', 'software_version': 'v0.11.0-169-g83308a10', 'cpu_info': '4 core ARMv7 Processor rev 4 (v7l)'}
2023-04-12 11:46:56.433 DEBUG (MainThread) [custom_components.moonraker] {'eventtime': 12233.790432886, 'status': {'print_stats': {'state': 'printing', 'message': '', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode', 'total_duration': 5486.823872803, 'print_duration': 5356.775327488001, 'filament_used': 15173.301239999078, 'info': {'total_layer': None, 'current_layer': None}}, 'display_status': {'message': 'Layer 47/106', 'progress': 0.58}, 'extruder': {'temperature': 199.87, 'target': 200.0, 'power': 0.8092012130691596}, 'heater_bed': {'target': 55.0, 'temperature': 55.1, 'power': 0.1088560624133767}, 'toolhead': {'position': [146.434, 208.972, 14.11, 29018.09514999929]}}}
2023-04-12 11:46:57.059 DEBUG (MainThread) [custom_components.moonraker] {'state': 'ready', 'state_message': 'Printer is ready', 'hostname': 'clu', 'klipper_path': '/home/pi/klipper', 'python_path': '/home/pi/klippy-env/bin/python', 'log_file': '/home/pi/printer_data/logs/klippy.log', 'config_file': '/home/pi/printer_data/config/printer.cfg', 'software_version': 'v0.11.0-169-g83308a10', 'cpu_info': '4 core ARMv7 Processor rev 4 (v7l)'}
2023-04-12 11:46:57.321 DEBUG (MainThread) [custom_components.moonraker] {'eventtime': 12234.542200489, 'status': {'print_stats': {'state': 'printing', 'message': '', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode', 'total_duration': 5487.575640406, 'print_duration': 5357.527095091001, 'filament_used': 15175.185999999083, 'info': {'total_layer': None, 'current_layer': None}}, 'display_status': {'message': 'Layer 47/106', 'progress': 0.58}, 'extruder': {'temperature': 199.89, 'target': 200.0, 'power': 0.8092012130691596}, 'heater_bed': {'target': 55.0, 'temperature': 55.09, 'power': 0.1088560624133767}, 'toolhead': {'position': [139.883, 189.337, 14.11, 29019.979909999296]}}}
2023-04-12 11:46:57.447 DEBUG (MainThread) [custom_components.moonraker] {'size': 8285384, 'modified': 1681308929.4305804, 'uuid': 'c1886d73-8bb0-4680-9c51-ff101a593169', 'slicer': 'PrusaSlicer', 'slicer_version': '2.6.0-alpha6+MacOS-arm64', 'gcode_start_byte': 43153, 'gcode_end_byte': 8275420, 'object_height': 31.8, 'estimated_time': 9457, 'nozzle_diameter': 0.4, 'layer_height': 0.3, 'first_layer_height': 0.3, 'first_layer_extr_temp': 200.0, 'first_layer_bed_temp': 60.0, 'filament_name': 'MDF PLA Voron', 'filament_type': 'PLA', 'filament_total': 26609.82, 'filament_weight_total': 65.92, 'thumbnails': [{'width': 32, 'height': 32, 'size': 1773, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-32x32.png'}, {'width': 300, 'height': 300, 'size': 28910, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-300x300.png'}], 'print_start_time': 1681308929.7732337, 'job_id': '00006C', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode'}
2023-04-12 11:46:57.447 ERROR (MainThread) [custom_components.moonraker] failed to get thumbnails  {'layer_count'}
2023-04-12 11:46:57.449 ERROR (MainThread) [custom_components.moonraker] Query Object {{'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode'}}
2023-04-12 11:46:57.449 ERROR (MainThread) [custom_components.moonraker] gcode {{'size': 8285384, 'modified': 1681308929.4305804, 'uuid': 'c1886d73-8bb0-4680-9c51-ff101a593169', 'slicer': 'PrusaSlicer', 'slicer_version': '2.6.0-alpha6+MacOS-arm64', 'gcode_start_byte': 43153, 'gcode_end_byte': 8275420, 'object_height': 31.8, 'estimated_time': 9457, 'nozzle_diameter': 0.4, 'layer_height': 0.3, 'first_layer_height': 0.3, 'first_layer_extr_temp': 200.0, 'first_layer_bed_temp': 60.0, 'filament_name': 'MDF PLA Voron', 'filament_type': 'PLA', 'filament_total': 26609.82, 'filament_weight_total': 65.92, 'thumbnails': [{'width': 32, 'height': 32, 'size': 1773, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-32x32.png'}, {'width': 300, 'height': 300, 'size': 28910, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-300x300.png'}], 'print_start_time': 1681308929.7732337, 'job_id': '00006C', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode'}}
2023-04-12 11:46:57.450 DEBUG (MainThread) [custom_components.moonraker] Finished fetching moonraker data in 1.251 seconds (success: True)
2023-04-12 11:46:57.555 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up moonraker platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 304, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/moonraker/sensor.py", line 316, in async_setup_entry
    await async_setup_basic_sensor(coordinator, entry, async_add_entities)
  File "/config/custom_components/moonraker/sensor.py", line 324, in async_setup_basic_sensor
    async_add_entities([MoonrakerSensor(coordinator, entry, desc) for desc in SENSORS])
  File "/config/custom_components/moonraker/sensor.py", line 324, in <listcomp>
    async_add_entities([MoonrakerSensor(coordinator, entry, desc) for desc in SENSORS])
  File "/config/custom_components/moonraker/sensor.py", line 462, in __init__
    self._attr_native_value = description.value_fn(self)
  File "/config/custom_components/moonraker/sensor.py", line 275, in <lambda>
    value_fn=lambda sensor: calculate_current_layer(sensor.coordinator.data),
  File "/config/custom_components/moonraker/sensor.py", line 531, in calculate_current_layer
    (data["status"]["toolhead"]["position"][2] - data["first_layer_height"])
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
2023-04-12 11:46:57.597 DEBUG (MainThread) [custom_components.moonraker] {'webcams': [{'name': 'CluCam', 'location': 'printer', 'service': 'mjpegstreamer-adaptive', 'target_fps': '10', 'stream_url': '/webcam/?action=stream', 'snapshot_url': '/webcam/?action=snapshot', 'flip_horizontal': False, 'flip_vertical': False, 'rotation': 0, 'source': 'database'}]}
2023-04-12 11:46:57.603 DEBUG (MainThread) [custom_components.moonraker] {'RESTART': 'Reload config file and restart host software', 'FIRMWARE_RESTART': 'Restart firmware, host, and reload config', 'STATUS': 'Report the printer status', 'HELP': 'Report the list of available extended G-Code commands', 'SAVE_CONFIG': 'Overwrite config file and restart', 'SET_GCODE_OFFSET': 'Set a virtual offset to g-code positions', 'SAVE_GCODE_STATE': 'Save G-Code coordinate state', 'RESTORE_GCODE_STATE': 'Restore a previously saved G-Code state', 'GET_POSITION': 'Return information on the current location of the toolhead', 'SET_PRINT_STATS_INFO': 'Overwrite, to get pause_next_layer and pause_at_layer feature', 'SDCARD_RESET_FILE': 'Clears a loaded SD File. Stops the print if necessary', 'SDCARD_PRINT_FILE': 'Loads a SD file and starts the print.  May include files in subdirectories.', 'PAUSE': 'Pause the actual running print', 'RESUME': 'Resume the actual running print', 'CLEAR_PAUSE': 'Clears the current paused state without resuming the print', 'CANCEL_PRINT': 'Cancel the actual running print', 'SET_DISPLAY_TEXT': 'Set or clear the display message', 'SET_GCODE_VARIABLE': 'Set the value of a G-Code macro variable', 'SET_PAUSE_NEXT_LAYER': 'Enable a pause if the next layer is reached', 'SET_PAUSE_AT_LAYER': 'Enable/disable a pause if a given layer number is reached', '_TOOLHEAD_PARK_PAUSE_CANCEL': 'Helper: park toolhead used in PAUSE and CANCEL_PRINT', '_CLIENT_EXTRUDE': 'Extrudes, if the extruder is hot enough', '_CLIENT_RETRACT': 'Retracts, if the extruder is hot enough', 'SET_LED_TEMPLATE': 'Assign a display_template to an LED', 'SET_LED': 'Set the color of an LED', '_SB_VARS': 'G-Code macro', '_SET_SB_LEDS': 'G-Code macro', '_SET_SB_LEDS_BY_NAME': 'G-Code macro', '_SET_LOGO_LEDS': 'G-Code macro', '_SET_NOZZLE_LEDS': 'G-Code macro', 'SET_LOGO_LEDS_OFF': 'G-Code macro', 'SET_NOZZLE_LEDS_ON': 'G-Code macro', 'SET_NOZZLE_LEDS_OFF': 'G-Code macro', 'STATUS_OFF': 'G-Code macro', 'STATUS_READY': 'G-Code macro', 'STATUS_BUSY': 'G-Code macro', 'STATUS_HEATING': 'G-Code macro', 'STATUS_LEVELING': 'G-Code macro', 'STATUS_HOMING': 'G-Code macro', 'STATUS_CLEANING': 'G-Code macro', 'STATUS_MESHING': 'G-Code macro', 'STATUS_CALIBRATING_Z': 'G-Code macro', 'STATUS_PRINTING': 'G-Code macro', 'SETUP_KAMP_MESHING': 'G-Code macro', 'RUN_SHELL_COMMAND': 'Run a linux shell command', 'BACKUP_CONFIG': 'Backs up config directory to GitHub', 'COND_G28': 'Home XYZ if not already homed', 'COND_QGL': 'QGL (including G28) if not already done', 'QGL': 'Home axes and then quad gantry level', 'OFF': 'G-Code macro', 'SHUTDOWN': 'G-Code macro', 'DUMP_VARIABLES': 'G-Code macro', 'GET_VARIABLE': 'G-Code macro', 'PARK': 'G-Code macro', 'PARK_CENTER': 'G-Code macro', 'PARK_BED': 'G-Code macro', 'PARK_FRONT': 'G-Code macro', 'PARK_REAR': 'G-Code macro', 'M600': 'Filament change', 'PRIME_NOZZLE': 'G-Code macro', 'PRINT_START': 'G-Code macro', 'PRINT_END': 'G-Code macro', 'EXCLUDE_OBJECT_START': 'Marks the beginning the current object as labeled', 'EXCLUDE_OBJECT_END': 'Marks the end the current object', 'EXCLUDE_OBJECT': 'Cancel moves inside a specified objects', 'EXCLUDE_OBJECT_DEFINE': 'Provides a summary of an object', 'RESPOND': 'Echo the message prepended with a prefix', 'SET_STEPPER_ENABLE': 'Enable/disable individual stepper by name', 'SET_TMC_FIELD': 'Set a register field of a TMC driver', 'INIT_TMC': 'Initialize TMC stepper driver registers', 'SET_TMC_CURRENT': 'Set the current of a TMC driver', 'DUMP_TMC': 'Read and display TMC stepper driver registers', 'TURN_OFF_HEATERS': 'Turn off all heaters', 'TEMPERATURE_WAIT': 'Wait for a temperature on a sensor', 'QUERY_ADC': 'Report the last value of an analog pin', 'PID_CALIBRATE': 'Run PID calibration test', 'SET_HEATER_TEMPERATURE': 'Sets a heater temperature', 'PROBE': 'Probe Z-height at current XY position', 'QUERY_PROBE': 'Return the status of the z-probe', 'PROBE_CALIBRATE': "Calibrate the probe's z_offset", 'PROBE_ACCURACY': 'Probe Z-height accuracy at current XY position', 'Z_OFFSET_APPLY_PROBE': "Adjust the probe's z_offset", 'SET_IDLE_TIMEOUT': 'Set the idle timeout in seconds', 'QUAD_GANTRY_LEVEL': 'Conform a moving, twistable gantry to the shape of a stationary bed', 'BED_MESH_CALIBRATE': 'G-Code macro', 'BED_MESH_PROFILE': 'Bed Mesh Persistent Storage management', 'BED_MESH_OUTPUT': 'Retrieve interpolated grid of probed z-points', 'BED_MESH_MAP': 'Serialize mesh and output to terminal', 'BED_MESH_CLEAR': 'Clear the Mesh so no z-adjustment is made', 'BED_MESH_OFFSET': 'Add X/Y offsets to the mesh lookup', '_CLIENT_VARIABLE': 'G-Code macro', 'STEPPER_BUZZ': 'Oscillate a given stepper to help id it', 'QUERY_ENDSTOPS': 'Report on the status of each endstop', 'SET_VELOCITY_LIMIT': 'Set printer velocity limits', 'MANUAL_PROBE': 'Start manual probe helper script', 'Z_ENDSTOP_CALIBRATE': 'Calibrate a Z endstop', 'Z_OFFSET_APPLY_ENDSTOP': 'Adjust the z endstop_position', 'TUNING_TOWER': 'Tool to adjust a parameter at each Z height', 'SET_PRESSURE_ADVANCE': 'Set pressure advance parameters', 'SET_EXTRUDER_ROTATION_DISTANCE': 'Set extruder rotation distance', 'SYNC_EXTRUDER_MOTION': 'Set extruder stepper motion queue', 'SET_EXTRUDER_STEP_DISTANCE': 'Set extruder step distance', 'SYNC_STEPPER_TO_EXTRUDER': 'Set extruder stepper', 'ACTIVATE_EXTRUDER': 'Change the active extruder', 'BASE_CANCEL_PRINT': "Renamed builtin of 'CANCEL_PRINT'", 'BASE_PAUSE': "Renamed builtin of 'PAUSE'", 'BASE_RESUME': "Renamed builtin of 'RESUME'", 'SET_PRINT_STATS_INFO_BASE': "Renamed builtin of 'SET_PRINT_STATS_INFO'", '_BED_MESH_CALIBRATE': "Renamed builtin of 'BED_MESH_CALIBRATE'", 'M99109': "Renamed builtin of 'M109'", 'M109': 'G-Code macro', 'M99190': "Renamed builtin of 'M190'", 'M190': 'G-Code macro', 'M117.1': "Renamed builtin of 'M117'", 'M117': 'G-Code macro'}
2023-04-12 11:46:57.620 DEBUG (MainThread) [custom_components.moonraker] {'error': {'code': -32601, 'message': 'Method not found'}}
2023-04-12 11:46:57.620 DEBUG (MainThread) [custom_components.moonraker] {'objects': ['webhooks', 'configfile', 'mcu', 'gcode_move', 'print_stats', 'virtual_sdcard', 'pause_resume', 'display_status', 'gcode_macro CANCEL_PRINT', 'gcode_macro PAUSE', 'gcode_macro RESUME', 'gcode_macro SET_PAUSE_NEXT_LAYER', 'gcode_macro SET_PAUSE_AT_LAYER', 'gcode_macro SET_PRINT_STATS_INFO', 'gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL', 'gcode_macro _CLIENT_EXTRUDE', 'gcode_macro _CLIENT_RETRACT', 'neopixel sb_leds', 'gcode_macro _sb_vars', 'gcode_macro _set_sb_leds', 'gcode_macro _set_sb_leds_by_name', 'gcode_macro _set_logo_leds', 'gcode_macro _set_nozzle_leds', 'gcode_macro set_logo_leds_off', 'gcode_macro set_nozzle_leds_on', 'gcode_macro set_nozzle_leds_off', 'gcode_macro status_off', 'gcode_macro status_ready', 'gcode_macro status_busy', 'gcode_macro status_heating', 'gcode_macro status_leveling', 'gcode_macro status_homing', 'gcode_macro status_cleaning', 'gcode_macro status_meshing', 'gcode_macro status_calibrating_z', 'gcode_macro status_printing', 'gcode_macro BED_MESH_CALIBRATE', 'gcode_macro SETUP_KAMP_MESHING', 'gcode_macro M109', 'gcode_macro M190', 'gcode_macro M117', 'gcode_macro BACKUP_CONFIG', 'gcode_macro COND_G28', 'gcode_macro COND_QGL', 'gcode_macro QGL', 'gcode_macro OFF', 'gcode_macro SHUTDOWN', 'gcode_macro DUMP_VARIABLES', 'gcode_macro GET_VARIABLE', 'gcode_macro PARK', 'gcode_macro PARK_CENTER', 'gcode_macro PARK_BED', 'gcode_macro PARK_FRONT', 'gcode_macro PARK_REAR', 'gcode_macro M600', 'gcode_macro PRIME_NOZZLE', 'gcode_macro PRINT_START', 'gcode_macro PRINT_END', 'exclude_object', 'stepper_enable', 'tmc2209 stepper_x', 'tmc2209 stepper_y', 'tmc2209 stepper_z', 'tmc2209 stepper_z1', 'tmc2209 stepper_z2', 'tmc2209 stepper_z3', 'tmc2209 extruder', 'heaters', 'heater_bed', 'probe', 'temperature_host raspberry_pi', 'temperature_sensor raspberry_pi', 'temperature_sensor mcu_temp', 'fan', 'heater_fan hotend_fan', 'controller_fan controller_fan_rear', 'controller_fan controller_fan_front', 'idle_timeout', 'quad_gantry_level', 'bed_mesh', 'gcode_macro _CLIENT_VARIABLE', 'motion_report', 'query_endstops', 'system_stats', 'manual_probe', 'toolhead', 'extruder']}
2023-04-12 11:46:57.669 DEBUG (MainThread) [custom_components.moonraker] {'eventtime': 12235.043007833, 'status': {'print_stats': {'state': 'printing', 'message': '', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode', 'total_duration': 5488.076447749999, 'print_duration': 5358.027902434999, 'filament_used': 15175.185999999083, 'info': {'total_layer': None, 'current_layer': None}}, 'display_status': {'message': 'Layer 47/106', 'progress': 0.58}, 'extruder': {'temperature': 199.91, 'target': 200.0, 'power': 0.8092012130691596}, 'heater_bed': {'target': 55.0, 'temperature': 55.08, 'power': 0.1088560624133767}, 'toolhead': {'position': [139.883, 189.337, 14.11, 29019.979909999296]}}}
2023-04-12 11:46:57.696 DEBUG (MainThread) [custom_components.moonraker] {'state': 'ready', 'state_message': 'Printer is ready', 'hostname': 'clu', 'klipper_path': '/home/pi/klipper', 'python_path': '/home/pi/klippy-env/bin/python', 'log_file': '/home/pi/printer_data/logs/klippy.log', 'config_file': '/home/pi/printer_data/config/printer.cfg', 'software_version': 'v0.11.0-169-g83308a10', 'cpu_info': '4 core ARMv7 Processor rev 4 (v7l)'}
2023-04-12 11:46:57.907 DEBUG (MainThread) [custom_components.moonraker] {'eventtime': 12235.293415072, 'status': {'print_stats': {'state': 'printing', 'message': '', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode', 'total_duration': 5488.326854988999, 'print_duration': 5358.2783096739995, 'filament_used': 15175.185999999083, 'info': {'total_layer': None, 'current_layer': None}}, 'display_status': {'message': 'Layer 47/106', 'progress': 0.58}, 'extruder': {'temperature': 199.93, 'target': 200.0, 'power': 0.8092012130691596}, 'heater_bed': {'target': 55.0, 'temperature': 55.08, 'power': 0.1088560624133767}, 'toolhead': {'position': [139.883, 189.337, 14.11, 29019.979909999296]}}}
2023-04-12 11:46:57.918 DEBUG (MainThread) [custom_components.moonraker] {'size': 8285384, 'modified': 1681308929.4305804, 'uuid': 'c1886d73-8bb0-4680-9c51-ff101a593169', 'slicer': 'PrusaSlicer', 'slicer_version': '2.6.0-alpha6+MacOS-arm64', 'gcode_start_byte': 43153, 'gcode_end_byte': 8275420, 'object_height': 31.8, 'estimated_time': 9457, 'nozzle_diameter': 0.4, 'layer_height': 0.3, 'first_layer_height': 0.3, 'first_layer_extr_temp': 200.0, 'first_layer_bed_temp': 60.0, 'filament_name': 'MDF PLA Voron', 'filament_type': 'PLA', 'filament_total': 26609.82, 'filament_weight_total': 65.92, 'thumbnails': [{'width': 32, 'height': 32, 'size': 1773, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-32x32.png'}, {'width': 300, 'height': 300, 'size': 28910, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-300x300.png'}], 'print_start_time': 1681308929.7732337, 'job_id': '00006C', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode'}
2023-04-12 11:46:57.918 ERROR (MainThread) [custom_components.moonraker] failed to get thumbnails  {'layer_count'}
2023-04-12 11:46:57.920 ERROR (MainThread) [custom_components.moonraker] Query Object {{'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode'}}
2023-04-12 11:46:57.921 ERROR (MainThread) [custom_components.moonraker] gcode {{'size': 8285384, 'modified': 1681308929.4305804, 'uuid': 'c1886d73-8bb0-4680-9c51-ff101a593169', 'slicer': 'PrusaSlicer', 'slicer_version': '2.6.0-alpha6+MacOS-arm64', 'gcode_start_byte': 43153, 'gcode_end_byte': 8275420, 'object_height': 31.8, 'estimated_time': 9457, 'nozzle_diameter': 0.4, 'layer_height': 0.3, 'first_layer_height': 0.3, 'first_layer_extr_temp': 200.0, 'first_layer_bed_temp': 60.0, 'filament_name': 'MDF PLA Voron', 'filament_type': 'PLA', 'filament_total': 26609.82, 'filament_weight_total': 65.92, 'thumbnails': [{'width': 32, 'height': 32, 'size': 1773, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-32x32.png'}, {'width': 300, 'height': 300, 'size': 28910, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-300x300.png'}], 'print_start_time': 1681308929.7732337, 'job_id': '00006C', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode'}}
2023-04-12 11:46:57.922 DEBUG (MainThread) [custom_components.moonraker] Finished fetching moonraker data in 0.301 seconds (success: True)
2023-04-12 11:47:27.398 DEBUG (MainThread) [custom_components.moonraker] {'eventtime': 12264.75280402, 'status': {'print_stats': {'state': 'printing', 'message': '', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode', 'total_duration': 5517.786243936999, 'print_duration': 5387.737698622, 'filament_used': 15261.139209999126, 'info': {'total_layer': None, 'current_layer': None}}, 'display_status': {'message': 'Layer 48/106', 'progress': 0.58}, 'extruder': {'temperature': 199.86, 'target': 200.0, 'power': 0.8587185197524144}, 'heater_bed': {'target': 55.0, 'temperature': 55.1, 'power': 0.07240271901182006}, 'toolhead': {'position': [153.631, 174.311, 14.41, 29105.93311999934]}}}
2023-04-12 11:47:27.435 DEBUG (MainThread) [custom_components.moonraker] {'state': 'ready', 'state_message': 'Printer is ready', 'hostname': 'clu', 'klipper_path': '/home/pi/klipper', 'python_path': '/home/pi/klippy-env/bin/python', 'log_file': '/home/pi/printer_data/logs/klippy.log', 'config_file': '/home/pi/printer_data/config/printer.cfg', 'software_version': 'v0.11.0-169-g83308a10', 'cpu_info': '4 core ARMv7 Processor rev 4 (v7l)'}
2023-04-12 11:47:27.619 DEBUG (MainThread) [custom_components.moonraker] {'eventtime': 12265.003623447, 'status': {'print_stats': {'state': 'printing', 'message': '', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode', 'total_duration': 5518.0370633640005, 'print_duration': 5387.988518049001, 'filament_used': 15262.589789999123, 'info': {'total_layer': None, 'current_layer': None}}, 'display_status': {'message': 'Layer 48/106', 'progress': 0.58}, 'extruder': {'temperature': 199.84, 'target': 200.0, 'power': 0.8587185197524144}, 'heater_bed': {'target': 55.0, 'temperature': 55.1, 'power': 0.07240271901182006}, 'toolhead': {'position': [183.937, 170.971, 14.41, 29107.383699999336]}}}
2023-04-12 11:47:27.632 DEBUG (MainThread) [custom_components.moonraker] {'size': 8285384, 'modified': 1681308929.4305804, 'uuid': 'c1886d73-8bb0-4680-9c51-ff101a593169', 'slicer': 'PrusaSlicer', 'slicer_version': '2.6.0-alpha6+MacOS-arm64', 'gcode_start_byte': 43153, 'gcode_end_byte': 8275420, 'object_height': 31.8, 'estimated_time': 9457, 'nozzle_diameter': 0.4, 'layer_height': 0.3, 'first_layer_height': 0.3, 'first_layer_extr_temp': 200.0, 'first_layer_bed_temp': 60.0, 'filament_name': 'MDF PLA Voron', 'filament_type': 'PLA', 'filament_total': 26609.82, 'filament_weight_total': 65.92, 'thumbnails': [{'width': 32, 'height': 32, 'size': 1773, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-32x32.png'}, {'width': 300, 'height': 300, 'size': 28910, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-300x300.png'}], 'print_start_time': 1681308929.7732337, 'job_id': '00006C', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode'}
2023-04-12 11:47:27.632 ERROR (MainThread) [custom_components.moonraker] failed to get thumbnails  {'layer_count'}
2023-04-12 11:47:27.635 ERROR (MainThread) [custom_components.moonraker] Query Object {{'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode'}}
2023-04-12 11:47:27.637 ERROR (MainThread) [custom_components.moonraker] gcode {{'size': 8285384, 'modified': 1681308929.4305804, 'uuid': 'c1886d73-8bb0-4680-9c51-ff101a593169', 'slicer': 'PrusaSlicer', 'slicer_version': '2.6.0-alpha6+MacOS-arm64', 'gcode_start_byte': 43153, 'gcode_end_byte': 8275420, 'object_height': 31.8, 'estimated_time': 9457, 'nozzle_diameter': 0.4, 'layer_height': 0.3, 'first_layer_height': 0.3, 'first_layer_extr_temp': 200.0, 'first_layer_bed_temp': 60.0, 'filament_name': 'MDF PLA Voron', 'filament_type': 'PLA', 'filament_total': 26609.82, 'filament_weight_total': 65.92, 'thumbnails': [{'width': 32, 'height': 32, 'size': 1773, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-32x32.png'}, {'width': 300, 'height': 300, 'size': 28910, 'relative_path': '.thumbs/Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm-300x300.png'}], 'print_start_time': 1681308929.7732337, 'job_id': '00006C', 'filename': 'Gridfinity bin 1x3x3-MDF PLA Voron-MDF Voron 0.4mm.gcode'}}
2023-04-12 11:47:27.639 DEBUG (MainThread) [custom_components.moonraker] Finished fetching moonraker data in 0.420 seconds (success: True)
greendog99 commented 1 year ago

Upon closer examination, I think a missing layer_count in the Gcode query is the root cause. It's causing an exception before layer_height has a chance to be read:

11:46:57.447 ERROR (MainThread) [custom_components.moonraker] failed to get thumbnails {'layer_count'}

https://github.com/marcolivierarsenault/moonraker-home-assistant/blob/f61c4eef47356c675761f86bb09512617904c3eb/custom_components/moonraker/__init__.py#L154-L167

marcolivierarsenault commented 1 year ago

Thanks @greendog99 we will look at it and fix it soon

greendog99 commented 1 year ago

I dug into things a bit further. SuperSlicer puts ; total layers count = x in the comments near the top of the gcode, and PrusaSlicer does not, so I added the following to my PrusaSlicer's Start G-code section:

; total layers count = [total_layer_count]

The Moonraker API is now reporting layer_count when querying file metadata. I restarted your integration while a new print was running, and all sensors are generated and are reporting.

I'm guessing maybe add a comment in the documentation advising to add this to the start gcode for non-SS users, and maybe a sanity check so the rest of the sensors still work if this value is missing?

greendog99 commented 1 year ago

Correction to my above comment -- the ; total layers count = [total_layer_count] statement must be added to the End G-Code section of PrusaSlicer, after PRINT_END, since Moonraker looks for this text in the Gcode footer.

https://github.com/Arksine/moonraker/blob/110cbd108409aecb4e5654b0f811cad047cd909b/moonraker/components/file_manager/metadata.py#L423-L425