Hey,
so if a door/window is open (samsung smartthing multisensor) and it starts to rain… notify me and tell me which item needs to be closed.
where am i going wrong?
this doesnt fire…
- alias: Rainy Day Door and Window Alert
trigger:
platform: state
entity_id:
- binary_sensor.bar_door_sensor_contact
- binary_sensor.en_suite_window_sensor_contact
- binary_sensor.multipurpose_sensor_downstairs_bathroom_window_contact
to: "on"
condition:
- condition: state
entity_id: sensor.dark_sky_icon
state: 'rain'
action:
service: persistent_notification.create
data_template:
message: '{{ trigger.from_state.attributes.friendly_name }} is open and its raining!'
title: Its raining!
service: notify.notify
data_template:
title: Its raining!
message: '{{ trigger.from_state.attributes.friendly_name }} is open and its raining!'
First, do you want it to run the actions when a door or window is opened, or when it starts to rain? If the latter then you have the triggers and conditions reversed.
Second, are you sure sensor.dark_sky_icon is exactly ‘rain’ when it’s raining? Might it have other values when it’s raining?
Third, your actions are not entered as a proper list. You forgot the dashes.
Hey,
thanks for the reply.
first question:
i think both?
i would want to alert if it starts to rain and a door is open
but also, if its already raining and a door then opens?
i did have it reversed at first, however i then couldnt work out how to use a “conditon” value in my notify, so i knew which door opened, if it started to rain.
second.
yes, i checked and that value does go to “rain”
icon optional
A machine-readable text summary of this data point, suitable for selecting an icon for display. If defined, this property will have one of the following values:
clear-day,
clear-night,
rain,
snow,
sleet,
wind,
fog,
cloudy,
partly-cloudy-day, or
partly-cloudy-night. (Developers should ensure that a sensible default is defined, as additional values, such as
hail,
thunderstorm, or
tornado , may be defined in the future.)
third,
sorry, where should i add the dashes?
First define a group with the three sensors. This will make things a little easier later.
group:
doors_windows:
name: Doors and Windows
entities:
- binary_sensor.bar_door_sensor_contact
- binary_sensor.en_suite_window_sensor_contact
- binary_sensor.multipurpose_sensor_downstairs_bathroom_window_contact
- alias: Rainy Day Door and Window Alert
trigger:
- platform: state
entity_id:
- binary_sensor.bar_door_sensor_contact
- binary_sensor.en_suite_window_sensor_contact
- binary_sensor.multipurpose_sensor_downstairs_bathroom_window_contact
to: 'on'
- platform: state
entity_id: sensor.dark_sky_icon
to: 'rain'
condition:
- condition: state
entity_id: group.doors_windows
state: 'on'
- condition: state
entity_id: sensor.dark_sky_icon
state: 'rain'
action:
- service: persistent_notification.create
data_template:
message: >
{% set open = states.binary_sensor
|selectattr('entity_id','in',state_attr('group.doors_windows','entity_id'))
|selectattr('state','eq','on')
|map(attribute='name')|list %}
{{ list|join(', ') }} {{ 'are' if list|length > 1 else 'is' }} open and it's raining!
title: "It's raining!"
- service: notify.notify
data_template:
message: >
{% set open = states.binary_sensor
|selectattr('entity_id','in',state_attr('group.doors_windows','entity_id'))
|selectattr('state','eq','on')
|map(attribute='name')|list %}
{{ list|join(', ') }} {{ 'are' if list|length > 1 else 'is' }} open and it's raining!
title: "It's raining!"
1 Like
wow, thanks a lot!!
so its firing as expected now - awesome,
however the template to work out the door/window doesnt open.
its just “empty” in the notification.
so it reads “is open and it’s raining!”
{% set open = states.binary_sensor
|selectattr('entity_id','in',state_attr('group.doors_windows','entity_id'))
|selectattr('state','eq','on')
|map(attribute='name')|list %}
{{ list|join(', ') }} {{ 'are' if list|length > 1 else 'is' }}
this works:
{% set open =
states.binary_sensor
|selectattr
('entity_id','in',state_attr
('group.doors_windows','entity_id')
)
|selectattr
('state','eq','on')
|map
(attribute='name')
|list %}
{{ open|join(', ') }} {{ 'are' if open|length > 1 else 'is' }} open and it's raining!
D’oh! My bad. This was the problem:
{{ 'are' if list|length > 1 else 'is' }}
it should have been:
{{ 'are' if open|length > 1 else 'is' }}
as you discovered.
1 Like
no worries at all - thanks so much for the help!!
so i assume this will trigger on both:
- any door thats open WHEN it starts to rain
- any door that opens, if is ALREADY raining
Yes, that’s the idea. Let me know if you have any more issues with it.
1 Like
Thanks for all the help!!
Out of interest, do you just “know” how to code this all or is there a better way to play around and test stuff ?
I used to do a load of SQL and using SQLSquirrel really helped me to learn and get stuff done
Well, I’ve been a programmer for over 40 years, so that helps a little.
Mainly it’s reading the docs, following posts on this forum, and playing around with HA for about a year or so trying different things, and reading the HA code, too, as needed. The Template editor is a HUGE help. Also I’m never far from a command line where I can invoke a Python interpreter to try some things, too.