So like many people here I get all sorts of useful notificiations, Mostly via pushbullet, but a few via SMTP as well. I’m actually moving more and more to SMTP. Anyway, sometimes I’d like to turn off notifications for a while, maybe for a day, maybe just for the afternoon. Not on any specific schedule. I know I can turn off the automation, but I have several. Also, some noticiations go to multiple people, so maybe I dont want them, but my wife does.
I thought about making an input boolean called “Notification On/Off” and adding that as a condition, but just for the notification, not the whole automation. Since other things may still need to happen.
Has anyone done anything like this? Or have any recommendations on the best way to do this?
Your best option is to create a script that handles notifications. The script should except 2 inputs, title and message. Add a conditional check in the script that checks the input_boolean. Here’s an example:
Well, you’d have to make a unique script for each combination of attributes you are passing to the script. So if the image always changes, you’d need one that supplies title, message, and image. Also, you’d have to reformat some of your code in the actions to be at the same level instead of indented.
data:
title:
message:
data:
images:
- img
to
data_template:
title:
message:
image:
and your script would have everything with the correct indents:
I tried to pass the service type as a variable, thought that way I could use one script for multiple notification types (or people). But to do so would require me to be able to change the notify and the boolean.
I played around with templates that were valid, but could not figure out how to send to script
like
{% set notifier = 'input_boolean.notify_' + user %}
"{{ is_state(notifier,'on') }}"
Probably a simplier question would be can I send the same data to two different scripts (well 95% the same, just differnent input boolean condtions and different notifiers
I found that I could use one script and just not include image: in the automation, it sends fine. Just leaves a message in the log about attachment not found. Maybe it’s the service I’m using (SMTP/GMAIL), but it works. Very nice. thanks for the recommendations
Works perfect. Thanks Again, took several scripts down to one, and so much simpler. In my example I did not include an image, this still works for me using smtp and gmail
I want to pass the actual logical operator true or false. i.e the word true to represent the logical condition True and the word false to represent the logical condition False
Do I need to I enclose it in quotes? I’m pretty sure that for strings it doesn’t matter and in fact it is my understanding that the true and false will also be passed as strings anyway but will be interpreted as logical operators???
That should work. The yaml interpreter should turn that into a boolean. Needs to be capital T, don’t use quotes because then the interpreter might assign it as a string.
the receiving script then passes on the boolean again so in this example does the debug: have quotes or not (I’m guessing not but being a template I am not sure).