put this in the template editor
{{ states | selectattr('entity_id', 'in', state_attr('group.doors','entity_id')) | selectattr('state','in',['on','open']) | list }}
and show the output
put this in the template editor
{{ states | selectattr('entity_id', 'in', state_attr('group.doors','entity_id')) | selectattr('state','in',['on','open']) | list }}
and show the output
What about this. (Sorry just trying to piece together the story)
{{ states | selectattr('entity_id', 'in', state_attr('group.doors','entity_id')) | list }}
I don’t see anything wrong with the template then, Not sure what to tell you. Based on all the information you’ve provided, both should be triggering.
Woww… for some reason it wasnt treating my comment line as a comment in the condition. When i removed that line and it worked now?
oh yeah, that makes some sense. Jinja comments need to be
{# blah #}
I used Petro’s nice code as a script, got it to work & notify me once, but then in testing more everytime I execute the script it bans the IP of my router. Any suggestions on why this occurs and how to prevent it?
what do you mean ‘it bans the ip of my router’? What is ‘it’?
So weird, it was happening last night. Would run the script once, worked, 2nd time the ip_ban_enabled would ban my router’s IP. Luckily had samba available and deleted my IP from the ip_bans.yaml. I tried now and no issues. Only change I did was restore config to a new SD card.
I managed to use your wonderful script to make three separate scripts to check doors, windows and locks, notify me in app and via Alexa if any are open. Such a wonderful script, thank you! Now to learn from it and see if I can make it check and say ‘all doors & windows closed & everything locked’.
I am having a problem with this automation.
I can get this to work if I click in the automation dashboard Run Actions.
I want it to run at 8 PM, but it does not work. There is no entry in the logs that refer to this.
I have about 10 automations (feed the dog, take medication, etc,) that use a similar setup.
What do I have coded incorrectly, or what can I check.
####################################################
# WINDOW OPEN STATUS 2021Apr02 #
####################################################
#https://community.home-assistant.io/t/automation-that-checks-for-is-doors-are-open-before-going-to-bed/59456/7
- id: "1793401787732"
alias: "8 pm Window Check"
description: 8 pm Window Check
trigger:
- at: "20:00:00"
platform: time
condition:
condition: template
value_template: >
# this counts the windows that are open and if we have any that are open, the notify will occur
{{ states | selectattr('entity_id', 'in', state_attr('group.windows','entity_id')) | selectattr('state','in',['on','open']) | list | length >= 1 }}
action:
- service: media_player.volume_set
data:
volume_level: 0.8
entity_id: media_player.everywhere
- data:
entity_id: group.echo
media_content_id: amzn_sfx_trumpet_bugle_04
media_content_type: sound
service: media_player.play_media
- data:
data:
method: speak
type: announce
message: >
{% set open_windows = ( states | selectattr('entity_id', 'in', state_attr('group.windows','entity_id')) | selectattr('state','in',['on','open']) | list | map(attribute='name') | join(', ') ) %}
It is 8 pm and the following windows are open: {{ open_windows }}
service: notify.alexa_media_everywhere
- service: notify.telegram_carlton
data_template:
title: "It's 8 PM Windows Open!"
message: >
{% set open_windows = ( states | selectattr('entity_id', 'in', state_attr('group.windows','entity_id')) | selectattr('state','in',['on','open']) | list | map(attribute='name') | join(', ') ) %}
The following windows are open: {{ open_windows }}
mode: single
Thanks
I assume that there actually are windows open at 8pm?
other than that it looks OK.
You can trigger the automation from the services tab and in there there is a check box that you need to use to not ignore the conditions. that way you can tell if the condition or the trigger is the problem.
But TBH if the actions run when you run it manually then it has to be in the conditions since the trigger is pretty basic.
Solved, after reading all the post many times I finally figured out that the automation can not have a (#) commented line.
This is what I had
condition:
condition: template
value_template: >
# this counts the windows that are open and if we have any that are open, the notify will occur
{{ states | selectattr('entity_id', 'in', state_attr('group.windows','entity_id')) | selectattr('state','in',['on','open']) | list | length >= 1 }}
This is what I change it to
condition: template
value_template: >
{{ states | selectattr('entity_id', 'in', state_attr('group.windows','entity_id')) | selectattr('state','in',['on','open']) | list | length >= 1 }}
It now works as expected.
Thank you for the help.
I completely missed that.
You actually can have comments but you need to have them moved to the left so they aren’t part of the template.
And I think you can have comments in the template itself if you use {#…#} around the comment.
I’ve never tried it but I’m pretty sure it’s valid jinja.
Wondering how to set the trigger to be ‘any door/window in a group’ and when binary_sensor.goodnight = on or something like that. That way, when a door/window opens while we are asleep, we can get verbal notice.
When i was first getting started and wanted to get notified every X minutes if my coffee pot was on @dale3h pointed me to Alert great for watching the state of things. There are probably things in here borrowed from @skalavala and @CCOSTAN.
To give more flexibility when an alert fires the syslog notifier is used.
An automation is triggered on the syslog event and the condition uses the message contents.
FULL Disclosure - None of this code has been run since my house was put up for sale July of 2020 and the IoT stuff was removed.
Assuming I can do this with Alexa, right? I’d also like to just make a notification alert to just send to my phone. This is great!
You can put all of your doors and windows that you want to monitor into a group.
Then, when at least one of those windows will be open, the group binary will switch to one.
I did that myself and it works perfectly.
Actually I created 3 groups:
Hi, just newbie to Home assistant and switched from Fibaro to HA. I also wanted to use the Door Check but i get every time an error:
“Error rendering data template: TypeError: argument of type ‘NoneType’ is not iterable”.
I tried to find out about a week but without any luck. Perhaps someone with knowledge could take a look to my code an could give me a some help:
alias: check all doors at 10PM
description: ''
trigger:
- platform: state
entity_id: light.kueche_kueche_licht_188
from: 'off'
to: 'on'
condition:
- condition: template
value_template: >
{{ states | selectattr('entity_id', 'in',
state_attr('group.tueren_alle','entity_id')) |
selectattr('state','in',['on','open']) | list | length >= 1 }}
action:
- service: notify.mobile_app_sebastian_s21
data_template:
title: Türen geöffnet!
message: >
{% set open_doors = states | selectattr('entity_id', 'in',
state_attr('group.tueren_alle','entity_id')) |
selectattr('state','in',['on','open']) | map(attribute='name') | list %}
{% if open_doors | length == 1 %} The {{ open_doors[0] }} door is open.
{% else %} The {{ open_doors[:-1] | join(' door, ') }}{{' door,' if
open_doors | length > 2 else ' door'}} and {{ open_doors[-1]}} door are
open. {% endif %}
Are you sure of your group ? Did you try to load your template in http://HA:8123/developer-tools/template ? Did you restarted HA ?