I need help with a automation. I am Smarthings Hub owner and recently started playing with HASS using MQTT to setup all my devices. It work great and I like that the automation is local. So now the task is to move my automation to that is on Smartthings to HASS. I am having trouble with one particular one that alerts me if anyone of my outside doors is left open.
If any one of doors.group = open/on
then
alert after 10 minutes.
else cancel alert
I am struggling wiht doing one automation that handles all doors or do each automation for each door in a separately.
alias: 'Notify if any doors left open for 10 minutes'
trigger:
platform: state
entity_id:
- sensor.front_door
- sensor.back_door
- sensor.garage_side_door
- sensor.garage_overhead_door
state: 'on'
for:
minutes: 10
action:
service: notify.notify
data_template:
message: >
The {{ trigger.to_state.attributes.friendly_name }} was left open
No need to cancel this alert as the message won’t be sent unless the door was open for the full 10 minutes. If it closes before 10 minutes, the action will never run
You can use hours, minutes or seconds in this scenario, by themselves, or as a combination:
for:
hours: 1
minutes: 10
seconds: 5
action:
service: notify.notify
data_template:
message: >
The {{ trigger.to_state.attributes.friendly_name }} was left open for 1 hour, 10 minutes and 5 seconds
“State:” was deprecated and removed in v. 0.50, so you need to change one line of this to make it work. Rather than “state: ‘on’” use “to: ‘on’” and all is good!
Hi all, I have this working using this code (thanks jbardi):
- action:
- data_template:
message: >
The {{ trigger.to_state.attributes.friendly_name }} was left open
title: Door left open
service: notify.home_assistant_alert
alias: Door left open
condition: []
id: '1518041349912'
trigger:
- entity_id:
- sensor.bed_door
- sensor.door_2
from: closed
platform: state
to: open
for:
minutes: 2
It works well for each door individually or if both doors are left open. However if both doors are opened and only one is closed (before 2 mins) you do not get any alerts after the 2 mins ends.
I have the same automation setup and the same issue (if I close one door/window after I open the initially opened one, it resets the automation and it won’t notify anymore).
Ok. Add this binary_sensor code to configuration.yaml. Replace ‘sensor.one_open_closed’ with your door sensor and ‘open’ with state of your sensor when door is open. Important part is delay_on: Change seconds to minutes: 30 if you want to be notified after 30 minutes. Yes, you can replace persistent_notification with notify.pushover.
So now I just have to pile all my door / window sensors under binary_sensor one by one?
Since I have 15 sensors, is there any way to group them, to keep configuration.yaml clean?
Also, I have all of them in customize.yaml and they have friendly names defined etc., do I still have to state friendly_name for each (or is this now a separate thing)?
Yup. Add them all in binary sensor. You can skip friendly_name if have them customized already. Only way to keep configuration.yaml clean is to split configuration.
I’m doing it a bit different, and I can’t figure out if this really helps you or not, but it works well for me! (Note: huge shoutout to @Petro, who posted the template for this in another thread)
Right now I have 3 window sensors in my house.
They are put in a group together (group.yaml), like this:
all_windows:
view: no
entities:
- binary_sensor.sovevaerelsevindue
- binary_sensor.badvindue
- binary_sensor.georgvindue
Then I have a few automations:
The first one gives me a notification on Slack, when a window has been open for 20 mins.
In automations.yaml:
- alias: Window has been open for 20 mins
initial_state: True
hide_entity: False
trigger:
- platform: state
entity_id: binary_sensor.sovevaerelsevindue
to: 'on'
for:
minutes: 20
- platform: state
entity_id: binary_sensor.badvindue
to: 'on'
for:
minutes: 20
- platform: state
entity_id: binary_sensor.georgvindue
to: 'on'
for:
minutes: 20
action:
- service: notify.slack
data_template:
title: "Open windows"
message: >
{% set open_windows = states | selectattr('entity_id', 'in', state_attr('group.all_windows','entity_id')) | selectattr('state','in',['on','open']) | map(attribute='name') | list %}
{% if open_windows | length == 1 %}
The window: "{{ trigger.from_state.attributes.friendly_name }}" has been open for 20 mins.
{% else %}
The window: "{{ trigger.from_state.attributes.friendly_name }}" has been open for 20 mins. Currently open windows: {{ open_windows[:-1] | join(', ') }}{{',' if open_windows | length > 2 else ''}} and {{ open_windows[-1]}}.
{% endif %}
and one that notifies me when a window is closed:
- alias: Window has been closed
initial_state: True
hide_entity: False
trigger:
- platform: state
entity_id: binary_sensor.sovevaerelsevindue
to: 'off'
for:
seconds: 2
- platform: state
entity_id: binary_sensor.badvindue
to: 'off'
for:
seconds: 2
- platform: state
entity_id: binary_sensor.georgvindue
to: 'off'
for:
seconds: 2
action:
- service: notify.slack
data_template:
title: "Open windows"
message: >
{% set open_windows = states | selectattr('entity_id', 'in', state_attr('group.all_windows','entity_id')) | selectattr('state','in',['on','open']) | map(attribute='name') | list %}
{% if open_windows | length == 0 %}
All windows are closed.
{% else %}
The window "{{ trigger.from_state.attributes.friendly_name }}" has been closed. Currently open windows: {{ open_windows[:-1] | join(', ') }}{{', ' if open_windows | length > 2}}{{ open_windows[-1]}}.
{% endif %}
@cklit Thanks, I think your version still just notifies you once, right. But I found my solution anyway and updated my post to say I found the alert component. This component works really well and keeps notifying you until you either acknowledge or fix the condition causing the alert. It’s exactly what I was looking for.