Keeps adding a "m" aka minutes to the value

Hi, prob a silly one, but I can’t figure out what’s causing it.

I have a sensor type history_stat

- platform: history_stats
  name: Boiler Time Elapsed
  entity_id: switch.boiler
  state: 'on'
  type: time
  start: '{{ as_timestamp(states.automation.is_the_boiler_on.attributes.last_triggered) }}'
  end: '{{ now() }}'

Which will generate a sensor.boiler_time_elapsed. But by some reason it add to the DB with the “m” at the value… See screenshot.

I then have a template to make it “pretty” but I wanted to make it as minutes, so unit_of_measurement: “min” but instead its adding min to the m…

The template:

 platform: template
  sensors:
    time_elapsed:
      friendly_name: "Boiler Time Running"
      value_template: '{{ states.sensor.boiler_time_elapsed.attributes.value }}'
      unit_of_measurement: "min"
      icon_template: >-
        {% if is_state('switch.timed_boiler', 'on') %}
          mdi:timer
        {% else %}
            mdi:timer-off
        {% endif %}

Which results in this:

Any ideas, what I’m doing wrong?

Thanks for the help.

Try:

      value_template: "{{ state_attr('sensor.boiler_time_elapsed','value').replace('m','') }}"

Note that will only work if the time is less than an hour. If it’s an hour or more, but less than a day, it will be displayed as “xxh yym”.

EDIT: Actually, you’re probably better off using something like this:

      value_template: "{{ states('sensor.boiler_time_elapsed')|float|multiply(60)|round }}"

Yep, this did the work :slight_smile: Thanks

1 Like