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:



And .sonos_alarm_1043


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


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)