Dynamic weather location

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.

2 Likes

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:

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

You’ll get the following data:
2e2480b6-c057-40a2-a105-9787e9b89de7

Now we want to extract the values:

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

This is the result:

2 Likes

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

https://community.home-assistant.io/t/dynamic-lovelace-weather-background/158357

Hello,

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,
John

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

My understanding is that Metno supports this, but only if you keep the original integration setup when you first start home assistant.

what do you mean? isn’t this the original one??

What I mean is that the very first time you start your home assistant server it sets up Met.no integration to use whatever is used for the latitude and longitude in home assistant. So you could use this for an RV for example, where the whole system moves, but not a single device.

If you manually add this integration later, this is not possible currently.

Is this still not possible?

I’d be fine using the restful and template sensor approach, but darksky is no more. Anyone have a current workaround?

You could use a template weather setup together with a REST interface to get some info elsewhere.

Unfortunately, without a good example of a specific weather provider this is beyond me (or at least beyond the amount of time/effort I’m willing to give it). Wunderground is my preferred source (I’ve found it to be the most accurate, at least for my home). Here’s a sample of the API response in case someone is bored and wants to put it together for me. :slight_smile:

Links (with my private API key removed):

https://api.weather.com/v3/wx/forecast/daily/5day?geocode=39.1,-94.6&format=json&units=e&language=en-US&apiKey=yourApiKey

{
  "calendarDayTemperatureMax": [83, 77, 82, 80, 84, 76],
  "calendarDayTemperatureMin": [67, 64, 62, 66, 67, 63],
  "dayOfWeek": [
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday"
  ],
  "expirationTimeUtc": [1695155854, 1695155854, 1695155854, 1695155854, 1695155854, 1695155854],
  "moonPhase": [
    "Waxing Crescent",
    "Waxing Crescent",
    "Waxing Crescent",
    "First Quarter",
    "Waxing Gibbous",
    "Waxing Gibbous"
  ],
  "moonPhaseCode": [
    "WXC",
    "WXC",
    "WXC",
    "FQ",
    "WXG",
    "WXG"
  ],
  "moonPhaseDay": [4, 5, 6, 7, 8, 9],
  "moonriseTimeLocal": [
    "2023-09-19T11:33:39-0500",
    "2023-09-20T12:41:48-0500",
    "2023-09-21T13:49:48-0500",
    "2023-09-22T14:55:44-0500",
    "2023-09-23T15:54:57-0500",
    "2023-09-24T16:45:44-0500"
  ],
  "moonriseTimeUtc": [1695141219, 1695231708, 1695322188, 1695412544, 1695502497, 1695591944],
  "moonsetTimeLocal": [
    "2023-09-19T21:32:00-0500",
    "2023-09-20T22:08:03-0500",
    "2023-09-21T22:52:55-0500",
    "2023-09-22T23:48:31-0500",
    "",
    "2023-09-24T00:55:26-0500"
  ],
  "moonsetTimeUtc": [1695177120, 1695265683, 1695354775, 1695444511, null, 1695534926],
  "narrative": [
    "Thundershowers. Lows overnight in the mid 60s.",
    "Showers ending by midday. Highs in the upper 70s and lows in the low 60s.",
    "Times of sun and clouds. Highs in the low 80s and lows in the mid 60s.",
    "Morning showers and thunderstorms. Highs in the low 80s and lows in the upper 60s.",
    "A few thunderstorms possible. Potential for severe thunderstorms. Highs in the mid 80s and lows in the low 60s.",
    "A few morning showers. Highs in the mid 70s and lows in the low 60s."
  ],
  "qpf": [0.17, 0.02, 0.09, 0.24, 0.37, 0.01],
  "qpfSnow": [0, 0, 0, 0, 0, 0],
  "sunriseTimeLocal": [
    "2023-09-19T07:03:04-0500",
    "2023-09-20T07:03:58-0500",
    "2023-09-21T07:04:51-0500",
    "2023-09-22T07:05:45-0500",
    "2023-09-23T07:06:39-0500",
    "2023-09-24T07:07:33-0500"
  ],
  "sunriseTimeUtc": [1695124984, 1695211438, 1695297891, 1695384345, 1695470799, 1695557253],
  "sunsetTimeLocal": [
    "2023-09-19T19:20:12-0500",
    "2023-09-20T19:18:35-0500",
    "2023-09-21T19:16:59-0500",
    "2023-09-22T19:15:22-0500",
    "2023-09-23T19:13:46-0500",
    "2023-09-24T19:12:10-0500"
  ],
  "sunsetTimeUtc": [1695169212, 1695255515, 1695341819, 1695428122, 1695514426, 1695600730],
  "temperatureMax": [null, 77, 82, 80, 84, 76],
  "temperatureMin": [65, 62, 66, 67, 63, 60],
  "validTimeLocal": [
    "2023-09-19T07:00:00-0500",
    "2023-09-20T07:00:00-0500",
    "2023-09-21T07:00:00-0500",
    "2023-09-22T07:00:00-0500",
    "2023-09-23T07:00:00-0500",
    "2023-09-24T07:00:00-0500"
  ],
  "validTimeUtc": [1695124800, 1695211200, 1695297600, 1695384000, 1695470400, 1695556800],
  "daypart": [
    {
      "cloudCover": [null, 79, 79, 41, 54, 67, 61, 48, 62, 60, 47, 23],
      "dayOrNight": [null, "N",
        "D",
        "N",
        "D",
        "N",
        "D",
        "N",
        "D",
        "N",
        "D",
        "N"
      ],
      "daypartName": [null, "Tonight",
        "Tomorrow",
        "Tomorrow night",
        "Thursday",
        "Thursday night",
        "Friday",
        "Friday night",
        "Saturday",
        "Saturday night",
        "Sunday",
        "Sunday night"
      ],
      "iconCode": [null, 11, 39, 29, 30, 47, 38, 47, 38, 47, 39, 29],
      "iconCodeExtend": [null, 1140, 6103, 2900, 3000, 3809, 6203, 3809, 3800, 3809, 6103, 2900],
      "narrative": [null, "Occasional showers with a thunderstorm possible. Low near 65F. Winds S at 10 to 20 mph. Chance of rain 50%.",
        "Showers in the morning, then cloudy in the afternoon. High 77F. Winds SE at 5 to 10 mph. Chance of rain 40%.",
        "Partly cloudy skies. Low 62F. Winds ESE at 5 to 10 mph.",
        "Intervals of clouds and sunshine. High 82F. Winds ESE at 5 to 10 mph.",
        "Partly to mostly cloudy with a chance of thunderstorms. Low 66F. Winds SE at 5 to 10 mph. Chance of rain 50%.",
        "Scattered thunderstorms in the morning. Partly cloudy skies late. High near 80F. Winds SSE at 10 to 15 mph. Chance of rain 50%.",
        "Scattered showers and thunderstorms. Low 67F. Winds SSE at 10 to 15 mph. Chance of rain 60%.",
        "Scattered showers and thunderstorms. Potential for severe thunderstorms. High 84F. Winds S at 10 to 20 mph. Chance of rain 50%.",
        "Scattered showers and thunderstorms. Potential for severe thunderstorms. Low 63F. Winds SW at 10 to 15 mph. Chance of rain 60%.",
        "Chance of a shower or two during the morning, followed by partly cloudy skies in the afternoon. High 76F. Winds W at 10 to 15 mph. Chance of rain 30%.",
        "Some clouds early will give way to generally clear conditions overnight. Low around 60F. Winds NW at 5 to 10 mph."
      ],
      "precipChance": [null, 50, 38, 15, 18, 47, 51, 61, 46, 58, 34, 16],
      "precipType": [null, "rain",
        "rain",
        "rain",
        "rain",
        "rain",
        "rain",
        "rain",
        "rain",
        "rain",
        "rain",
        "rain"
      ],
      "qpf": [null, 0.17, 0.02, 0, 0, 0.09, 0.07, 0.17, 0.06, 0.31, 0.01, 0],
      "qpfSnow": [null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      "qualifierCode": [null, null, null, null, null, null, null, null, "Q9605",
        "Q9605",
        null, null],
      "qualifierPhrase": [null, null, null, null, null, null, null, null, "Potential for severe thunderstorms.",
        "Potential for severe thunderstorms.",
        null, null],
      "relativeHumidity": [null, 68, 75, 88, 73, 84, 81, 85, 74, 80, 74, 80],
      "snowRange": [null, "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        ""
      ],
      "temperature": [null, 65, 77, 62, 82, 66, 80, 67, 84, 63, 76, 60],
      "temperatureHeatIndex": [null, 81, 77, 74, 83, 80, 82, 81, 87, 83, 76, 71],
      "temperatureWindChill": [null, 65, 66, 62, 64, 66, 67, 67, 68, 63, 64, 60],
      "thunderCategory": [null, "Thunder expected",
        "No thunder",
        "No thunder",
        "No thunder",
        "Thunder expected",
        "Thunder expected",
        "Thunder expected",
        "Severe thunderstorms possible",
        "Severe thunderstorms possible",
        "No thunder",
        "No thunder"
      ],
      "thunderIndex": [null, 2, 0, 0, 0, 2, 2, 2, 3, 3, 0, 0],
      "uvDescription": [null, "Low",
        "Moderate",
        "Low",
        "High",
        "Low",
        "Moderate",
        "Low",
        "Moderate",
        "Low",
        "High",
        "Low"
      ],
      "uvIndex": [null, 0, 4, 0, 7, 0, 5, 0, 5, 0, 6, 0],
      "windDirection": [null, 176, 144, 106, 117, 135, 165, 158, 174, 214, 270, 322],
      "windDirectionCardinal": [null, "S",
        "SE",
        "ESE",
        "ESE",
        "SE",
        "SSE",
        "SSE",
        "S",
        "SW",
        "W",
        "NW"
      ],
      "windPhrase": [null, "Winds S at 10 to 20 mph.",
        "Winds SE at 5 to 10 mph.",
        "Winds ESE at 5 to 10 mph.",
        "Winds ESE at 5 to 10 mph.",
        "Winds SE at 5 to 10 mph.",
        "Winds SSE at 10 to 15 mph.",
        "Winds SSE at 10 to 15 mph.",
        "Winds S at 10 to 20 mph.",
        "Winds SW at 10 to 15 mph.",
        "Winds W at 10 to 15 mph.",
        "Winds NW at 5 to 10 mph."
      ],
      "windSpeed": [null, 16, 9, 9, 9, 9, 11, 11, 13, 11, 10, 7],
      "wxPhraseLong": [null, "Thundershowers",
        "AM Showers",
        "Partly Cloudy",
        "Partly Cloudy",
        "Scattered Thunderstorms",
        "AM Thunderstorms",
        "Scattered Thunderstorms",
        "Scattered Thunderstorms",
        "Scattered Thunderstorms",
        "AM Showers",
        "Partly Cloudy"
      ],
      "wxPhraseShort": [null, "T-Showers",
        "AM Showers",
        "P Cloudy",
        "P Cloudy",
        "Sct T-Storms",
        "AM T-Storms",
        "Sct T-Storms",
        "Sct T-Storms",
        "Sct T-Storms",
        "AM Showers",
        "P Cloudy"
      ]
    }
  ]
}

The same goes for me. I don’t have the time needed to figure this out. But with a little knowledge of HA you should be able to get this working within an hour. Just use the REST sensor to get the results from WeatherUnderground and then use the developer tools to get the JSON from there. If this succeeds you can copy the templates to the Weather configuration.