Conditional Pushbullet notifications

So I have many automations that send notifications to my wife and myself using pushbullet

here is an example

  - service: notify.pushbullet_notifications
    data_template:
      target:
      - !secret pauls_secret_email
      - !secret tracys_secret_email
      title: Zigbee Devices Offline
      message: message here

Sometimes I would like to be able to turn off notifications for one person or the other, but just for a while. I do have a input boolean for each person named “enable_notifications_paul” , etc. Was wondering if anyone had a recommendation on a conditional template for the “target:” based on that?

I have this from a different automation

condition: "{{ is_state('input_boolean.notify_paul','on') }}"

and also

condition: "{{ is_state('input_boolean.notify_tracy','on') }}"

Could I do a template within a template for the target: based on these?

Just trying to wrap my head aroind the template within a template

Does this look like it would work? I’ll test out later tonight,but was looking for a warm fuzzy. :slight_smile:

  - service: notify.pushbullet_notifications
    data_template:
      target: >
        {% if states('input_boolean.notify_paul') == 'on' and states('input_boolean.notify_tracy') == 'on' %}
           - !secret pauls_secret_email
           - !secret tracys_secret_email
        {% elif states('input_boolean.notify_paul') == 'on' and states('input_boolean.notify_tracy') == 'off' %}
           - !secret pauls_secret_email
        {% elif states('input_boolean.notify_paul') == 'off' and states('input_boolean.notify_tracy') == 'on' %}
           - !secret tracys_secret_email
        {% else %}
           - noone
        {% endif %}
      title: Zigbee Devices Offline
      message: message here

Try something like this:

  - service: notify.pushbullet_notifications
    data_template:
      target: >
        {% if states('input_boolean.notify_paul') == 'on' %}
           - !secret pauls_secret_email
        {% elif states('input_boolean.notify_tracy') == 'on' %}
           - !secret tracys_secret_email
        {% endif %}
      title: Zigbee Devices Offline
      message: message here

To simplify.

If they both had the input boolean turned on, would both receive the message? If so, that looks perfect

That’s the theory.

1 Like

Great, thanks. I’ll try it out tonight and report back as the solution or not.

In your example tracy will never receive an email when paul does. Although i’m not so good at the templates i guess something like this would work, but i’m not sure what happens when there are no targets defined:

- service: notify.pushbullet_notifications
    data_template:
      target: >
        {% if states('input_boolean.notify_paul') == 'on' %}
           - !secret pauls_secret_email
        {% endif %}
        {% if states('input_boolean.notify_tracy') == 'on' %}
           - !secret tracys_secret_email
        {% endif %}
      title: Zigbee Devices Offline
      message: message here
1 Like

Ah you’re right, I just threw something together quickly to trim down the ifs for him.

Thanks for the correction.

2 Likes

Only issue I have is that it’s not formatting correctly for some reason.

In the template editor it ends up like this

- !secret pauls_secret_email
        
        
         - !secret tracys_secret_email

But even this shows up the same way

        {% if states('input_boolean.notify_paul') == 'on' and states('input_boolean.notify_tracy') == 'on' %}
           - !secret pauls_secret_email
           - !secret tracys_secret_email

Edit: I should have stated, this is not working because of the formatting. Not sure how to get it to format correctly

Edit2: This is the error I see in my logs with the current formatting issue

Invalid target syntax: - !secret pauls_secret_email

 

 - !secret tracys_secret_email

edit 3:

gave up for the moment. I’ll come back to it later.

Was trying to end up with this

  action:
  - service: notify.pushbullet_notifications
    data_template:
      target:
      - !secret pauls_secret_email
      - !secret tracys_secret_email
      title: Doors left unlocked
      message: message

Just could not get the - !secret… to work

Edit 4: 12-22
still no go. Tried this most recently

  - service: notify.pushbullet_notifications
    data_template: >
     {% if states('input_boolean.notify_paul') == 'on' and states('input_boolean.notify_tracy') == 'on' %}
      target: 
      - !secret pauls_secret_email
      - !secret tracys_secret_email
     {% elif states('input_boolean.notify_paul') == 'on' and states('input_boolean.notify_tracy') == 'off' %}
      target: 
      - !secret pauls_secret_email
     {% elif states('input_boolean.notify_paul') == 'off' and states('input_boolean.notify_tracy') == 'on' %}
      target: 
      - !secret tracys_secret_email
     {% else %}
      target: 
      - noone
     {% endif %}
      title: "Goodbye Routine has ran"
      message: "All lights have been turned off. Garage door has closed and locks have been locked"