Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home Assistant device_tracker always shows not_home #695

Closed
blysik opened this issue May 6, 2020 · 9 comments · Fixed by #705
Closed

Home Assistant device_tracker always shows not_home #695

blysik opened this issue May 6, 2020 · 9 comments · Fixed by #705

Comments

@blysik
Copy link

blysik commented May 6, 2020

Describe the bug

The Home Assistant device_tracker never knows the car is home. Even if proximity.home_tesla is 0, the device_tracker entities never show the car as home.

Expected behavior

If the car is parked at home, the device_tracker should say 'home'.

How to reproduce it (as minimally and precisely as possible):
Normal usage.

Environment

  • TeslaMate version: v.1.19.3
  • Type of installation: Docker
  • OS TeslaMate is installed on: Docker installed on Intel NUC, RHEL
  • HA v0.109.4
@ngardiner
Copy link
Contributor

The proximity sensor determines the distance between the zone (home) and the device-tracker specified. So if your config is:

proximity:
  home_tesla:
    zone: home
    devices:
      - device_tracker.tesla_location
    tolerance: 10
    unit_of_measurement: km

You can check:

  • Does device_tracker.tesla_location correctly show the location of your vehicle on the map in lovelace
  • Is the Home zone defined under zones with an accurate Lat and Lon value?

@blysik
Copy link
Author

blysik commented May 7, 2020

  • I have that exact proximity block, yes.
  • device_tracker.tesla_location does show the correct place on the map.
  • Home zone is defined correctly in the configuration.yaml, and in Configuration -> Zones -> Home -> the longitude/latitude are correct.

Everything appears correct, except the actual device_tracker always shows not_home. It's super strange to me. Maybe I should try deleting it?

See the attached image below. (I covered the long/lat, but it's correct.)

Screen Shot 2020-05-06 at 9 27 40 PM

@ngardiner
Copy link
Contributor

Yes I see what you're referring to and I have the same on my side.

I suspect that the state of the device tracker is updated by an automation and not by the lat and lon. I will do some research and get back to you, but I suspect there's an automation required to check if the device_tracker entity is within the home zone radius and if so to change status to home.

@blysik
Copy link
Author

blysik commented May 7, 2020

That seems reasonable. I'll experiment with automations also and see if I can make something. I was just under the expectation the logic was already there somehow. Thanks.

@blysik
Copy link
Author

blysik commented May 7, 2020

My understanding is that this block will always set not_home:

- alias: Update Tesla location as MQTT location updates
  initial_state: true
  trigger:
  - platform: mqtt
    topic: teslamate/cars/1/latitude
  - platform: mqtt
    topic: teslamate/cars/1/longitude
  action:
  - service: device_tracker.see
    data_template:
      dev_id: tesla_location
      location_name: not_home
      gps:
      - '{{ states.sensor.tesla_latitude.state }}'
      - '{{ states.sensor.tesla_longitude.state }}'

Maybe the location needs to be a template, based on proximity. If proximity 0, than home, if not, then not_home.

@blysik
Copy link
Author

blysik commented May 7, 2020

This automation seems to work for me properly. Not sure if it's the most elegant method.

- alias: Update Tesla location as MQTT location updates
  initial_state: true
  trigger:
  - platform: mqtt
    topic: teslamate/cars/1/latitude
  - platform: mqtt
    topic: teslamate/cars/1/longitude
  action:
  - service: device_tracker.see
    data_template:
      dev_id: tesla_location
      location_name: >
            {% if is_state('proximity.home_tesla', '0') %}
              home
            {% else %}
              not_home
            {% endif %}
      gps:
      - '{{ states.sensor.tesla_latitude.state }}'
      - '{{ states.sensor.tesla_longitude.state }}'

@ngardiner
Copy link
Contributor

Nice work! I like it, I wonder if there's a way to check which zone it is in and then return the zone name, otherwise not_home? It would be very cool to have the zone updated, eg work or school based on zones defined in HASS. I might have some time to play around with this shortly, but your change above should certainly take care of home/not_home status transitions.

@ngardiner
Copy link
Contributor

ngardiner commented May 8, 2020

You know, I think this is the default behaviour. The HASS doco says:

The state of your tracked device will be 'home' if it is in the home zone, detected by your network or Bluetooth based presence detection. If you’re using a presence detection method that includes coordinates then when it’s in a zone the state will be the name of the zone (case sensitive). When a device isn’t at home and isn’t in any zone, the state will be 'not_home'.

https://www.home-assistant.io/integrations/device_tracker/

As a test, I've dropped the location_name parameter entirely from the automation and it is correctly picking up "home". I'm not in a position to test other zones at the moment but I suspect removing the override will let HASS figure out the zone itself.

@blysik
Copy link
Author

blysik commented May 8, 2020

aha! that's great, and makes sense. I'll remove it also. I don't have any other zones setup, but i'll see about doing that in the future.

ngardiner added a commit to ngardiner/teslamate that referenced this issue May 9, 2020
   - Removed the static not_home location from the device_tracker definition which fixes teslamate-org#695 
   - Added Garage Door automation
   - Added automation for doors and windows open which would address teslamate-org#698 (for HomeAssistant users at least)
adriankumpf added a commit that referenced this issue May 19, 2020
* Update home_assistant.md

   - Removed the static not_home location from the device_tracker definition which fixes #695 
   - Added Garage Door automation
   - Added automation for doors and windows open which would address #698 (for HomeAssistant users at least)

* Enalbe syntax highlighting

* Enalbe syntax highlighting

* Enalbe syntax highlighting

Co-authored-by: Adrian Kumpf <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants