how can I calculate -1H and -20M in this template?
How is that possible?
{{ as_timestamp(state_attr('sun.sun','next_setting')) |timestamp_custom('%H:%M') }}
Thank you
how can I calculate -1H and -20M in this template?
How is that possible?
{{ as_timestamp(state_attr('sun.sun','next_setting')) |timestamp_custom('%H:%M') }}
Thank you
It depends what your usage is.
Generally you can (in this case, cos you want less) deduct the number of seconds
How would that look?
What is your usage case ?
What do you want to do with it ?
As I said, it depends
Ex.:
{{as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_custom('%H:%M') }}
Output:16:14
{{ states.sensor.time.state == as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_custom('%H:%M') }}
Output:False
I want that the variable is True 1 Hour and 10 Minutes before 16:14 in this example.
Like 1 Hour and 10 Minutes before the state next_setting quals the time
So for a binary sensor state ?
So when does it go off ? Midnight is easiest but… ?
Does it need to be to the second (difficult but doable) or is the minute good enough (VERY much easier) ?
I dont want the end time to be 16:14. It should be 16:14-00:10=16:04 or something
A right answer depends on your usage for this. So what do you want to do? Just tell us, for what you do need this calculation, and someone will help. But without knowing, what you wanna do, one can’t give the right answer.
For example: I need this calculation to start my coffee machine in the morning.
I have absolutely no idea what this means
Are you trying to create a binary sensor eg an element that gives a binary state that starts 1hr 10mins before sunset and ends at (say) when a water tank reaches 50 degrees (this is not doable to the second)
So say sunset is (today) at 18:33:51 then 1hr 10mins before that is 17:23:51
But is 18:33 sufficient ?
As @paddy0174 says, if you want the coffee machine on at 17:23:51 then we can do that but it’s QUITE complicated.
(edit: This usage case would be a trigger)
But why on earth would you need such accuracy ?
1 hour and 10 minutes is 4200 seconds. Simply subtract 4200 from the timestamp, before converting it to %H:%M format.
{{ states('sensor.time') == (as_timestamp(state_attr('sun.sun','next_setting')) - 4200) | timestamp_custom('%H:%M') }}
Thank you!
You’re welcome!
You should know that it’s the custom of this community forum to mark the original post with the Solution tag, not the copy of the original post (like you’ve done).
Hey @anon36612278 are you still monitoring this thread?
Earth calling Marlon …
Its solved.