Template sensor time format

I have a sensor with time format configured as:
{%set a=as_timestamp(sensor.my_sensor)| timestamp_custom(' %H') %}

I would like to use this sensor value in an automation trigger without success. My automation should trigger when the the time is the same as my_sensor. I have tried both to use tie as trigger but also template. I’m happy for any tips.

if the timestamp_custom returns a valid hour value then this should work:

{%set a=as_timestamp(states('sensor.my_sensor'))| timestamp_custom('%H') %}
{{ now()).hour == a }}

Thanks’! I will give it a try right now!

Should probably be:

as_timestamp(states("sensor.my_sensor"))

yeah your right.

I meant to correct that and forgot.

fixed my post

Thanks!

Thanks both your help. Unfortunately there is still some issue. Here is my template sensor code and the code for automation.

cheapest_price_1_start:
        value_template: >- 
           {% set prices=states.sensor.nordpool_kwh_se3_sek_3_095_025.attributes.raw_today + 
           states.sensor.nordpool_kwh_se3_sek_3_095_025.attributes.raw_tomorrow  -%}
           {%set list = namespace(prices=[]) -%}
           {% for price in prices -%}
           {%- if price.end > now() -%}{% set list.prices = list.prices + [price] -%}{%- endif -%}
           {% endfor -%}
           {% set cheapest = list.prices | sort(attribute='value') -%}
           {{as_timestamp(cheapest[0].start) }}

- alias: Elpanna
  description: ''”
  mode: single
  trigger:
    - platform: template
      value_template: >-
        {%set a=as_timestamp('sensor.cheapest_price_1_start')| timestamp_custom('%H') %}
        {{ now().hour == a }}
  condition: []
  action:
    - service: notify.mobile_app_anders_12a
      data:
        message: Test
        title: Test

Oops, the description question mark shouldn’t be there.