Hi All,
I’ve seen various discussions on time formatting etc. but I can’t align any of them to my specific use case, which I know is simple, but I can’t work out the “proper” way to do it.
The short version
In a custom sensor, what is the correct “Unit of measurement” and “Device class” to use for a string that is in HH:MM
format?
Every time I try to convert it to a timestamp I just get an “Invalid timestamp” error (when I use DEVICE_CLASS_TIMESTAMP
) and I can’t find the correct unit of measurement to use as there only seems to be TIME_HOUR
or TIME_MINUTE
nothing for TIME
on it’s own.
The background/Long version
I’m adding new functionality to the “Growatt” sensor in HASS. The sensor works by scraping information from the external growatt server online, one of the values I want to add is the last time that the server received an update from the hardware.
The value that I’m able to get from the server is the last X-axis value from a chart that gets returned and this is in the format HH:MM
.
All of the existing sensor types in the component are in this format:
"mix_import_from_grid_today": (
"Import from grid today (load)",
ENERGY_KILO_WATT_HOUR,
"etouser",
{"device_class": DEVICE_CLASS_ENERGY},
),
I’m looking to add one like this:
"mix_last_update": (
"Last Data Update",
NOT_SURE_WHAT_TO_PUT_HERE,
"lastdataupdate",
{"device_class": DEVICE_CLASS_???},
),
The only way I’ve got it to work without throwing an invalid timestamp error is to leave both fields empty and it is essentially just treated as a string. It works, but it doesn’t feel like the “right” way of doing it.
Thanks in advance.