[Solved] How to send location as map via telegram

Hi

I’m doing this to send location of a device tracker as a map via Telegram:

      - service_template: notify.telegramdebug
        data_template:
          message: 'Blah blah.'
          data:
            location:
              latitude: states.device_tracker.mydevice.latitude
              longitude: states.device_tracker.mydevice.longitude

This errs:

Sep 14 15:45:30 home-assistant hass[32241]: 2017-09-14 15:45:30 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Sep 14 15:45:30 home-assistant hass[32241]: Traceback (most recent call last):
Sep 14 15:45:30 home-assistant hass[32241]: File “/usr/lib/python3.5/asyncio/tasks.py”, line 241, in _step
Sep 14 15:45:30 home-assistant hass[32241]: result = coro.throw(exc)
Sep 14 15:45:30 home-assistant hass[32241]: File “/usr/local/lib/python3.5/dist-packages/homeassistant/core.py”, line 1025, in _event_to_service_call
Sep 14 15:45:30 home-assistant hass[32241]: yield from service_handler.func(service_call)
Sep 14 15:45:30 home-assistant hass[32241]: File “/usr/local/lib/python3.5/dist-packages/homeassistant/components/telegram_bot/init.py”, line 288, in async_send_telegram_message
Sep 14 15:45:30 home-assistant hass[32241]: partial(notify_service.send_location, **kwargs))
Sep 14 15:45:30 home-assistant hass[32241]: File “/usr/lib/python3.5/asyncio/futures.py”, line 361, in iter
Sep 14 15:45:30 home-assistant hass[32241]: yield self # This tells Task to wait for completion.
Sep 14 15:45:30 home-assistant hass[32241]: File “/usr/lib/python3.5/asyncio/tasks.py”, line 296, in _wakeup
Sep 14 15:45:30 home-assistant hass[32241]: future.result()
Sep 14 15:45:30 home-assistant hass[32241]: File “/usr/lib/python3.5/asyncio/futures.py”, line 274, in result
Sep 14 15:45:30 home-assistant hass[32241]: raise self._exception
Sep 14 15:45:30 home-assistant hass[32241]: File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
Sep 14 15:45:30 home-assistant hass[32241]: result = self.fn(*self.args, **self.kwargs)
Sep 14 15:45:30 home-assistant hass[32241]: File “/usr/local/lib/python3.5/dist-packages/homeassistant/components/telegram_bot/init.py”, line 547, in send_location
Sep 14 15:45:30 home-assistant hass[32241]: latitude = float(latitude)
Sep 14 15:45:30 home-assistant hass[32241]: ValueError: could not convert string to float: ‘states.device_tracker.mydevice.latitude’

In the webui in states I can validate that the info looks OK:

device_tracker.mydevice
Larswork
longitude: 10.1234
icon: False
latitude: 59.1234
battery: 64
gps_accuracy: 24
source_type: gps
friendly_name: lars
tid: La

Any idea what I’m doing wrong?

Ok, i see states.device_tracker.my… come out empty, so error must be there.

Try this:
states.device_tracker.mydevice.attributes.longitude

1 Like

Thanks. Both of these:

states.device_tracker.mydevice.attributes.longitude
states.device_tracker.mydevice.attributes["longitude"]

seems to work.

1 Like

No, I withdraw that.

They work fine in text, i.e.

  - service_template: notify.telegramdebug
    data_template:
      message: 'message {{ distance(states.device_tracker.lars) | round(1) }} km. {{ states.device_tracker.lars.attributes["latitude"] }} / {{ states.device_tracker.lars.attributes.latitude }} '

But not with telegram when used like in the first post. Seems it’s trying to use the text ‘states.device…’ instead of read the object?

Sep 14 20:57:20 home-assistant hass[5167]:   File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/telegram_bot/__init__.py", line 547, in send_location
Sep 14 20:57:20 home-assistant hass[5167]:     latitude = float(latitude)
Sep 14 20:57:20 home-assistant hass[5167]: ValueError: could not convert string to float: 'states.device_tracker.lars.attributes.latitude'

I tried this script to send my location and it works:

location:                                                                                                      
  alias: 'my location'                                                                                         
  sequence:                                                                                                    
    - service: telegram_bot.send_location                                                                      
      data_template:                                                                                           
        latitude: '{{states.device_tracker.motorolag4plus.attributes.latitude}}'                               
        longitude: '{{states.device_tracker.motorolag4plus.attributes.longitude}}'
1 Like

Hi.

That worked. Thanks!