Issues with Template sensor and unknown value

Hi All,

I’ve setup a binary sensor that triggers 10 minutes before the first alarm goes off (my wife or myself depending who needs to get up earlier) and toggles on. I use this for automations like kicking on the furnace and coffee maker before we’re awoken by and alarm.

The issue I have is when one alarm is not set, the value of the next alarm sensor is “unavailable” which breaks the template, and therefore the automations. How do I make better able to handle this senario?

{{ ['sensor.pixel_5_next_alarm_2', 'sensor.sm_f936w_next_alarm']
  | map('states') | map('as_timestamp')
  | min - 600 < now().timestamp() }}

Thank you!

Give this a try

{{ ['sensor.pixel_5_next_alarm_2', 'sensor.sm_f936w_next_alarm']
  | map('states') | reject( 'in', ['unavailable','unknown']) | map('as_timestamp')
  | min - 600 < now().timestamp() }}
1 Like

That did the trick. Thanks very much!