Multiple notifications - device tracker

As long as no two automations trigger and try to run the same script at the same time. Don’t know how likely that is in your case, but I can tell you after many years of embedding programming, if it can happen, it will happen. :slight_smile: But seriously, you’re probably pretty safe I’m guessin’.

You are right, it could happen, but it s really unlikely. I’m ok with that.

I’d like to add that there are some ' signs missing in the above shown examples. This might be important for others.

So in the script, ir should look like this

is_home_notify_user1:
  sequence:
    - condition: template
      value_template: "{{ is_state('device_tracker.user1', 'home') }}"
    - service_template: notify.user1
      data_template:
        message: "{{ message }}"

instead of this
value_template: "{{ is_state(device_tracker.user1, 'home') }}"

I will edit this in my examples above.

You may have missed it, but you don’t need to use service_template here. The service is not being specified by a template, so by using service_template you’re just making it less efficient. Not a huge issue, but no reason not to change it to just service. data_template, however, is needed here, since message is specified via a template.

1 Like

Ok, so I used this for a long time:

is_home_notify:
  sequence:
    - condition: state
      entity_id: person.XXX
      state: 'home'
    - service_template: "{{ notify }}"
      data_template:
        message: "{{ message }}"

and it works fine. Now I read about that new functionality with replacing notifications and I’d like to add that to the script. I was able to add it to the script but with that code included I can’t use the script without “replacing notifications” any more.

So what I tried is this:

script:

is_home_notify:
  sequence:
    - condition: state
      entity_id: person.XXX
      state: 'home'        
    - service: notify.ios_XXX
      data_template:
        message: "{{ message }}"
        data:
          push:
            category: "{{ category }}"  
          apns_headers:
            'apns-collapse-id': "{{ collapse_id }}"

in automation:
this works:

    - service: script.is_home_notify_XXX
      data:
        message: "some message"
        category: "some category" 
        collapse_id: somecollapseid

but this won’t work any more:

    - service: script.is_home_notify_XXX
      data:
        message: "some message"
        category: "some category" 

because it seems like it needs the collapse id.

I also tried this, but this won’t work in any case:

          apns_headers:
            "{{collapse_id}}"
        collapse_id: "'apns-collapse-id': 'collapse_gang'"`

Is it possible to integrate it somehow or do I have to use a separate script for that?

@petro could you help with this?

separate script

ok thank you