Pirate-Weather / pirate-weather-ha

Replacement for the default Dark Sky Home Assistant integration using Pirate Weather
https://pirateweather.net/
Apache License 2.0
360 stars 24 forks source link

Get Location from the Home Zone in hass.config #241

Open askpatrickw opened 4 months ago

askpatrickw commented 4 months ago

Describe the feature

This is related to #46 which is a request for a templating integration.

This conversation on the HA Community may be useful. https://community.home-assistant.io/t/how-does-an-integration-access-has-set-location/734850

Read Location from Home Assistant's Location

This feature is a simpler request which is for the integration to use the Home Zone as the source of the location. This is exposed on the HASS object under hass.config.

On every run, this integration should read the latitude and longitude from hass.config and that would solve the mainline stationary and mobile cases.

This should be the default behavior for new installs. For existing installs, the existing specified location can be stored as the advanced config.

Advanced Configuration

Location

One might want to use Pirate Weather to see the weather at some other location, in that case the integration can expose manually setting location in advanced configuration which is normally hidden from the user.

Language

Hass.config exposes language and advanced setting could be used an override, or the HASS language could be used instead. The README says only English is supported though, so maybe just remove this and use the HA one if is needed in the future.

Units

Hass.config exposes units. It may be that the HA Units are not specific enough, and you would want and override to enable "SI". I believe UK, CA, US would be covered.

Related: Updating Location using homeassistant.set_location

Mobile uses can use homeassistant.set_location to set the location. Below is an example of using Peplink Mobile Router's GPS (captured from API calls) to do so.

alias: update_peplink_gps
trigger:
  - platform: state
    entity_id: sensor.peplink_gps
action:
  - service: device_tracker.see
    data:
      dev_id: van_luna
      gps:
        - "{{ state_attr('sensor.peplink_gps', 'latitude') }}"
        - "{{ state_attr('sensor.peplink_gps', 'longitude') }}"
  - service: homeassistant.set_location
    data_template:
      latitude: "{{ state_attr('sensor.peplink_gps', 'latitude') }}"
      longitude: "{{ state_attr('sensor.peplink_gps', 'longitude') }}"

Home Assistant version

latest

Integration version

latest

Acknowledgements

alexander0042 commented 3 months ago

Thanks for asking that question and bringing it to my attention! I was thinking about this a little over the weekend and might have something that could work here. The basic idea is that if someone puts a lat/lon in during setup, use that. Otherwise, the update coordinator could check the location on every update and use that.

The issue here is how to identify the update coordinator to make sure an entity knows what data to read from. This is currently based on location, but there's no real reason we couldn't use the entity name to define it instead. It'll take me a couple weeks to get to this, but adding it to the docket!

askpatrickw commented 3 months ago

I'll add that displaying the location being used on the card would be nice to have too.

image

image

cloneofghosts commented 3 months ago

When you say location being used do you mean the coordinates of the current location or the name of the current location? Pirate Weather doesn't have a data point for the current location name (you can always request this as a feature in the API repo) but showing the coordinates should be doable.

askpatrickw commented 3 months ago

I'd live with coordinates, I'm frequently not near a named place anyway.

cloneofghosts commented 3 months ago

It should be possible to show the location coordinates somewhere but I'll defer to @alexander0042. I also created a feature request for a location name being returned in the API.

markandersonus commented 2 months ago

Any ETA on this? Dying to get dynamic weather based on location of my RV (I have the pep wave integration)

askpatrickw commented 1 month ago

People following this Issue should also go put a 👍 on the linked API issue. https://github.com/Pirate-Weather/pirateweather/issues/260

alexander0042 commented 1 month ago

Thanks for tagging that issue- if I can find a way to cache the geonames data, then it's very possible to return a location name. With respect to the weather card, it's based off the integration name, so I don't know if it would be possible to update it dynamically. Maybe there's another card that might work better for this?

In the meantime, I'm testing a new update that lets the latitude and longitude be left blank during the initial setup, which will then let it pull the data from hass on each update!

cloneofghosts commented 1 month ago

V1.5.5 has just been released which allows you to enter in 0 as the latitude and longitude to pull in the current location from HA. It doesn't include a location name or output the current coordinates at the moment.

alexander0042 commented 1 month ago

Would outputting the current coordinates (as sensors I guess) be helpful here? It'd be easy enough to do, but I'm not sure the value beyond debugging

cloneofghosts commented 1 month ago

Would outputting the current coordinates (as sensors I guess) be helpful here? It'd be easy enough to do, but I'm not sure the value beyond debugging

I know we used to have debug statements which printed the co-ordinates that it called the API with and I remember we removed it as it was caught by CodeQL.

It could maybe be added back and just ignore the CodeQL warning or if having a sensor would make more sense then it could be setup instead.

askpatrickw commented 1 month ago

Just as an FYI on the sensor thing...

If you are dynamically updating the location of your HA instance, you must already have some sensor in order to do that.

I'm using a USB GPS Attached to my Victron Cerbo GX which I'm then collecting over MQTT. Other might be using the GPS in their cellular router (like a Peplink) or their Starlink.