Weather integration using gps source

Hey all, i have HA running in a RV and i really want a weather card for my dashboard, problem is whenever we move the rv we have to manually update the home location. Is there any way to update the location automatically OR perhaps provide weather data on a particular users GPS location eg my phone

It looks like you could invoke the homeassistant.set_location service from an automation to update the location details, assuming you can obtain that data from something.

I am trying to set it up in developer, i can pull the longitude and latitude from my
entity: device_tracker.iphone on lovelace it shows the lat and long however not sure how to pull those items from the entity into the service

I think the key here is to be able to define a trigger for when those attributes are updated, and invoke the service with those attribute values. I’m not certain offhand how to define such a trigger as yet, but the service could be updated in such an automation like this:

service: homeassistant.set_location
data:
  latitude: "{{ state_attr('device_tracker.iphone', 'latitude') }}"
  longitude: "{{ state_attr('device_tracker.iphone', 'longitude') }}"

I thought about this some more, and I think the simple answer is to trigger on the state of the device tracker itself, which is either home or not_home. If you create an automation to trigger when transitioning from the former to the latter, and call that service, that should be what you need. Essentially, HA will “follow” your iPhone’s location (once it leaves the currently defined “Home” zone).

Perhaps:

- alias: Update Home Assistant Location
  trigger:
  - entity_id: device_tracker.iphone
    from: home
    to: not_home
  action:
  - service: homeassistant.set_location
    data:
      latitude: "{{ state_attr('device_tracker.iphone', 'latitude') }}"
      longitude: "{{ state_attr('device_tracker.iphone', 'longitude') }}"
1 Like

thanks it seems to be working, will have to wait and see how the location updates, love this forum

1 Like

This looks pretty interesting. I was thinking about doing something similar on the boat. Thank you!

Ive been trying to get this to work ona fresh install and it keeps saying message is malformed? any ideas?

I wonder if the template values are not returning the expected data. Try going into Developer Tools | States, type in or select your device_tracker entity, and see what it shows for the latitude and longitude attributes. If this are null or are even absent, that might explain the “malformed” message you are seeing. In that case, the automation may need to have a conditional to verify that the attributes are valid before executing the action block. This is probably going to require some research, as I don’t know offhand exactly what that would look like.

If they are null/missing, then additionally you’ll need to check into why this is happening; for mobile app device_trackers, perhaps the right app permissions were not granted, or that particular sensor was not enabled (in the app)?

This worked great to get my home location automatically updated, but to your original question of getting weather data updated as well: Did you ever figure out a solution?

Maybe vote on my feature request to make this easier to do?