i am trying to calculate with times. and thats Always difficult.
but i think this is not as it is supposed to be:
{{now.strftime("%Y-%m-%d %H:%M:%S")}} >> 2016-09-16 13:39:20
{{states.sensor.Vijver_repeater_7_0.last_updated}} >> 2016-09-16 10:52:54.632565+00:00
{{as_timestamp(states.sensor.some_sensor.last_updated) | timestamp_local}} >> 2016-09-16 12:52:54
okay so far everything as expected. last_updated is in UTC and must be converted.
but then:
{{(as_timestamp(now)-as_timestamp(states.sensor.some_sensor.last_updated)) | timestamp_local }} >> 1970-01-01 01:46:25
not a timedifference from 2 hours, and not a local time, but a time difference fom 1 hour??
i wrote it all out, i think 2 things go wrong.
the jinja:
timestamp local: {{as_timestamp(now.strftime("%Y-%m-%d %H:%M:%S"))}}
timestamp local: {{as_timestamp(now)}}
# timestamp utcnow gives timestamp now
utc: {{utcnow.strftime("%Y-%m-%d %H:%M:%S")}}
timestamp utc: {{as_timestamp(utcnow.strftime("%Y-%m-%d %H:%M:%S"))}}
timestamp utc: {{as_timestamp(utcnow)}}
# timestamp from last updated seems like to be converted to local time
utc sensor: {{states.sensor.some_sensor.last_updated}}
local sensor: {{as_timestamp(states.sensor.some_sensor.last_updated) | timestamp_local}}
timestamp sensor: {{as_timestamp(states.sensor.some_sensor.last_updated)}}
# local minus sensor gives the right amount of seconds
timestamp local - timestamp sensor: {{(as_timestamp(now.strftime("%Y-%m-%d %H:%M:%S"))-as_timestamp(states.sensor.some_sensor.last_updated)) }}
timestamp utc - timestamp sensor: {{(as_timestamp(utcnow.strftime("%Y-%m-%d %H:%M:%S"))-as_timestamp(states.sensor.some_sensor.last_updated)) }}
# converting the timestamp to lacol time screws it up again
local(timestamp local - timestamp sensor): {{(as_timestamp(now.strftime("%Y-%m-%d %H:%M:%S"))-as_timestamp(states.sensor.some_sensor.last_updated)) | timestamp_local }}
local(timestamp utc - timestamp sensor): {{(as_timestamp(utcnow.strftime("%Y-%m-%d %H:%M:%S"))-as_timestamp(states.sensor.some_sensor.last_updated)) | timestamp_local }}
the result:
local: 2016-09-16 14:54:49
timestamp local: 1474030489.0
timestamp local: 1474030489.097891
# timestamp utcnow gives timestamp now
utc: 2016-09-16 12:54:49
timestamp utc: 1474023289.0
timestamp utc: 1474030489.097891
# timestamp from last updated seems like to be converted to local time
utc sensor: 2016-09-16 10:52:54.632565+00:00
local sensor: 2016-09-16 12:52:54
timestamp sensor: 1474023174.632565
# local minus sensor gives the right amount of seconds
timestamp local - timestamp sensor: 7314.367434978485
timestamp utc - timestamp sensor: 114.36743497848511
# converting the timestamp to lacol time screws it up again
local(timestamp local - timestamp sensor): 1970-01-01 03:01:54
local(timestamp utc - timestamp sensor): 1970-01-01 01:01:54