Match timestamp from time sensor and Sonos Alarm time

Hi Forum,

Im searching for at solution to fix the following template equation:

{{ states('sensor.time') == (state_attr('switch.sonos_alarm_1043', 'time')) }}

Which at the moment gives the result “False” , even at the time where the sensor.time should match the Sonos Alarm time.

I’m guessing that it’s caused by the timestamp where:

sensor.time

hh:mm

And .sonos_alarm_1043

hh:mm:ss

So how do I change the timestamp on one of them to get the equation to true.

Thanks

The simple fix would be:

{{ states('sensor.time') == state_attr('switch.sonos_alarm_1043', 'time')[0:5] }}

To only get the first five characters.

Another way is to use as_timestamp(state) == as_timestamp(state)