Hi all,
this is my first post, so please be gentle with me, especially if I did not post everything right :).
My usecase is as follows:
I want my home assistant to measure the outdoor temperature deviation from a defined “comfort zone”, wind and precipitation and determine a time value when it should warn me to close open windows.
The part with the template sensor is done for that purpose.
For example the sensor (screenshot below) will 60 minutes warning when the temperature is in the comfort zone, but 5 minutes, if we have freezing outdoor temperaturs.
Even if the temperature is in the comfort zone, if rain sets in, time will decrease, exponentially so if wind is above 10 kph.
The resulting value is a float minute value.
Now, all that was left is to hook the template sensor into the automation. That is where I fail. I tried to define automation variables first, then refer to them in the state triggers and delay commands, but somehow I fail again and again.
I tried to implement this by using deltatime string (like … for: "{{triggertime}}"
, or like in the example below, via numberic values.
Did I miss something obvious? Or is it simply not possible to hook templates to trigger state periods?
Script excerpt below:…
alias: Window Warning
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.aussen_bad
to: "on"
for:
minutes: |
{{ triggertime }}
id: BadOpenTooLong
[...]
action:
- choose:
- conditions:
- condition: trigger
id: BadOpenTooLong
sequence:
- repeat:
until:
- condition: state
entity_id: binary_sensor.aussen_bad
state: "off"
sequence:
- if:
- condition: state
entity_id: person.xxx
state: home
then:
- service: notify.mobile_app_xxx
data:
title: ACHTUNG!
message: >-
{{ trigger.from_state.attributes.friendly_name }}
schließen!
enabled: true
- service: notify.mobile_app_xxx
data:
message: >-
{{ trigger.from_state.attributes.friendly_name }}
schließen!
title: ACHTUNG!
- parallel:
- service: tts.google_translate_say
data:
cache: true
entity_id: media_player.xxx
message: >-
{{trigger.from_state.attributes.friendly_name }}
schließen!
language: de
enabled: true
- service: tts.google_translate_say
data:
cache: true
entity_id: media_player.xxx
message: >-
{{trigger.from_state.attributes.friendly_name }}
schließen!
language: de
enabled: true
- delay:
minutes: >
'{{ repeattime }}'
mode: parallel
max: 10
variables:
triggertime: >
'{{ states("sensor.zeitgeber_warnung_fenster_offen_2") | float }}'
repeattime: >
'{{ states("sensor.zeitgeber_warnung_fenster_offen_2") / 2 | float }}'
Thanks
Martin