How do i save a sensor with hh:mm measurement type?

This is my config

sensor:
  - platform: command_line
    name: ATAC_arrival
    unit_of_measurement: time
    command: "awk -F, '{print $3}' /home/homeassistant/.homeassistant/atac.txt"

What i get is this


awk correctly parses the hh:mm format but the sensor graph rounds up to the whole hour making no sense.
Thank you for your help!

Anyone? :frowning:

it’s only looking at the first number. And it assumed it was a string getting converted to a number.

You can’t graph time in multiple units. HH:MM will be parsed and the :MM will be removed because the only number that can be graphed is a number with the correct number format. I.E. x.xxxx, not xx:xx.

So your options are to convert your value to hours, or convert your value to minutes, or convert your values to seconds. To me it seems like you’d want your value in hours.

so this should work.

sensor:
  - platform: command_line
    name: ATAC_arrival
    unit_of_measurement: hours
    command: "awk -F, '{print $3}' /home/homeassistant/.homeassistant/atac.txt"
    value_template: >
      {% set hours, minutes = value.split(':') %}
      {{ hours | float + minutes | float / 60 }}

Wow, I hadn’t thought of that!
I used a template sensor to learn that thing too.
Hope there will be proper support for time formats in the future though, centesimal minutes are not exactly elegant or intuitive.
Thank you petro!

1 Like