Dynamic weather location

I was wondering if it could be possible to use templating in the configuration.yaml file. I would like to use this to setup dynamic weather data. I bike a lot, therefor it would be great to get actual weather data of the location I’m right at that moment. For example:

- platform: darksky
  api_key: !secret darksky_api_key
  language: nl
  latitude: {{states.device_tracker.name.attributes.latitude}}
  longitude: {{states.device_tracker.name.attributes.longitude}}
  scan_interval: '00:05:00'
    - icon
    - cloud_cover
    - apparent_temperature

could something like this be possible. It would be great!

I don’t understand why not just use Dark Sky on your mobile device? It will do exactly that, and you don’t have to open HA to see it.

I have a lot of automations depending on the Home assistant darksky sensor. For example. My lovelace weather tab’s background depends on it.

I get a notification when I have to go home before sunset (if I’m out of light for example).
And a lot more automations that only the darksky app can’t achieve.

1 Like

Because he want to use a current state as a location to darksky and therefore needs to be possible to accept a template value as a longitude and latitude.

1 Like

Well you aren’t going to be so far away that your sunset time is going to change, so I don’t understand why that would matter, or what that would change. You can STILL have that notification.

But HOME Assistant is for your HOME. I fail to understand where this is useful. If you want to know the weather for the location you are CURRENTLY at, use Darksky?

I know what he is asking. I’m not an idiot. I just don’t understand the benefit of it.

1 Like

I don’t think it will work because the configuration file get’s parsed at load time. So even if templating was possible the values wouldn’t update without a restart.

If you are running Android I recommend Tasker for mobile device automation. As mentioned this is best done on device not trying to link back to your house. If you need something to happen at your house based on your mobile location there are ways to send messages from Tasker back the HASS to trigger events at your house. I actually use this method to do things like turn up the heat/AC when I am on my way home. No reason to walk into a hot house with a hangover after a long party weekend… :slight_smile:

I’am not an idiot either, but I do understand the possibilities. When you can set the longitude and latitude dynamically as the position of your phone you can show for example the current weather based on your mobile location instead of a fixed home location. Think about travelers or people on a boat.

1 Like

But you can get that data from apps that are already on your mobile device.

I travel. That doesn’t mean I want my HOME Assistant to display the weather where I currently am.
I have apps on my phone if I want to know the weather where I am. If I wanted HOME Assistant to know the weather where I am, there are a plethora of ways for me to get that data back to Home Assistant.

I think this is a different issue altogether. The request here is for DYNAMIC WEATHER LOCATION, not DYNAMIC HOME ASSISTANT LOCATION.

The boat example is an interesting use case. But rather than templating the config file, it would probably be better implemented by exposing the Lat/Long as attributes in dark sky and then allow those to be adjusted via automations. Unfortunately it doesn’t look like that component allows that today, but if you are handy at Python it could probably be done.

good point

You can use the location from one of your device trackers and manually do some kind of REST API call to dark sky to get a JSON file and parse that.


Yeah that’s an excellent idea, don’t forget about the Rest module it is very powerful, it can often do the same thing as the built in components. I replaced the defunct Weather Underground component with Rest templates after they changed their API and have been running fat dumb and happy ever since.

I opened this PR https://github.com/home-assistant/home-assistant/pull/30019 because I had the exact same use case in mind.

Very nice. Can i have your configuration , how to set the background in the weather tab with the weather condition? Thankssss.

I have been busy with the restful sensor and here is the solution to my problem.

First I created the restful sensor in my configuration.yaml file:

  - platform: rest
    resource_template: 'https://api.darksky.net/forecast/<apikey>/{{states.person.<name>.attributes.latitude}},{{states.person.<name>.attributes.longitude}}'
      - currently
    name: darksky_api
    value_template: 'OK'

You’ll get the following data:

Now we want to extract the values:

  - platform: template
        value_template: '{{ states.sensor.darksky_api.attributes["currently"]["icon"] }}'
        value_template: '{{ states.sensor.darksky_api.attributes["currently"]["precipIntensity"] }}'
        value_template: '{{ states.sensor.darksky_api.attributes["currently"]["precipProbability"] }}'
        value_template: '{{ states.sensor.darksky_api.attributes["currently"]["windSpeed"] }}'

This is the result:

1 Like

Yes offcourse. I have made a new project for it. This is the link:



I have been looking for this for some time now. I am implementing this in a RV and would like to get current weather info as i travel.
I tried to add this, but i must be missing something as i can not get the configuration to check correctly.
It keeps giving me a invalid configuration.

is it possible you can assist and help me implement this .

Thanks again,

If you want help from the community please submit your current configuration to have us have a look at it.

I was reading this and thought that you could also do this in one go. Have a REST sensor that uses a value template to extract one value from the json output and create attributes with the sensor for other values.

In this way you don’t have separate sensors to show on the UI but just one for use in automations. This could be useful depending on your use case.

Is it possible to do it with the Met.no weather provider (the default one) I tried to use other weather providers but no longer accept new users or were paid services.

I am at this step, but can figure it out.
Also I don’t know where the config file for this is really located at to look at the code