Next Alarm Sensor Value - 15 mins before

All,

I’m hoping this is a fairly easy one but I can’t seem to get my head round it.

I’ve got a helper value which changes based on the next alarm on my phone. What I want to do however is actually make the helper value be 15 mins before the alarm so it can turn my heating on etc.
This is the code I’ve currently got to run when ever the next alarm value changes from my phone.

service: input_datetime.set_datetime
entity_id: input_datetime.helper_value
data_template:
  datetime: >-
    {{
    as_timestamp(states('sensor.phone_next_alarm'))|timestamp_custom('%Y-%m-%d
    %H:%M:00') }} 

What do I need to change to get it to to be 15 mins before?

1 Like

as_timestamp() returns a timestamp which is a value in seconds from jan 1st 1970 UTC. So to go 15 minutes before that simply subtract 15 minutes * 60 seconds.

{{ (as_timestamp(states('sensor.phone_next_alarm')) - 15*60) |timestamp_custom('%Y-%m-%d %H:%M:00') }} 
2 Likes

That is excellent. I know it would be something simple.

Thanks very much