Please add access to as_timestamp() function from python_script component

It is very useful for automation to be able to calculate time from the last event. Of cause, I can write something like this function myself. But I would very much prefer if it will be access to the native function. Can prevent bugs.

datetime objects have a timestamp() method.

This python_script gets the timestamp of the current time, two different ways, and prints the two results to the log using logger.warning.

n =
ts1 = n.timestamp()

ts2 =
logger.warning('Timestamp1: {}, Timestamp2: {}'.format(ts1, ts2))

Here’s the result:

If you need to find the difference between two times, you can use timedelta.

Thanks. But the problem is I need to calculate time passed from last state change. And I need as_timestamp() to convert last_updated property of a state.

And BTW. I am trying to find maximum value of a list, but getting error when calling max(list_name) So hom can i get maximum?

Sorry, I don’t know why max and list functions aren’t available. I guess you’ll have to create your own functions to perform the two operations.