Update a device_tracker GPS from a telegram command

I’m trying to create a simple automation that updates the gps location of a device_tracker after a telegram command is received with coordinates. for now it looks like this:

- id: telegram_jeep_location
  alias: 'Telegram Jeep location'
  trigger:
    platform: event
    event_type: telegram_command
    event_data:
      command: '/jeeppark'
  action:
  - data_template:
      gps: '{{ trigger.event.data["args"] }}'
      dev_id: jeep
    service: device_tracker.see 

After execute the command /jeeppark 41.7917539 12.2781456 on telegram the event gets triggered correctly:

{
    "event_type": "telegram_command",
    "data": {
        "user_id": <redacted>,
        "from_first": "<redacted>",
        "chat_id": <redacted>,
        "command": "/jeeppark",
        "args": [
            "41.7917539",
            "12.2781456"
        ]
    },
    "origin": "LOCAL",
    "time_fired": "2019-06-22T12:06:33.725197+00:00",
    "context": {
        "id": "<redacted>",
        "parent_id": null,
        "user_id": null
    }
}

However the automation throws an error:
ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.telegram_jeep_location. Invalid data for call_service at pos 1: None for dictionary value @ data['gps']

I believe it has something to do with how the gps coordinates touple gets formmated because I can manually launch the service without issues with this JSON data:

{"dev_id":"jeep",
"gps":[41.7917539, 12.2781456]}

Any insight is appreciated ^^

A template can only result in a single string. So what you’re getting is '[41.7917539, 12.2781456]', not [41.7917539, 12.2781456]. Try this instead:

      gps:
        - '{{ trigger.event.data["args"][0] }}'
        - '{{ trigger.event.data["args"][1] }}'
3 Likes

i love you <3

BTW, this should also work:

      gps:
        - '{{ trigger.event.data.args[0] }}'
        - '{{ trigger.event.data.args[1] }}'
1 Like

I still need a bit of help.
The automation now works perfectly, and the device_tracker location is updated as intended, that is if I or any other allowed_chat_id send the command.
However, I’m using Taker to send the command and the only convenient way to to do so is to do an HTTP API call using a bot token, for some reason, the bot won’t elaborate the message he sent himself, it dosent even appear in the telegram_commands event bus (whereas my /commands work)

I of course tried to allow the bot id in the allowed_chat_ids, and even using a second bot to send the command, both instances were ignored.
Privacy mode is disabled on the bot trough the BotFather.

Sending the message trough Tasker using my account instead of using a bot seems like a real pain in the ass, there was once a plugin that required huge permission access on the phone to do so but it looks like it was removed from the play store, I wonder why :slight_smile:

Hi,

Were you able to get any solution to this? I am having the same problem for the telegram_command event being able to identify the command from a second bot

Help or information on this i appreciated.

Thanks,

Hard