7 Day Weather Forecast

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

I originally had the problem that it was giving me Unknown for the state but quickly worked out it was the breaking change from min/max to daytime_high/overnight_low

But I can’t work out the days. They just stay as this:
image

I understand it’s probably because of a breaking change associated with dark_sky_friendly_names.py but not sure what exactly

This is the code in the python script

###############################################################################
# Author:      Alok R. Saboo
# Description:  This script takes the dark_sky forecast sensors and updates
#               their friendly_name to include the date and day.
#               https://github.com/arsaboo/homeassistant-config/blob/master/packages/weather.yaml
###############################################################################
dark_sky_entities = ["sensor.forecast_1", "sensor.forecast_2", "sensor.forecast_3",
                     "sensor.forecast_4", "sensor.forecast_5", "sensor.forecast_6",
                     "sensor.forecast_7"]
days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]

triggeredEntity = data.get('entity_id')
# logger.warning("trigger is {}".format(triggeredEntity))
now = datetime.datetime.now()
today = now.weekday()

if triggeredEntity is None:
    for entity_id in dark_sky_entities:
        # copy it's state
        state = hass.states.get(entity_id)
        newState = state.state
        forecastdays = int(entity_id.split('_')[1])
        day = datetime.timedelta(days = forecastdays)
        forecastdate = now + day
        newEntityPicture = state.attributes.get('icon')
        if today + forecastdays > 6:
            newDay = days[today + forecastdays - 7]
        else:
            newDay = days[today + forecastdays]
        # Set states
        hass.states.set(entity_id, newState, {
            'friendly_name': "{} ({}/{})".format(newDay, forecastdate.month, forecastdate.day),
            'icon': newEntityPicture,
        })
else:
    state = hass.states.get(triggeredEntity)
    newState = state.state
    forecastdays = int(triggeredEntity.split('_')[1])
    day = datetime.timedelta(days = forecastdays)
    forecastdate = now + day
    newEntityPicture = state.attributes.get('icon')
    if today + forecastdays > 6:
        newDay = days[today + forecastdays - 7]
    else:
        newDay = days[today + forecastdays]
    # Set states
    hass.states.set(triggeredEntity, newState, {
        'friendly_name': "{} ({}/{})".format(newDay, forecastdate.month, forecastdate.day),
        'icon': newEntityPicture,
    })

I just updated to 0.92 this morning and it looks like all my forecasts states are set to unknown and there are messages in the logs for each day that failed.

Card
image

Logs

I can’t find any of the sensor.forecast_N sensors in my entities lists. I wonder if the dark_sky component is in flux at the moment…

I saw a couple of entities had changed. Easiest way is to check the entity names in dev tools and amend lovelace to match.

Same here. I know it wasn’t an entity name change because none of my sensor values aren’t showing the ##/##/## output.

This change happened in 0.91, did you update your entities to accommodate this breaking change?

“Dark Sky provides hourly forecasts for various monitored conditions. This change creates new sensors for each hourly forecasted condition with suffix _<hour>h while adding the suffix _<day>d to the daily forecasted conditions. For example, now a sensor.dark_sky_summary_<day>d and sensor.dark_sky_summary_<hour>h will be created if the forecast and hourly_forecast parameters are populated. (@rtclauss - #21820) (darksky docs)”

Is there actually a way to limit the temperature display to integer numbers?

Yup, that was it. Thanks DetroitEE. I had previously adjusted it for the “overnight_low” and “daytime_high” change but the added ‘d’ was unexpected and overlooked (by me). :stuck_out_tongue: