I would like to setup the following notifications:
Send repeated messages every 30 min if doors or windows are open after sundown.
Send repeated messages every 30 min if doors or windows are open and the forecast calls for rain.
Should I use Automation or Alert? My understanding is the Automation will be triggered once each time the conditions are met, but Alerts will send out repeat notification after one trigger. What I cannot find are examples of using conditions within Alerts.
I have never used the alert component, but to me it looks like the second example from the documentation is what you need.
So you create a template binary sensor which evaluates the states of the doors, windows, sun etc., and based on that sensor fire the alert.
@danielperna84
Thanks for the pointer. I think binary sensor will be able to solve this problem. But after a night of fighting with HA I could NOT get the senor working. Hopefully someone can point out where I went wrong with the code.
binary_sensor:
- platform: template
sensors:
sun_up:
value_template: '{{ states.sun.sun.attributes.elevation > 0 }}'
friendly_name: 'Sun Is Up'
entity_id:
- sun.sun
window_open_at_night:
value_template: >-
{%- if states.binary_sensor.sun_up.state == 'off'
and states.binary_sensor.windows.state == 'on' -%}
on
{%- else -%}
off
{%- endif -%}
friendly_name: 'Window(s) Is Open At Night'
device_class: opening
entity_id:
- binary_sensor.sun_up
- binary_sensor.windows
I get two new binary sensors from the above, but only the state for sun_up changes. window_open_at_night state never changes even when the if condition is false. What is wrong here?
I was following template guide which has “Off” and “On” in the last example. I left the expressions in for now, but will keep that in mind for the future.
@ih8gates,
You are correct. The template is expecting true/false to be returned. Will try to do a pull request and update the binary_sensor documentation.