Time format 25 character (2020-01-20T20:48:36+00:100) on sensors last detected, how do I change it please?

It appears most of my sensors , i.e. Canary, Ring etc are retaining a 25 character time string
2020-01-20T20:48:36+00:100 in the last used entity.

This becomes more of an issue in HADashboard as I want to print out the time within a tile.
I’m not sure if this should be done in the config.yaml or somewhere else, In fact I’m not sure at all how to do this.

Ideally the UK format would work well for me i.e. 20-Jan-20 8:48PM. however showing the number of minutes from current time would be just as useful.

If anyone can give me some help please it would be very much appreciated.

Thank you.

You could make a template sensor in Home Assistant and use that entity to display the time in HADashboard. See here https://www.home-assistant.io/integrations/template/

Thank you Tomas for your reply, I think I’m getting close to solving this, taken 1 step forward and half a step back :slight_smile:

With your suggestion and a post from another thread I came up with the following code in my configuration.yaml

  - platform: template
    sensors:
      garden_last_time
         friendly_name: "garden last time"
         value_template: {{as_timestamp(states("sensor.garden_last_activity")) | timestamp_custom('%H:%M',True)  }}

The value template entry I checked in developers tool>templates and indeed returns just the time which is exactly what i want.

The problem I have now is that I get the green tick in the configuration.yaml indicating all is fine.

However prior to restating my server and clicking on the validate config it errors with the following return.


Error loading /config/configuration.yaml: invalid key: "OrderedDict([('as_timestamp(states("sensor.garden_last_activity")) | timestamp_custom(\'%H:%M\'', None), ('True)', None)])"
  in "/config/configuration.yaml", line 130, column 0

Line 130 in my configuration.yaml is the value_template line.

It could be just a quote or bracket missing but not exactly sure what I’ve done wrong here.

Again any help would be appreciated.

Best Regards

You either need to enlose the value template in quotes, and then you can not use the same type of quotes inside the value template (which you are doing) , or use the multiline yaml option which do not require the quoutes:

value_template: >- # This is the multiline directive
     {{as_timestamp(states("sensor.garden_last_activity")) | timestamp_custom('%H:%M',True)  }}

this would also work:

value_template: '{{as_timestamp(states("sensor.garden_last_activity")) | timestamp_custom("%H:%M",True)  }}'
3 Likes

Hi Tomas, Thank you ever so much your a star!. confirming this works and returns the new formatted time. I has to change the indentation also slightly for everything to validate.

Answer

  - platform: template
    sensors:
      garden_last_time:
        value_template: '{{as_timestamp(states("sensor.garden_last_activity")) | timestamp_custom("%H:%M",True)  }}'
1 Like