Weatherbit.io - Current Weather and Forecast data

Also, to clarify, is sensor.weatherbit_forecast_day_1 today’s conditions or tomorrow’s?

And finally, is the precipitation in the forecast sensors the % probability of rain or the mm of rain forecast?

@mattvolp Some of your questions are answered in the API documentation as I mentioned in this post. Day 1 is today. Precipitation is mm/inches. I don’t see a list of possible conditions in the documentation, but I haven’t looked very hard. So far I have seen “rainy”, “partlycloudy”, “cloudy”, “lightning-rainy”. I’ve been working today on changes to the Dark Sky animated weather card so it will work with Weatherbit - I don’t know JS so I’m just hacking away to make something for my own personal use :grin:

Thanks for this.

I guess the info i’m after are all of the conditions outlined here: https://www.home-assistant.io/integrations/weather/ as they are the only ones the weather platform understands.

You are right Matt. What I do, is that I take the code from the API

weather: {

}
and map that to the condition you see in the Weather entity. The Weather Entity is somewhat limited compared to what Weatherbit delivers, so some conditions are mapped to more than one code. See a complete list of Weatherbit Icon codes here: Weatherbit API Icons / Condition Codes as @klogg already pointed out.

1 Like

Severe Weather Alerts

I have prepped the API Engine to handle the Weather Alerts we can get from Weatherbit, but before I just add that blindly, I want to ask the community how this should be presented.

  1. As Weatherbit does not deliver ONE file with Raw data, every new function requires an additional call to the Weatherbit API, and as such it will hit your daily 500 calls limit. So would people prefer to have this as an option that can be de-selected when setting up the Integration, or should I retrieve the data together with the Forecast ?

  2. My current thinking is to add this as ONE additional sensor, where the state displays the number of alerts for the location, and the data is then stored in the Attributes. These Attributes can then be retrieved in Automations, Notifications etc. Any other suggestions?

I’m currently hitting 280 calls a day (2 locations). I’m not using the individual sensor option and at this time not interested in Alerts. Would your change put me at/over the limit? .

No - with the Update Interval you have set now, you will not hit the limit. This will add another call pr location per forecast update interval. So if this is set to every 30 minutes it will another 96 calls per day.

2 Likes

Great integration, really good replacement for DarkSky.

  1. I think this should be optional
  2. I agree that this should be in a single sensor, given the number of weather alerts is variable, it might be easiest to store them as JSON objects in an attribute and provide an example or two of how to extract that for use in automation and display.

I currently download weather alerts from the Met Office and display them in a markdown card under a weather card:

The code’s 2nd part of this:

Then people can either use your examples as is or use them as a starting place.

4 Likes

I am probably missing something here. I wanted to double check my calculations because I had forgotten about the additional calls for the forecast. I’m not seeing the number of calls/per day when I log into weatherbit and when I go back to the integration I can’t see or change my original configuration. I’m guessing I need to delete and re-add?

Thanks for your quick reply

In order to change settings you are correct that you need to remove, and then re-add the Integration. You don’t need to restart Home Assistant between these two actions. I have not found a way to edit settings without doing this, but that might come in the future.

Thank you so much for adding the description sensor!

I agree that the Weather Alerts should be an option and a single sensor. I’m excited to have them, but some may not want the extra API calls. I like the way @eggman is displaying them with a markdown card - thanks for sharing this.

Have you considered including the weather code? Doing so would allow some clever things if you download the icon set.

I got some of this data from a REST sensor while I’ve been playing with this but you get the idea
image

Actually it hit me, when I pushed the release button - why not include the icon code, and also add this to the forecast sensors. So I will do that in the next release. Thanks for the suggestion.

1 Like

This is a bit off-topic, sorry…

@klogg I thought I’d use this API as a way to learn about REST sensors, but I’m struggling with the templating. Would you be willing to share the code for your REST sensor? Thanks!

No problem.
I’ve only been playing with it too at the moment but here is what I have.

Secrets used:

weatherbit_current_resource: https://api.weatherbit.io/v2.0/current?postal_code=[POSTCODE]&key=[API_KEY]
weatherbit_forecast_resource: https://api.weatherbit.io/v2.0/forecast/daily?postal_code=[POSTCODE]&key=[API_KEY]
#============
#=== Sensors
#============
sensor:
  #=================
  #=== REST SENSORS
  #=================

  #=== Current
  - platform: rest
    resource_template: !secret weatherbit_current_resource
    name: weatherbit_current
    value_template: >
      {{ value_json.data[0].city_name }}
    json_attributes:
      - data
    scan_interval:
      minutes: 86400

  # #=== Forecast
  - platform: rest
    resource_template: !secret weatherbit_forecast_resource
    name: weatherbit_forecast
    value_template: >
      {{ value_json.city_name }}
    json_attributes:
      - data
    scan_interval:
      minutes: 86400

  #=== History (yesterday) Resource can't be a secret because of the templated dates
  - platform: rest
    resource_template: https://api.weatherbit.io/v2.0/history/daily?postal_code=[POSTCODE]&start_date={{ (as_timestamp(now()) - 86400) | timestamp_custom('%Y-%m-%d') }}&end_date={{ now().strftime('%Y-%m-%d') }}&key=[API_KEY]]
    name: weatherbit_history
    value_template: >
      {{ value_json.city_name }}
    json_attributes:
      - data
    scan_interval:
      minutes: 86400


  #===========================
  #=== TEMPLATED WEATHER DATA
  #===========================

  #=== Current temp
  - platform: template
    sensors:
      weather_api_current_temp:
        value_template: >
          {% set current = state_attr('sensor.weather_api_current', 'current') %}
          {{ current.temp_c }}
        icon_template: "mdi-thermometer-low"
        unit_of_measurement: '°C'

  #=== Forecast max temp today
  - platform: template
    sensors:
      weather_api_forecast_max_temp_today:
        value_template: >
          {% set forecast = state_attr('sensor.weather_api_forecast', 'forecast') %}
          {{ forecast.forecastday[0].day.maxtemp_c }}
        icon_template: "mdi-thermometer-high"
        unit_of_measurement: '°C'


  #=== RAIN TODAY
  #=== Actual rain today
  - platform: template
    sensors:
      weather_api_actual_rain_today:
        value_template: >
          {% set forecast = state_attr('sensor.weather_api_forecast', 'forecast') %}
          {{ forecast.forecastday[0].day.totalprecip_mm }}
        icon_template: "mdi-weather-rainy"
        unit_of_measurement: mm

  #=== Forecast will it rain today
  - platform: template
    sensors:
      weather_api_forecast_will_it_rain_today:
        value_template: >
          {% set forecast = state_attr('sensor.weather_api_forecast', 'forecast') %}
          {{ forecast.forecastday[0].day.daily_will_it_rain }}
        icon_template: "mdi-weather-rainy"

  #=== Forecast chance of rain today
  - platform: template
    sensors:
      weather_api_forecast_chance_of_rain_today:
        value_template: >
          {% set forecast = state_attr('sensor.weather_api_forecast', 'forecast') %}
          {{ forecast.forecastday[0].day.daily_chance_of_rain }}
        icon_template: "mdi-weather-rainy"
        unit_of_measurement: '%'

  #=== Forecast total rain today
  - platform: template
    sensors:
      weather_api_forecast_total_rain_today:
        value_template: >
          {% set forecast = state_attr('sensor.weather_api_forecast', 'forecast') %}
          {{ forecast.forecastday[0].day.totalprecip_mm }}
        icon_template: "mdi-weather-rainy"
        unit_of_measurement: mm

  #=== TOMORROW
  #=== Forecast will it rain tomorrow
  - platform: template
    sensors:
      weather_api_forecast_will_it_rain_tomorrow:
        value_template: >
          {% set forecast = state_attr('sensor.weather_api_forecast', 'forecast') %}
          {{ forecast.forecastday[1].day.daily_will_it_rain }}
        icon_template: "mdi-weather-rainy"


  #=== Forecast total rain tomorrow
  - platform: template
    sensors:
      weather_api_forecast_total_rain_tomorrow:
        value_template: >
          {% set forecast = state_attr('sensor.weather_api_forecast', 'forecast') %}
          {{ forecast.forecastday[1].day.totalprecip_mm }}
        icon_template: "mdi-weather-rainy"
        unit_of_measurement: mm


  #=== Forecast chance of rain tomorrow
  - platform: template
    sensors:
      weather_api_forecast_chance_of_rain_tomorow:
        value_template: >
          {% set forecast = state_attr('sensor.weather_api_forecast', 'forecast') %}
          {{ forecast.forecastday[1].day.daily_chance_of_rain }}
        icon_template: "mdi-weather-rainy"
        unit_of_measurement: '%'


  #== Weather Outlook Sensor
  - platform: template
    sensors:
      irrigation_weather_outlook:
        value_template: >
          {% set current = state_attr('sensor.weather_api_current', 'current') %}
          {% set current_conditons = current.condition.text %}
          {% set max_high_temp = states('sensor.weather_api_forecast_max_temp_today') %}
          {% set will_rain_today = states('sensor.weather_api_forecast_will_it_rain_today') %}
          {% set will_rain_tomorrow = states('sensor.weather_api_forecast_will_it_rain_tomorrow') %}
          {% set total_rain_today = states('sensor.weather_api_forecast_total_rain_today') %}
          {% set total_rain_tomorrow = states('sensor.weather_api_forecast_total_rain_tomorrow') %}
          {% set chance_of_rain_today = states('sensor.weather_api_forecast_chance_of_rain_today') %}
          {% set chance_of_rain_tomorrow = states('sensor.weather_api_forecast_chance_of_rain_tomorow') %}

          {% set rain_today = total_rain_today ~ 'mm / ' ~ chance_of_rain_today ~ '%' %}
          {% set rain_tomorrow = total_rain_tomorrow ~ 'mm / ' ~ chance_of_rain_tomorrow ~ '%' %}

          {% set outlook = 'Outlook: ' ~ current_conditons ~ ', High Temperature ' ~ max_high_temp ~ '°C<br>' %}

          {% if will_rain_today == '1' and will_rain_tomorrow == '1' %}
            {% set outlook = outlook ~ 'Rain Today (' ~ rain_today ~ ') & Tomorrow (' ~ rain_tomorrow ~ ')' %}
          {% elif will_rain_today == '1' %}
            {% set outlook = outlook ~ 'Rain Today (' ~ rain_today ~ ')' %}
          {% elif will_rain_tomorrow == '1' %}
            {% set outlook = outlook ~ 'Rain Tomorrow (' ~ rain_tomorrow ~ ')' %}
          {% else %}
            {% set outlook = outlook ~ 'No rain forecast today or tomorrow.' %}
          {% endif %}

          {{ outlook }}
        entity_picture_template: >
          {% set current = state_attr('sensor.weather_api_current', 'current') %}
          {% set is_day = current.is_day %}
          {% set icon = current.condition.icon %}
          {% set icon = icon.split('/')[-1] %}
          {% set icon = icon.split('.')[0] %}
          {% set is_day = current.is_day %}
          
          {% if is_day %}
            {{ '/local/icons/weather_icons/weather_api_day/' ~ icon ~ '.png' }}
          {% else %}
            {{ '/local/icons/weather_icons/weather_api_night/' ~ icon ~ '.png' }}
          {% endif %}
2 Likes

@klogg Thank you so much! I appreciate your taking the time to post all that. Now I see how to set up a REST sensor that works. I was trying to pull just the POP (percent of precipitation) out of the forecast and wasn’t getting anywhere. I will study this and try to understand the templating. Your template sensors are more complicated than anything I’ve done before - mine are all pretty simple.

1 Like

I hate to keep adding requests but I can’t see the forecast max temperature anywhere.
Could you add that in too?

@briis I’d love to have the forecast probability of precipitation (pop), but I understand we are asking a lot, feel free to say no if it’s getting to be too many sensors/too much work for you.

Actually, the temperature you see on each Forecast Day on the sensors, is the max_temp. The naming with temperature and templow is the same used on the Weather Entity. There is an Average Temperature available for each day, but I don’t see the use of that.

1 Like