7 Day Weather Forecast

Love this code, but I have to restart my HASS in order for the days to work. Otherwise it will not change, but state the day it worked. (i.e. if I start my HASS today, it will say Today, Tomorrow, Thursday, Friday, etc. Tomorrow (Wednesday) it will say the same days (and info will be correct, but the named day is incorrect). I get this in the logs.

Tue Mar 19 2019 16:57:57 GMT-0500 (CDT)

Template sensor forecast_2 has no entity ids configured to track nor were we able to extract the entities to track from the friendly_name template(s). This entity will only be able to be updated manually.

Thoughts?

You need to add that entity I’d to the sensor

To here? This is part of my weather.yaml file in my package. Thanks

sensors: 
  forecast_0:
    friendly_name: Today
    value_template: >
      {{states.sensor.dark_sky_daily_high_temperature_0.state|round(0)}}°/{{states.sensor.dark_sky_daily_low_temperature_0.state|round(0)}}°
    icon_template: >-
      {% if is_state("sensor.dark_sky_icon", "clear-day") %}
        mdi:weather-sunny
      {% elif is_state("sensor.dark_sky_icon", "clear-night") %}
        mdi:weather-night
      {% elif is_state("sensor.dark_sky_icon", "cloudy") %}
        mdi:weather-cloudy
      {% elif is_state("sensor.dark_sky_icon", "rain") %}
        mdi:weather-pouring
      {% elif is_state("sensor.dark_sky_icon", "sleet") %}
        mdi:weather-snowy-rain
      {% elif is_state("sensor.dark_sky_icon", "snow") %}
        mdi:weather-snowy
      {% elif is_state("sensor.dark_sky_icon", "wind") %}
        mdi:weather-windy
      {% elif is_state("sensor.dark_sky_icon", "fog") %}
        mdi:weather-fog
      {% elif is_state("sensor.dark_sky_icon", "partly-cloudy-day") %}
        mdi:weather-partlycloudy
      {% elif is_state("sensor.dark_sky_icon", "partly-cloudy-night") %}
        mdi:weather-partlycloudy
      {% else %}
        error
      {% endif %}
  forecast_1:
    friendly_name: Tomorrow
    value_template: >
      {{states.sensor.dark_sky_daily_high_temperature_1.state|round(0)}}°/{{states.sensor.dark_sky_daily_low_temperature_1.state|round(0)}}°
    icon_template: >-
      {% if is_state("sensor.dark_sky_icon_1", "clear-day") %}
        mdi:weather-sunny
      {% elif is_state("sensor.dark_sky_icon_1", "clear-night") %}
        mdi:weather-night
      {% elif is_state("sensor.dark_sky_icon_1", "cloudy") %}
        mdi:weather-cloudy
      {% elif is_state("sensor.dark_sky_icon_1", "rain") %}
        mdi:weather-pouring
      {% elif is_state("sensor.dark_sky_icon_1", "sleet") %}
        mdi:weather-snowy-rain
      {% elif is_state("sensor.dark_sky_icon_1", "snow") %}
        mdi:weather-snowy
      {% elif is_state("sensor.dark_sky_icon_1", "wind") %}
        mdi:weather-windy
      {% elif is_state("sensor.dark_sky_icon_1", "fog") %}
        mdi:weather-fog
      {% elif is_state("sensor.dark_sky_icon_1", "partly-cloudy-day") %}
        mdi:weather-partlycloudy
      {% elif is_state("sensor.dark_sky_icon_1", "partly-cloudy-night") %}
        mdi:weather-partlycloudy
      {% else %}
        error
      {% endif %}
  forecast_2:
    friendly_name_template: >
      {%- set date = as_timestamp(now()) + (2 * 86400 ) -%}
      {{ date | timestamp_custom("%A") }}
    value_template: >
      {{states.sensor.dark_sky_daily_high_temperature_2.state|round(0)}}°/{{states.sensor.dark_sky_daily_low_temperature_2.state|round(0)}}°
    icon_template: >-
      {% if is_state("sensor.dark_sky_icon_2", "clear-day") %}
        mdi:weather-sunny
      {% elif is_state("sensor.dark_sky_icon_2", "clear-night") %}
        mdi:weather-night
      {% elif is_state("sensor.dark_sky_icon_2", "cloudy") %}
        mdi:weather-cloudy
      {% elif is_state("sensor.dark_sky_icon_2", "rain") %}
        mdi:weather-pouring
      {% elif is_state("sensor.dark_sky_icon_2", "sleet") %}
        mdi:weather-snowy-rain
      {% elif is_state("sensor.dark_sky_icon_2", "snow") %}
        mdi:weather-snowy
      {% elif is_state("sensor.dark_sky_icon_2", "wind") %}
        mdi:weather-windy
      {% elif is_state("sensor.dark_sky_icon_2", "fog") %}
        mdi:weather-fog
      {% elif is_state("sensor.dark_sky_icon_2", "partly-cloudy-day") %}
        mdi:weather-partlycloudy
      {% elif is_state("sensor.dark_sky_icon_2", "partly-cloudy-night") %}
        mdi:weather-partlycloudy
      {% else %}
        error
      {% endif %}

So do I add this to forecast_2?

entity_id: sensor.dark_sky_daytime_high_temperature_2, sensor.dark_sky_overnight_low_temperature_2

I have them as a list:

  - platform: template
    sensors:
      forecast_0:
        entity_id:
          - sensor.dark_sky_daytime_high_temperature_0
          - sensor.dark_sky_overnight_low_temperature_0
          - sensor.dark_sky_precip_probability_0
        friendly_name: "Today"
        value_template: >

etc…

1 Like

oh that looks much clearer. Do you mind if I ask you a question related but totally different?

I really want this in my HADashboard…the middle info.

https://i.redd.it/8pfue4rv0gq01.jpg

All the info is in dark_sky. Can I add another entity_id with

sensors: 
  forecast_0:
    friendly_name: Today
    value_template: >
      {{states.sensor.dark_sky_daily_high_temperature_0.state|round(0)}}°/{{states.sensor.dark_sky_daily_low_temperature_0.state|round(0)}}°
    entity_id: 
      - sensor.dark_sky_daytime_high_temperature_0
      - sensor.dark_sky_overnight_low_temperature_0
      - sensor.dark_sky_daily_summary

so that it would add the daily summary, and then add it all in one template so all those sensors could be in there?

Should be able to… my dark_sky uses/shows the daily summary… you just need to edit the card to show it

1 Like

Ok, I will play around with it and see if I can get it to work. If I do I will post it here.

I think I am getting there, but it just says states.sensor.dark_sky_summary

This is what I added to my weather.yaml

  - platform: template
sensors: 
  forecast_0:
    friendly_name: Today
    value_template: >
      {{states.sensor.dark_sky_daily_high_temperature_0.state|round(0)}}°/{{states.sensor.dark_sky_daily_low_temperature_0.state|round(0)}}°
      states.sensor.dark_sky_summary_0.state
    entity_id: 
      - sensor.dark_sky_daytime_high_temperature_0
      - sensor.dark_sky_overnight_low_temperature_0
      - sensor.dark_sky_summary_0

    value_template: >
      {{states.sensor.dark_sky_daily_high_temperature_0.state|round(0)}}°/{{states.sensor.dark_sky_daily_low_temperature_0.state|round(0)}}°
      {{states.sensor.dark_sky_summary_0.state}}

doh, forgot the brackets! You sir rock! Thank you.

1 Like

DavidFW1960, do you happen to be good in CSS as well!

hmm… occasionally…

1 Like

well, I feel like I am close, but I don’t know css at all. The goal is the pic, or close to it

Today
max/low {space} icon {space} summary

Tomorrow
max/low {space} icon {space} summary

Day 3 (friendly name)
max/low {space} icon {space} summary

etc. But this hopefully would be in one widget so it can take up less space. Right now the best I could do is this

(The today is me trying to add the summary)

This is the post I took the three files from. Share your HADashboard setups

And here are my three files:

base_day_forecast.css
.widget-base_day_forecast-{{id}} {
	position: relative;
}
.widget-base_day_forecast-{{id}} .title {
    position: absolute;
    top: 5px;
    width: 100%;
}
.widget-base_day_forecast-{{id}} .title2 {
    position: absolute;
    top: 23px;
    width: 100%;
}
.widget-base_day_forecast-{{id}} .iconcontainer.icon {
   position: absolute;
   bottom: 25%;
   width: 100%;
}

h1.title.left-title{
    text-align:left;
    box-sizing:border-box;
    padding-left: 15px;
    top: 17px;
}

h2.value.left-value{
    box-sizing: border-box;
    padding-left: 15px;
    font-size: 125% !important;
    top: 35px !important;
    bottom: auto;
    position: absolute;
    left: 0;
}

.icon.right-icon{
text-align:right;
padding-right:15px;
box-sizing:border-box;
}

base_day_forecast.html

<h1 class="title left-title" data-bind="text: title"></h1>
<h2 class="iconcontainer icon right-icon" data-bind="attr:{style: icon_style}"><i data-bind="attr: {class: icon}"></i></h2>
<div class="valueunit" style=""><h2 class="value left-value" data-bind="html: value" style="color: #fff;font-size: 100%;"></h2></div>

and finally
base_day_forecast.js
function base_day_forecast(widget_id, url, skin, parameters)
{

self = this;
self.widget_id = widget_id;
self.parameters = parameters;

if ("monitored_entity" in self.parameters)
{
    entity = self.parameters.monitored_entity
}
else
{
    entity = self.parameters.entity
}

var callbacks = [];

self.OnStateAvailable = OnStateAvailable;
self.OnStateUpdate = OnStateUpdate;

var monitored_entities =
    [
        {"entity": parameters.entity, "initial": self.OnStateAvailable, "update": self.OnStateUpdate}
    ];

WidgetBase.call(self, widget_id, url, skin, parameters, monitored_entities, callbacks)

function OnStateAvailable(self, state)
{
    set_view(self,state);
}
 
function OnStateUpdate(self, state)
{
    set_view(self,state);
}

function set_view(self,state){
    self.icon = 'mdi ' + state.attributes.icon.replace(':','-');
    self.title = state.attributes.friendly_name;
    self.value = state.state;

    self.set_field(self, "icon", self.icon)
    self.set_field(self, "value", self.value)
    self.set_field(self, "title", self.title)
}

}

Ok, I am going to try and write a widget (or at least change the standard weather widget). Anyone know how I get to see the css and html of the standard weather widget in HADashboard?

Edit: Nevermind. I found it here. https://github.com/home-assistant/appdaemon/tree/dev/appdaemon/widgets

Ok, I don’t know what I am doing. I tried, but css, js, and html are not being friendly to me.
If anyone can help…not sure if it is hard or not for someone who knows what they are doing. This is my vision. This would all be one widget.

The html/js would be this.

Today
Max/Min (left) icon (middle) summary (right)
Tomorrow
Max/Min (left) icon (middle) summary (right)
Next_day(friendly name template)
Max/Min (left) icon (middle) summary (right)
Next_day(friendly name template)
Max/Min (left) icon (middle) summary (right)
Next_day(friendly name template)
Max/Min (left) icon (middle) summary (right)

I do have all this info in entities.
Today
sensor.dark_sky_daytime_high_temperature_0 / sensor.dark_sky_overnight_low_temperature_0 / sensor.dark_sky_icon_0 /sensor.dark_sky_summary_0
Tomorrow
sensor.dark_sky_daytime_high_temperature_1 / sensor.dark_sky_overnight_low_temperature_1 / sensor.dark_sky_icon_1 /sensor.dark_sky_summary_1
Next Day (friendly name)
sensor.dark_sky_daytime_high_temperature_2 / sensor.dark_sky_overnight_low_temperature_2 / sensor.dark_sky_icon_2 /sensor.dark_sky_summary_2
Next Day (friendly name)
sensor.dark_sky_daytime_high_temperature_3 / sensor.dark_sky_overnight_low_temperature_3 / sensor.dark_sky_icon_3 /sensor.dark_sky_summary_3

and so forth? I just don’t understand how to get this into a widget and format it correctly.

Ha David,

Please allow me to ask what sensors this creates? the sensor.forecast_0 with friendly_name Today, but how can that have a list of entity_id’s? Have never seen a sensor created like that…

Or do you list these, because you fear the template won’t update without them? (believe that won’t be the case here, and only in case of lets say now(), and adding the entity_id: sensor.time takes care of that)

I added those when I was getting an error that it didn’t know the entity to update in the template… This was a LONG time ago. The solution was to add the entities referenced in the template or to create an automation as I recall to update the entities… It was so long ago I don’t remember the exact error message but I preferred to add the entities instead of adding the automation.

A ok, as I suspected in second reading, thanks for answering. (had hoped it to be some clever ay of creating a multitude of sensors…haha, the dark_sky component creates many …

Since all referenced states in your sensor are known to the state machine and are updated, these entity_id’s should not be necessary though. Might have been another error?

No it confused me too but until I added the entity id’s to the template I got the error. It definitely needed them added.

Yeah Darksky if you enable all options creates around 250 sensors (7 days)! It was choking my history and I ended up excluding 95% or them from being recorded in history. And of course for 0.91, that was fun as I had to go and edit the exclude list to change the entities (_0 becomes _0d etc)

hmm, strange, not in my setup. will do some more testing. you must be right, so wonder why i am not seeing that…

fwiw, Ive split-up the dark_sky sensors into 2: 1 for the regular sensor, and 1 for the forecast, of which I don’t need all available conditions (left the #comments to display what’s not needed in my setup):

  - platform: darksky
    api_key: !secret darksky_key
    language: nl
    update_interval:
    # At least one of these must be specified:
      minutes: 30
    monitored_conditions:
      - hourly_summary
      - daily_summary
      - summary
      - icon
      - temperature
#      - temperature_high
#      - temperature_low
      - precip_type
      - precip_intensity
      - precip_probability
      - precip_accumulation
      - apparent_temperature
#      - apparent_temperature_high
#      - apparent_temperature_low
      - dew_point
      - wind_speed
      - wind_gust
      - wind_bearing
      - cloud_cover
      - humidity
      - pressure
      - visibility
      - ozone
      - precip_intensity_max
      - uv_index

  - platform: darksky
    api_key: !secret darksky_key
    language: nl
    name: dark_sky_forecast
    update_interval:
    # At least one of these must be specified:
      hours: 1
    forecast:
      - 0
      - 1
      - 2
      - 3
      - 4
      - 5
    monitored_conditions:
      - summary
      - icon
#      - precip_type
      - precip_intensity
      - precip_probability
#      - precip_accumulation
#      - apparent_temperature
#      - dew_point
#      - wind_speed
#      - wind_gust
#      - wind_bearing
#      - cloud_cover
#      - humidity
#      - pressure
#      - visibility
#      - ozone
#      - minutely_summary
#      - hourly_summary
#      - daily_summary
      - temperature_high
      - temperature_low
#      - apparent_temperature_high
#      - apparent_temperature_low
#      - precip_intensity_max
#      - uv_index
#      - moon_phase
#      - nearest_storm_distance
#      - nearest_storm_bearing