Nested condition/service_template?

HI.

Im using this notification process now:

condition:
  - condition: template
    value_template: >
      {{ is_state('input_boolean.notify_presence', 'on')}}
action:
  - service: notify.notify
    data:
      message: W arrived home
  - condition: template
    value_template: >
      {{ is_state('input_boolean.notify_announcement', 'on')}}
  - service: notify.ios_phone
    data_template:
      title: 'Arrival notification'
      message: 'W entered home' #{{ trigger.zone.attributes.friendly_name }}
      data:
        push:
          sound: 'US-EN-Morgan-Freeman-Wife-Is-Arriving.wav'

Im searching for a way to have the last input_boolean.notify_announcement condition decide whether a regular notify.notify, or a notify.ios_phone is sent.

No need for a regular notify.notify when the notify iOS also sends a notification, next to playing a sound file. Ive tried to ditch the visible notification from the sound file, but dont know if thats even possible. It seems it always displays a title at least? or can I use only:

  - service: notify.ios_phone
    data:
      data:
        push:
          sound: 'US-EN-Morgan-Freeman-Wife-Is-Arriving.wav'

So, im trying to do this:

condition 1: if input_boolean.notify_presence == 'on', check if input_boolean.notify_announcement == 'on': if yes send notify.ios, if not, send notify.notify.

Hope this makes sense…

Thx,
Marius

you need to make your input_boolean.notify_announcement handle that. You’d need to use a an event trigger

yes, but im not sure how. I could of course make 2 automations, one for regular notification, and one for announcement notification. Then, if both would be on, have a template check for the state of that input_boolean to action or not.

so in notification automation use the check for
{{ is_state('input_boolean.notify_announcement', 'off') }} and if true action notify.notify. If false, let the announcement run.

But, As I try to do that in one automation now, that wont work, unless I could nest that somehow.

using 2 little scripts makes it easier, and maybe clearer what I am looking for.

  - condition: template
    value_template: >
      {{ is_state('input_boolean.notify_presence', 'on')}}
 action:
  service_template: >
    {% if is_state('input_boolean.notify_announcement', 'on')%} script.speech
    {% else%} script.notify
    {%endif%}



script.speech:
  sequence:
    service: notify.ios_phone
    data_template:
      title: 'Arrival notification'
      message: 'W entered home' #{{ trigger.zone.attributes.friendly_name }}
      data:
        push:
          sound: 'US-EN-Morgan-Freeman-Wife-Is-Arriving.wav'

script.notify:
  sequence:
    service: notify.notify
    data:
      message: W arrived home

for complexer automations id need the variable to use the triggers and pass them along to the scripts. Better still to try it in 1 automation …

I would make the message part of each script a variable. Then you can use the same two scripts everywhere.

You could also make a third script that looks at the input boolean and calls the correct notify script based on the state of that boolean. Then all of your notifications could just call the same script and that script would do all the heavy lifting, passing the work off to the final script which actually notifies.

1 Like