More complicated self.call_service question

Quick Question for non-programmers

For the service self.call_service() how would I convert a more complicated service call like

  - alias: Notify of Motion
    trigger:
      ...
    action:
      service: notify.mobile_app_<your_device_id_here>
      data:
        message: Motion Detected
        data:
          vibrationPattern: "100, 1000, 100, 1000, 100" # The pattern you wish to set for vibrations
          channel: Motion # For devices on Android 8.0+ only

I get the

self.call_service(notify/mobile_app_<your_device_id_here>,  message='Motion Detected')

but how do I add vibrationPattern and channel information as data within data ?

Hi @Vesha,

The data inside the data can be sent as a python dictionary if I am not mistaken, so something like:

self.call_service(notify/mobile_app_<your_device_id_here>,  message='Motion Detected', data={"vibrationPattern": "100, 1000, 100, 1000, 100", "channel": "Motion"})

However, I am not 100% sure that this will work, if it does not work, I would try to wrap the python dictionary from the data keyword argument with json.dumps(…) like:

self.call_service(notify/mobile_app_<your_device_id_here>,  message='Motion Detected', data=json.dumps({"vibrationPattern": "100, 1000, 100, 1000, 100", "channel": "Motion"}))

And do not forget to import json.

Cheers,
Xavi M.

Thank you the first dict one did work.

1 Like