Button-card: display float as integer?

Hi everybody,

I am trying to clean up my lovelace; what took one entire row is now, thanks to button-card just one card. There is just one little thing I cannot fix: the little green circle one Prusa MK3S Current State is an input_number entity, which is float by default.

Can I display it as int instead? It will always be an integer, anyway (by that, I mean that the first float value is always 0).

Below is how I display the card. I have tried piping to int, but that will make the entire card disappear from lovelace. I didn’t find a setting to define the input_number as integer by default. Is there something I can do? Thank you for your ideas :slight_smile:

  - type: "horizontal-stack"
    cards:
      - type: "custom:button-card"
        entity: sensor.prusa_mk3s_current_state
        show_state: true
        label: >
          [[[
            return "ETA " + states['sensor.mk3s_rest'].state
          ]]]
        show_label: true
        size: 20px
        styles:
          grid:
            - position: relative
          custom_fields:
            notification:
              - background-color: green
              - border-radius: 50%
              - position: absolute
              - left: 51%
              - top: -10%
              - height: 20px
              - width: 20px
              - font-size: 10px
        custom_fields:
          notification: > 
### this is the part in question >
            [[[
              return states['input_number.gedruckt_ohne_reinigung'].state 
            ]]]
### <
        tap_action:
          action: call-service
          service: input_number.set_value
          service_data:
            entity_id: input_number.gedruckt_ohne_reinigung
            value: 0

what does your mk3s_rest sensor look like?

This is the sensor

sensor:
  - platform: template
    sensors:
      mk3s_rest:
        friendly_name: "Prusa MK3S Time Remaining Time"
        unit_of_measurement: "Restzeit"
        value_template: "{{ states('sensor.prusa_mk3s_time_remaining') | float | timestamp_custom('%R', false) }}"
 

That sensor displays the correct time as far as I can tell.

Right, but why convert if it you want the time renaming as an integer in the UI. An integer is going to be a time in minutes or hours or seconds. Not all 3.

I don’t want the time remaining. Sorry, perhaps I didn’t explain this correctly… I have this already (displaying 00:47 in the image). What I am trying to change is the 0.0 you can see (above Prusa MK3S Current State) to be 0 instead of 0.0.

That is input_number.gedruckt_ohne_reinigung, which is a sensor that I manually reset to zero and which increases by 1 each time a print finishes (then reminds me to clean the print bed once the number reaches 2).

For some reason, it is just zero now, but before it was always displayed as in the image above.

ah ok, this is what I use to only display the relevant sig figs.

[[[
    var statestr = states['input_number.gedruckt_ohne_reinigung'].state;
    var test = parseFloat(parseFloat(statestr).toFixed(2));
    return (isNaN(test)) ? 'NA' : test;
]]]
3 Likes

Thank you. Unfortunately, now that it already displays the correct value, I cannot verify if this works for me as well (I exchanged my lines with your example, but the output stayed the same). I will take a look next time the value changes =)