3D Printer Maintenance Reminder

I have a number of appliances I want to do this for, but at the moment I want to start with my 3D printer. I want to setup something like a car’s maintenance schedule where I would get a “10 hour” alert and “100 hour” alert to do different types of maintenance. Once I have completed the appropriate tasks I would then call a service that would mark the maintenance repeat and restart the periods.

I’m currently able to monitor the printer status via MQTT and one of the possible state values is “printing”. Using history_stats I can determine how many total hours it has been in the printing status. I then setup a number helper that will store the “last_maintenance” value. My idea is that I will set this to the current total hours each time I do maintenance. I also have a template helper that returns (total_hours - last_maintenance_hours). This works and I can view the number of hours since the value stored in the last_maintenance_hours number helper.

From the developer tools I can call a service:

  service: input_number.set_value
  data:
    value: "{{ states('sensor.bambu_printing_total') }}"
  target:
    entity_id: input_number.last_bambu_maintenance

This works from developer tools and sets the helper to the current value for total hours. However, when I try to add that to the tap action of a button it creates the button. When I tap the button I get the following error:

Failed to call service input_number/set_value. expected float for dictionary value @ data['value']

The button config:

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: input_number.set_value
  data:
    value: '{{ states(''sensor.bambu_printing_total'') }}'
  target:
    entity_id: input_number.last_bambu_maintenance
name: Bambu Maintenance
icon: mdi:alert-circle-check-outline
entity: sensor.bambu_time_remaining
show_state: true

Any ideas on where I’m going wrong or how I can get around this? Am I going to have issues with this method in the long run as I reach the end of the recorder history?

Thanks

In HA all states (the value listed under the “state” tab in the dev tools states page) are strings.

the input number service expects a number not a string.

So in your template you need to convert the string to a number:

  service: input_number.set_value
  data:
    value: "{{ states('sensor.bambu_printing_total') | float}}"
  target:
    entity_id: input_number.last_bambu_maintenance

Thank you for the reply. I had tried that and got the same error. I also tried with different versions of quotes and it always reverts back to single quote around the value and double single quotes around the sensor name.

I double checked by copying your version to test again and still the same thing, it doesn’t appear to be converting to float. Once I save the changes and edit the button again it always reverts to this:

  service: input_number.set_value
  data:
    value: '{{ states(''sensor.bambu_printing_total'') | float }}'
  target:
    entity_id: input_number.last_bambu_maintenance

Thanks

Sorry, I missed that you said it would work in dev tools already. So ignore my above post. Apparently HA is smart enough to not need the float conversion in this case.

however…

I also missed that you tried to use the template in a button config.

Unfortunately you can’t use templates in a button.

see this link

That’s what did it for me, I overlooked that limitation and the script solved it, thank you.

1 Like