dir
August 19, 2022, 6:00pm
1
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.
finity
August 19, 2022, 6:42pm
2
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 }}
dir
August 19, 2022, 6:54pm
3
Thanks’! I will give it a try right now!
Hellis81
(Hellis81)
August 19, 2022, 7:00pm
4
Should probably be:
as_timestamp(states("sensor.my_sensor"))
finity
August 19, 2022, 7:45pm
5
yeah your right.
I meant to correct that and forgot.
fixed my post
Thanks!
dir
August 20, 2022, 6:43am
6
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
dir
August 20, 2022, 6:45am
7
Oops, the description question mark shouldn’t be there.