Okay this is probably gonna be super ridiculous and simple but after an hour of checking all the time conversion threads I cannot find anything showing how I can get X hours, X minutes and XX seconds from a value that is just HH:MM:SS…
More specifically it’s a glances uptime rest sensor. I have numerous templates myself that convert actual timestamps to that format but can’t seem to find one that does that conversion… also I’m not sure how it treats days I believe it will be X days, HH:MM:SS
Or if there is a way to get an actual timestamp from glances instead of what this is.
Thank you, and if it doesn’t go over 24 and shows the days on it’s own do you know how to handle that? As an example I came across of the glances uptime seems to populate the days on it’s own:
Or would it not matter because the hours won’t go over 24?
I can also check back once my sensor goes over a day tomorrow… unfortunately “lights and plugs” on every single label in my breaker panel was not the kindest thing the previous owner’s electrician could have done…
I would rather not have that part at all if it hasn’t been a day yet, as that would match the others I have
Is there like I guide you are referring to to know all this… or is it just years of experience? I was searching everywhere but maybe I should be specifying something else when looking
Paste this into the Template Editor to see how it works:
{% set d = '5 Days, 6:30:20'.split(', ') %}
{% set x = 1 if 'day' in d[0]|lower else 0 %}
{% set t = d[x].split(':') %}
{{ '{}{} hours, {} minutes, and {} seconds'.format(d[0]|lower~', ' if x == 1 else '', t[0], t[1], t[2]) }}
Replace ‘5 Days, 6:30:20’ with ‘6:30:20’ and the result will not show 0 days.
Yet again, you will need to modify the template to use your sensor’s value. What is the entity name of the sensor?
Do you know how to do that conversion? I had read in the epic time conversion thread that values like hh:mm don’t work for the normal conversions, also it will be prefixed with the number of ‘X days’ after 24 hours
Unless I just misunderstood what he was referring to
The hours value won’t exceed 24. If the elapsed time exceeds 24 hours it will indicate X Days. The challenge, for your proposed technique, is to convert this to a timestamp:
Is there a way to get it to drop the seconds after the first minute?
Putting a Lovelace page together it it seems mushed and like maybe that’s what a different friendly time I have is doing…
And you never answered, is this just from years of experience or do you have some sort of reference for some of this stuff? Is this in jinja templating docs that I could read?
Hi
Here’s the final code which is ok with uptime sensor get on Glances API
My sensor is a timestamp sensor on HA. So in the card diaply or dashbors HA manage him-self the displaying of 1 days ago, 1 hour ago,…
rest:
- scan_interval: 300 # seconds
resource: http://192.168.2.20:61208/api/3/uptime
sensor:
- name: "proxmox_uptime"
unique_id: "proxmox_uptime"
value_template: >
{% set d = value_json.split(', ') %}
{% set x = 1 if 'day' in d[0]|lower else 0 %}
{% set t = d[x].split(':') %}
{% set day = 0 if x == 0 else d[0].split(' ')[0] %}
{% set sec = (t[2] | int + ( t[1] | int * 60 ) + (( t[0] | int + 24 * day | int ) * 3600) )| int %}
{{ (now() | as_timestamp - sec) | as_datetime }}
device_class: timestamp
Note that glances Integration in HA getting uptime sensor before but for unknown reason, it disapear.
So with Glances API, we can get a lot of information on our proxmox or linux server https://glances.readthedocs.io/en/latest/api.html#get-uptime
You can get in a web GUI all the information of your glances server http://IP:61208