I would like to write an automation that reminds me when our windows are open for too long. The duration until the windows are closed should depend on the outside temperature. I have put together the following status template “open_for_x_min”:
{% set t = states('sensor.openweathermap_temperature') | float(0) %}
{% if t <= 0 %}
5
{% elif t > 0 and t <= 10 %}
10
{% else %}
15
{% endif %}
The notification should come when the windows have been open for 5, 10 or 15 minutes.
I have tried it once with an automation:
alias: window-open
description: window is open
trigger:
- type: opened
platform: device
device_id: xxx
entity_id: xxxx
domain: binary_sensor
for:
hours: 0
minutes: 0
seconds: 0
condition: []
action:
- delay: 00:{{ states('sensor.open_for_x_min') }}
- action: notify.pushover
metadata: {}
data:
message: close window!
title: Office
mode: single
This works so far, but the message appears even if the window has already been closed again.
The solution seems to be the confirmation function with a status query:
condition: state
entity_id: binary_sensor.windowsensorXY
attribute: value_state
state: Open
for:
hours: 0
minutes: 10
seconds: 0
However, I can’t get my variable {{ states(‘sensor.open_for_x_min’) }} that works for the delay above into the state query.
When I insert it:
alias: window-open
description: window is open
trigger:
- type: opened
platform: device
device_id: xxx
entity_id: xxxx
domain: binary_sensor
for:
hours: 0
minutes: 0
seconds: 0
condition:
- condition: state
entity_id: binary_sensor.hm_sec_sco_oeq0222795
attribute: value_state
state: Open
for:
hours: 0
minutes: {{ states('sensor.open_for_x_min') }}
seconds: 0
action:
- action: notify.pushover
metadata: {}
data:
message: close window!
title: Office
mode: single
I get the error:
Message malformed: expected float for dictionary value @ data['condition'][0]['for']['minutes']
After the error message, my variable in YAML is changed to:
condition: state
entity_id: binary_sensor.hm_sec_sco_oeq0222795
attribute: value_state
state: Open
for:
hours: 0
minutes:
"[object Object]": null
seconds: 0
Do you know what I need to change? Or do you have a completely different way?