Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 96121

Displaying a sensor value that is a datetime/timestamp

$
0
0

@parautenbach wrote:

I’ve done something that I’m not sure is the best way to go about it, even though it works. I’d be keen to hear if there is a better way to approach this.

I have a camera (Raspberry PI NOIR, but it’s not important) with a live feed in Lovelace. I have an automation that takes snapshots when motion is detected. To display the latest snapshot, I’ve set up a local file camera. This all works just fine.

I also want to display the datetime of the last snapshot. When I take the snapshot, I also write a UNIX timestamp (long int) to a text file. I read this value using a file sensor. I convert this value to a datetime using the template "{{ value | int | timestamp_local }}".

It doesn’t seem a camera using the local file platform has a last_changed or last_updated attribute, otherwise, I would’ve used it. I also couldn’t find a neat way to get the image file’s metadata (thinking about it now, I could probably use a shell script, but I’d still roughly end up in the same position).

The reason I think this is perhaps too hacky is that I don’t think sensors were intended to use with datetime’s, but rather ints and floats (even though my value is a long int timestamp).

Is there a better way to achieve this?

PS: During this, I also experimented with the relative_time function in the template, but it doesn’t seem to accept the datetime returned by strptime. I didn’t dig into the Python code to figure out why but did see some older and similar issues reported. I’m not sure whether this is a known issue. Happy to provide more info if someone wants to know more.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 96121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>