Problem with mikrotik device_tracker

Hello everyone.
Today i update home assistant to 98.5 version and it broke some automations with presence notification.
I think it happend because of huge update of device_tracker/mikrotik_tracker. Here is my old config:

device_tracker:
  - platform: mikrotik
    host: 192.168.***.***
    username: *******
    password: *******
    interval_seconds: 300
    consider_home: 600
    track_new_devices: false

And my new config:

mikrotik:
  - host: 192.168.***.***
    username: *******
    password: *******
    method: capsman
    track_devices: true

Now, the problem is with one automation:

- id: '********************'
  alias: Presence notifier
  trigger:
  - entity_id:
    - device_tracker.renga
    - device_tracker.lesya
    platform: state
  action:
  - data_template:
      message: "{% if trigger.entity_id == \"device_tracker.renga\" %}\n  {% set person\
        \ = \"Renga\" %}\n{% elif trigger.entity_id == \"device_tracker.lesya\" %}\n\
        \  {% set person = \"Lesya\" %}\n{% endif %} {% if trigger.to_state.state == 'home' %}\n  {{ 
      person}} arrived\n{% else %}\n  {{ person }} leaving\n{% endif %}\n"
      title: Presence {{ as_timestamp(now()) | timestamp_custom("%d-%m-%Y, %H:%M:%S",
        True) }}
    service: notify.ios_renga

With the new mikrotik tracker i recieve a lot of messages, with 13 seconds intervals. This is because tracker updates entity attributes, like uptime, signal, etc. So i changed my automation a little:

{% if trigger.from_state.state  == 'not_home' and trigger.to_state.state == 'home' %}\n  {{ person }}\
        \ arrived\n{% elif trigger.from_state.state  == 'home' and trigger.to_state.state == 'not_home' %}\n  {{ person }} leaving\n  {% endif %}\n

Now it’s okay with messages, but i have a huge amount of errors in log file:

2019-09-11 13:38:20 ERROR (SyncWorker_11) [homeassistant.components.ios.notify] No message parameter was found in the notification payload.

Can enyone help me with that problem?

I would think that’s because in many cases the template for message results in an empty string.

I think what you want to do, instead of testing for the cases where you want to get a message in the message template, is instead to add a condition to the automation so the notify service is only called in the cases you want. E.g.:

  condition:
    condition: template
    value_template: >
      {{ trigger.from_state.state == 'not_home' and trigger.to_state.state == 'home' or
         trigger.from_state.state == 'home' and trigger.to_state.state == 'not_home' }}

Then you can change the last part of the message template to:

{% if trigger.to_state.state == 'home' %}\n  {{ person }}\
        \ arrived\n{% else %}\n  {{ person }} leaving\n  {% endif %}\n

Actually, you could clean up the whole message template a bit:

      message: >
        {{ trigger.to_state.object_id.title() }} {{
           'arrived' if trigger.to_state.state == 'home' else 'leaving' }}
1 Like