Unlock the Hidden Weather Forecast in Home Assistant

Sdílet
Vložit
  • čas přidán 29. 06. 2024
  • In this video, we'll show you how to retrieve a weather forecast in Home Assistant. By following this simple tutorial, you'll be able to access the latest weather information for your home or office.
    Home Assistant is a powerful open-source platform that allows you to control your entire home or office from one interface. By following this tutorial, you'll be able to retrieve a weather forecast for your location in just a few minutes!
    This tutorial explains how you can create a Jinja2 Trigger template in Home Assistant that makes use of an action. This way, you can call a service in the template that returns a value. This value can be stored in a variable. You can return that variable as the state of the template, or use that variable to calculate another value.
    ⭐ NOTE: as of Home Assistant 2023.12, the service is no longer weather.get_forecast, but weather.get_forecasts. You need to use the following code in the template now: {% set precipitation = my_forecast['weather.openweathermap'].forecast[daypart].precipitation %} ⭐
    ⭐ You can download the code that I created for this video at: ko-fi.com/s/bf6b252838 ⭐
    Links referred to in this video:
    * How to create your own Garden Watering System in Home Assistant: • How to Create YOUR OWN...
    Blog version: www.smarthomejunkie.net/how-t...
    ⭐⭐⭐
    * Join this channel to get access to perks: 📺 / smarthomejunkie
    * Please consider becoming my patron 🏅 at / smarthomejunkie
    * Or please support me by buying me a ☕ at ko-fi.com/smarthomejunkie/
    ⭐⭐⭐
    ⭐ If you want me to create a review of your product, please visit this page for information and rates: www.smarthomejunkie.net/revie... ⭐
    ⭐ I offer Consultancy and Training for your Home Assistant setup. Visit this page for more information: www.smarthomejunkie.net/servi... ⭐
    My Devices: github.com/smarthomejunkie/My...
    Instagram: / smarthomejunkie
    Twitter: / smarth0mejunkie
    Facebook: / smarthomejunkie
    TikTok: / smarthomejunkie
    Discord: / discord
    Music by:
    * 2TECH-AUDIO: 2tech-audio.bandcamp.com/
    00:00:00 Introduction
    00:00:50 The action parameter in Home Assistant
    00:01:14 The Weather Get Forecast service in Home Assistant
    00:01:53 Check results of the Weather Forecast Service in the developer tools.
    00:02:37 Explaining what the total rain forecast for the next couple of hours is.
    00:03:14 How to install Studio Code Server in Home Assistant.
    00:03:32 How to create a templates.yaml file in Home Assistant.
    00:04:15 Add the forecast code to the templates.yaml file.
    00:07:19 Test the Get Forecast Trigger Template
    00:07:56 Conclusion
    #homeassistant #template #yaml #automations #smarthome #sensors #development
  • Jak na to + styl

Komentáře • 66

  • @SmartHomeJunkie
    @SmartHomeJunkie  Před 9 měsíci +2

    ⭐ NOTE: as of Home Assistant 2023.12, the service is no longer weather.get_forecast, but weather.get_forecasts. You need to use the following code in the template now: {% set precipitation = my_forecast['weather.openweathermap'].forecast[daypart].precipitation %} ⭐
    See the description of this video for more information.
    ⭐ You can download the code that I created for this video at: ko-fi.com/s/bf6b252838 ⭐
    Links referred to in this video:
    * How to create your own Garden Watering System in Home Assistant: czcams.com/video/e8mlJBce3uQ/video.html
    Blog version: www.smarthomejunkie.net/how-to-create-action-template-sensors-in-home-assistant

    • @martinmurer4954
      @martinmurer4954 Před 4 měsíci

      Maybe you should pin this comment to the top!

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 4 měsíci +1

      @@martinmurer4954 Weird. It was pinned to the top.

    • @BenCos2018
      @BenCos2018 Před 3 měsíci

      @@SmartHomeJunkieIt removes the pin when you edit it

    • @tomjones2860
      @tomjones2860 Před 2 měsíci

      If you change
      {% set precipitation = my_forecast['weather.openweathermap'].forecast[daypart].precipitation %}
      Don't you need to change the "probability" line too
      {% set precipitation_probability = my_forecast['weather.openweathermap'].forecast[daypart].precipitation_probability / 100 %}
      ???

  • @donaldhoudek2889
    @donaldhoudek2889 Před 9 měsíci +6

    Congratulations on 40K subscribers!

  • @sevagjb
    @sevagjb Před 9 měsíci +1

    i like it, i see advance work nice :)

  • @AndriusNera
    @AndriusNera Před 9 měsíci +4

    Hello, I would like a sensor that can calculate daily or monthly costs based on daily or monthly electricity consumption and the variable nordpool hourly rate

  • @Eldari-sr7db
    @Eldari-sr7db Před 5 měsíci

    thanks for the Videos! i learn a lot from them. one question - what is the language of the template? is it possible to write it also in python?

  • @robertaccess
    @robertaccess Před 9 měsíci +1

    intresting...

  • @fbutler
    @fbutler Před 8 měsíci +1

    Thanks, I've downloaded the code to use as the framework for creating a weather.get.forecast based sensor containing the minimum temperature in the next 24 hours to enable a frost warning notification to be sent every day at 9:00am

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 8 měsíci

      Excellent!

    • @gorgorgonzales3090
      @gorgorgonzales3090 Před 6 měsíci

      I am trying to achive the same thing, how did you configure the sensorstate to reflect the min temperature? Thanks!

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 6 měsíci

      Ah! This is a great topic for a future video!

    • @gorgorgonzales3090
      @gorgorgonzales3090 Před 6 měsíci +1

      @@SmartHomeJunkie Oh that would be great! 🥳

  • @xelemorf
    @xelemorf Před 7 měsíci +1

    @SmartHomeJunkie
    I would have an idea similar to this, which would announce the weather and temperature with Alexa for the next couple of hours when a button is pressed on the main door.

  • @gmaclean1
    @gmaclean1 Před 9 měsíci

    Love your videos, thank you.
    I however don’t have a love affair with home assistant when they make changes like this. I’m struggling to understand why they would discontinue the old weather system when it works and is easily understandable by users.

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci +2

      As far as I understood, some weather integrations cost money when you call the api. Using this service you can control your costs.

  • @eminteinko8552
    @eminteinko8552 Před 8 měsíci

    Hi! Nice work, is it possible to transfer the rain forecast to cloud forecast as well? Thank you

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 8 měsíci

      There's no cloud forecourt attribute as far as I know.

  • @erwingobee3890
    @erwingobee3890 Před 9 měsíci +2

    Hi, was een goed concert vrijdagavond in Tilburg.

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci

      Haha, heb je me gezien? Ik ben zaterdag nog een keer geweest 🤣😳

  • @christian1603
    @christian1603 Před 9 měsíci

    Hi ! Simple question... You have the entity weather.openweathermap coming from the openweathermap integration. How is it configured (hourly, daily, onecall_hourly or onecall_daily)? Or doesn't this matter any more ?

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci

      I think I defined it hourly, but I also think it doesn't matter if you use the service. Didn't test it though.

  • @JoseBerruezo
    @JoseBerruezo Před 9 měsíci +3

    Hello, why is your template showing "action: Property action is not allowed." ?

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci

      That is because Studio Code Server is not up to date yet.

  • @antoniobaldassarre7457
    @antoniobaldassarre7457 Před 7 měsíci

    hi there, thank you very much for the help. After I follow your guide, I still cannot see the sensor in the dev tool. Any idea why ☹ ?

  • @michelbeauregard6187
    @michelbeauregard6187 Před 9 měsíci +1

    Hi, great video. I was using the response value of a weather service call in the action section of the automation as follows:
    service: weather.get_forecast
    data:
    type: hourly
    target:
    entity_id: weather.granby_forecast
    response_variable: response
    That response variable is temporary as its associated with the automation only. Which can be optimise for the purpose.

  • @henkoo123456
    @henkoo123456 Před 9 měsíci +1

    Is dit het enigste wat aangepast moet worden voor het programma Garden Watering System?

  • @michaelthompson657
    @michaelthompson657 Před 6 měsíci

    Hi, I have the met office weather integration which has the same 3 hour weather but it only has probability of precipitation and not precipitation aswell like you mentioned in this video. I have no idea how or what parts of the code to alter. Can you help?

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 6 měsíci

      Hmmmzzzzz.... If your integration does not provide the precipitation, there's no way to retrieve it. I am a bit puzzled though because each weather integration should provide that information. You might want to check out Openweathermap instead.

    • @michaelthompson657
      @michaelthompson657 Před 6 měsíci

      @@SmartHomeJunkie apologies, I mustn’t have explained myself correctly. It’s has separate sensors for daily and 3 husky precipitation but it also shoes precipitation with the get forecasts service like you showed here. My main problem is altering the code because it only has probability of precipitation and it doesn’t have precipitation too. So it only has one precipitation value, so I’m not sure what to do with the yaml code

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 6 měsíci

      I'm not sure what you mean. What result does the weather. show?

  • @Xpl0jd1
    @Xpl0jd1 Před 9 měsíci +1

    I struggle abit with my HA, I got a IKEA button with Press "UP/DOWN", Hold "UP/DOWN" also have Press "LEFT/RIGHT".
    I´m trying to get brightness to go up and down by Hold "UP/DOWN" but fail, also want to colour cycle by Press "LEFT/RIGHT".
    I dont find any help, do you have a video about this that i missed? :D

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci +1

      Sure:
      Dim Lights THE RIGHT WAY In Home Assistant - TUTORIAL
      czcams.com/video/L-bcabdaMxE/video.html

    • @Xpl0jd1
      @Xpl0jd1 Před 9 měsíci

      @@SmartHomeJunkie thank you! I missed the restart function on automations. But do you also have a video how to cycle throw different colours with side buttons?

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci +1

      @@Xpl0jd1 Yup...
      How to Cycle through Scenes like Hue using a Button in Home Assistant - TUTORIAL
      czcams.com/video/nBdDdC2jVUc/video.html

    • @Xpl0jd1
      @Xpl0jd1 Před 9 měsíci +1

      @@SmartHomeJunkie ah using scenes 🙈

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci

      @@Xpl0jd1 You can use it with single lights too, but in my example I used scenes.

  • @de3ra
    @de3ra Před 3 měsíci

    I was trying to do this but with the twice daily forcast so voice assist can say what the daily weather report is when i ask it, but it seems the description is not pulling up. Is anyone able to help me understand why? It seems like it should be working.
    state: >
    {% set ns = namespace() %}
    {% for daypart in my_forecast %}
    {% if loop.first %}
    {% set ns.DetailedDescription = daypart.detailed_description %}
    {% endif %}
    {% endfor %}
    {{ ns.DetailedDescription }}

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 3 měsíci

      I'm not completely sure, but I believe voice assist cannot understand a command to tell this standardly yet. You can however create an automation that respond to a specific sentence and then send the weather info using TTS to your smart speaker.

  • @radovanobal878
    @radovanobal878 Před 20 dny

    they kicked a large bucket of manure with the forecast removal. It's made it infinitely harder for new users than it was with the old variable access.

  • @louisviciedo
    @louisviciedo Před 9 měsíci +1

    similar issue as stated below "'my_forecast' is undefined" error when i try to use it in developer tools. Its been triggering for 12 hours now. ANy thoughts?

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci

      This is kinda weird. The code works perfect here. 🤷🏼‍♂️

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci

      Which weather integration do you use?

    • @louisviciedo
      @louisviciedo Před 9 měsíci

      @@SmartHomeJunkie openweathermap, same as you Ed. Thanks!

    • @DarrenGerbrandt
      @DarrenGerbrandt Před měsícem

      Had this as well when I was browsing around and tried the copy/paste in the Template section of Developer tools but no error if I use it in the template.yaml file. So my thoughts are don't try it in the TEMPLATE section in the Developer Tools. It works fine if you follow the video instructions of adding the !include line to the configuration.yaml and then creating a template.yaml file and putting the template sensor info there as the video instructs.

    • @DarrenGerbrandt
      @DarrenGerbrandt Před měsícem

      @@SmartHomeJunkie I am assuming he's using the Template Editor in the TEMPLATE section of Developer Tools, I got the same error when I thought I would try it out but no error when making a template.yaml file and pasting the code into it.

  • @daveforrester61
    @daveforrester61 Před 6 měsíci

    Have you noticed that the change in 2023.12 from weather.get_forecast to weather.get_forecasts breaks the template sensor as the new format response is subtley different. I got an error saying the response variable has no attribute "forecast". It actually does, but the dictionary is structured slightly differently. I haven't figured out how to fix it.

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 6 měsíci +2

      Yes, I know and already mentioned it in the description of this video and in the what's new video. I already changed the code on my side and will add it to the description as soon as I am back at my PC.

    • @daveforrester61
      @daveforrester61 Před 6 měsíci

      Sorry, but simply changing "weather.get_forecast" to "weather.get_forecasts" doesn't work, well not for me anyway. The response I get has "weather.openweathermap" as the first line, with "forecast" on line 2 and indented 2 spaces. My template sensor becomes unavailable because the "forecast" attribute is a level down in the dictionary response and I can't figure out how to make it use that level. Does this simple change actually work for you?

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 6 měsíci +2

      @@daveforrester61 I never said that it would be simple ;)
      Please see the first comment or video description on what to change exactly.

    • @daveforrester61
      @daveforrester61 Před 6 měsíci

      😂 that was the bit I missed. However, I did manage to figure it out myself with a bit of work in JSON and the template editor 😊. Enjoy your coffee and keep up the great work 👍

  • @ClintCambier1988
    @ClintCambier1988 Před 6 měsíci

    I have tried all sorts of versions of this template. When I use the Template Editor, everytime I get the error "'forecast' is undefined".
    Does anyone know what might be wrong?

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 6 měsíci

      Did you read the NOTE in the description of this video? Home Assistant changed some things in 2023.12.

    • @ClintCambier1988
      @ClintCambier1988 Před 6 měsíci

      @@SmartHomeJunkie I did :-), numerous times but I must still be missing something or it's related to another factor that I'm not yet aware of.
      I have also tried minimizing the script to see if there's any syntax error but all I'm getting is "my_forecast is undefined".
      I'm on version HA Core 2023.12.3.
      If you prefer that I contact you in a different way and buy you another digital coffee up front, let me know.
      - trigger:
      - platform: time_pattern
      hours: "1"
      action:
      - service: weather.get_forecasts
      target:
      entity_id: weather.forecast_edugo_arena
      data:
      type: hourly
      response_variable: my_forecast
      sensor:
      - name: Rain Forecast Edugo Arena
      unique_id: 9ba20bcc-913f-48bd-a9f3-75c97acfdb3d
      unit_of_measurement: mm
      state: >
      {% set ns = namespace() %}
      {% set ns.totalprecipitation = 0 %}
      {% for daypart in range(0, 7) %}
      {% set precipitation = my_forecast['weather.forecast_edugo_arena'].forecast[daypart].precipitation %}
      {% set precipitation_probability = my_forecast[daypart].precipitation_probability %}
      {% if precipitation_probability > 0 %}
      {% set precipitation = precipitation * precipitation_probability %}
      {% endif %}
      {% set ns.totalprecipitation = ns.totalprecipitation + precipitation %}
      {% endfor %}
      {{ ns.totalprecipitation | float(0) | round(2) }}
      If I go to the Developer Tools > Services and use the following then I get the expected ["weather.forecast_edugo_arena"].forecast data structure.
      I also tried copy pasting the example from www.home-assistant.io/integrations/weather to the Developer Tools > Template and also there I received the "hourly is undefined" error.

  • @gigiduru659
    @gigiduru659 Před 4 měsíci

    Hi! I read about v2023.12 change and I modified to:
    - service: weather.get_forecasts
    ...
    {% for daypart in range(0, 7) %}
    {% set precipitation = my_forecast['weather.openweathermap'].forecast[daypart].precipitation %}
    But I get error in v2024.2.3: Error rendering state template for sensor.openweathermap_expected_precipitation: UndefinedError: 'dict object' has no attribute 'forecast'

  • @TomRoos712
    @TomRoos712 Před 9 měsíci

    I've recently downloaded the garden watering code and after 2 days I saw this video come live.
    Unfortunately I can't get it to work. It keeps giving me status unknown.
    You have any tips?

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci

      There must be an error in your code somewhere when the status stays unknown. It also depends on how long the time trigger is set. If it's set to one hour, you might have to wait for one hour before the status changes.

    • @Girbie1973
      @Girbie1973 Před 9 měsíci

      Have you been able to resolve it? I have exactly the same issue. I can't find any error in the code.

    • @TomRoos712
      @TomRoos712 Před 9 měsíci

      Haven't had time to look at it yet unfortunately.

    • @SmartHomeJunkie
      @SmartHomeJunkie  Před 9 měsíci

      @@TomRoos712 Are you on the latest version of Home Assistant?

  • @Tntdruid
    @Tntdruid Před 9 měsíci +2

    123 start the coffeemaker 😄