I use notifications in a lot of my automations. But sometimes the notifications get annoying. While you can use a condition statement, it’s a hassle. So I created a script that accepts a message and a boolean value so you can easily turn notifications on/off from the GUI. I hope you find it useful!
In this automation, I want to send a message anytime mysensor turns off. I also have input_boolean.mysensor_notifications
which appears as a slider in my UI. Turning it on/off from the GUI allows me to get notifications, or get some peace and quiet.
The action calls script.conditional_notify
which expects a boolean value (in this case the input_boolean mentioned above) and a title
and message
. The action is always called, and puts the burden of checking the input_boolean on the script.
- alias: MySensor Turns Off
trigger:
entity_id: binary_sensor.mysensor
platform: state
to: 'off'
action:
- service: script.conditional_notify
data_template:
boolean: input_boolean.mysensor_notifications
title: "Front Door"
message: "Closed"
And here is the script:
conditional_notify:
sequence:
- condition: template
value_template: "{{(states(boolean) == 'on')}}"
- service: notify.notify
data_template:
title: "{{title}}"
message: "{{message}}"
You’ll notice it is very simple. It checks the value of the boolean, and if true it calls the notify service. In this case I’m using it to send messages to my iOS devices. But you can easily change it to whatever notifcation service you like. I like this because if I decide to change services, I only have to do it in one place.