Custom Dark Sky Animated Weather Card

Update your card config like below:

     - type: custom:dark-sky-weather-card
        entity_sun: sun.sun
        entity_daily_summary: sensor.dark_sky_daily_summary
        entity_current_conditions: sensor.dark_sky_icon  
        entity_humidity: sensor.dark_sky_humidity
        entity_pressure: sensor.dark_sky_pressure
        entity_temperature: sensor.dark_sky_temperature
        entity_visibility: sensor.dark_sky_visibility
        entity_wind_bearing: sensor.dark_sky_wind_bearing
        entity_wind_speed: sensor.dark_sky_wind_speed
        entity_forecast_high_temp_1: sensor.dark_sky_daytime_high_temperature_1
        entity_forecast_high_temp_2: sensor.dark_sky_daytime_high_temperature_2
        entity_forecast_high_temp_3: sensor.dark_sky_daytime_high_temperature_3
        entity_forecast_high_temp_4: sensor.dark_sky_daytime_high_temperature_4
        entity_forecast_high_temp_5: sensor.dark_sky_daytime_high_temperature_5
        entity_forecast_low_temp_1: sensor.dark_sky_overnight_low_temperature_1
        entity_forecast_low_temp_2: sensor.dark_sky_overnight_low_temperature_2
        entity_forecast_low_temp_3: sensor.dark_sky_overnight_low_temperature_3
        entity_forecast_low_temp_4: sensor.dark_sky_overnight_low_temperature_4
        entity_forecast_low_temp_5: sensor.dark_sky_overnight_low_temperature_5
        entity_forecast_icon_1: sensor.dark_sky_icon_1
        entity_forecast_icon_2: sensor.dark_sky_icon_2
        entity_forecast_icon_3: sensor.dark_sky_icon_3
        entity_forecast_icon_4: sensor.dark_sky_icon_4
        entity_forecast_icon_5: sensor.dark_sky_icon_5

There was a breaking change that fixed the DarkSky component.

1 Like

Working fine, thanks !

I try add it to my beta HA 0.84.0b4 with newer UI Lovalece editor and i can not add this.
When add new card with this:

  • type: custom:dark-sky-weather-card
    entity_sun: sun.sun
    entity_daily_summary: sensor.dark_sky_daily_summary
    entity_today_summary: sensor.dark_sky_hourly_summary
    entity_current_conditions: sensor.dark_sky_icon
    entity_humidity: sensor.dark_sky_humidity
    entity_pressure: sensor.dark_sky_pressure
    entity_temperature: sensor.dark_sky_temperature
    entity_feelstemp: sensor.dark_sky_apparent_temperature
    entity_visibility: sensor.dark_sky_visibility
    entity_wind_bearing: sensor.dark_sky_wind_bearing
    entity_wind_speed: sensor.dark_sky_wind_speed
    entity_forecast_high_temp_1: sensor.dark_sky_daytime_high_temperature_1
    entity_forecast_high_temp_2: sensor.dark_sky_daytime_high_temperature_2
    entity_forecast_high_temp_3: sensor.dark_sky_daytime_high_temperature_3
    entity_forecast_high_temp_4: sensor.dark_sky_daytime_high_temperature_4
    entity_forecast_high_temp_5: sensor.dark_sky_daytime_high_temperature_5
    entity_forecast_low_temp_1: sensor.dark_sky_overnight_low_temperature_1
    entity_forecast_low_temp_2: sensor.dark_sky_overnight_low_temperature_2
    entity_forecast_low_temp_3: sensor.dark_sky_overnight_low_temperature_3
    entity_forecast_low_temp_4: sensor.dark_sky_overnight_low_temperature_4
    entity_forecast_low_temp_5: sensor.dark_sky_overnight_low_temperature_5
    entity_forecast_pop_1: sensor.dark_sky_precip_probability_1
    entity_forecast_pop_2: sensor.dark_sky_precip_probability_2
    entity_forecast_pop_3: sensor.dark_sky_precip_probability_3
    entity_forecast_pop_4: sensor.dark_sky_precip_probability_4
    entity_forecast_pop_5: sensor.dark_sky_precip_probability_5
    entity_forecast_icon_1: sensor.dark_sky_icon_1
    entity_forecast_icon_2: sensor.dark_sky_icon_2
    entity_forecast_icon_3: sensor.dark_sky_icon_3
    entity_forecast_icon_4: sensor.dark_sky_icon_4
    entity_forecast_icon_5: sensor.dark_sky_icon_5
    entity_forecast_sum_1: sensor.dark_sky_summary_1
    entity_forecast_sum_2: sensor.dark_sky_summary_2
    entity_forecast_sum_3: sensor.dark_sky_summary_3

But i can not save it…

I don’t understand the question. What’s the error you’re having? You can’t save it? Or it doesn’t display? I don’t know anything about the beta releases of HA, is there a reason why you’re using it?

I have the same problem on Chrome. This card uses a lot of CPU resources and kills my battery. Any way to improve this?

@plantoschka It looks like it is the animated icons causing the high cpu usage. My CPU jumps 20% when using the animated vs static icons. If the CPU usage is concerning then I would suggest switching to the static version of the icons.

I like the idea of the daily summary but think it takes up too much room at the bottom of the card. I added tooltips to each of the forecast days that allow you to hover over the day and receive the daily summary text. This also works on mobile devices simpy by touching the individual day.

image

3 Likes

Wow good idea. Any chanche to see sources? Thanks

As I was trying to respond @itajackass who asked to see code on how tooltips were implemented, I noticed that I can no longer make changes to my original post that started this thread. Apparently this is by design of the admins (see this post: Edit Original Post?). I am not going to weigh in on whether this is a good or bad policy, it is what it is… Unfortunately it means that the code in that post, which no longer works due to the many changes to HA and Lovelace along the way, cannot be corrected.

So, for those interested, I have posted the current version of my card on GitHub. You can get it here:
dark-sky-weather-card.js

For installation / configuration instructions please see the following file: Readme

Please note that my version of the card does not contain all of the changes that others have made to the card. It is based on the original I posted that started this thread. I plan on reviewing the changes that people have made and potentially adding them to my card if appropriate. I will attempt to keep this post updated as I make changes.

This version works with 0.84. and incorporates tooltips to show the daily summary information.

image

Note that in my version of the card I add an extra forecast day (0). This was in response to a breaking change that was made a couple of versions ago. The original platform provided the 0 (current day) forecast items without explicitly requesting them. The breaking change made this work like the rest of the forecast days which also meant that the entities for forecast day 0 now had a _0 appended to them. This is important so that the overnight low forecast can be correctly set for each day. eg: Day 1’s overnight forecast should come from forecast 0 to match the way it is displayed on the DarkSky website.


Corrected / Added 12 Dec 18

  • Fixed Pressure UOM. The value returned from DarkSky is in millibars so the UOM now states mbar.
  • Added Tooltips for daily summary

Added 13 Dec 18

  • Added configuration flag capability
  • Added tooltips flag (turns daily summary tooltips on or off)
  • Added static_icons flag (switches between animated and static icons)

Added 14 Dec 18

  • Added sunset flag. Allows display of sunset and sunrise icons.
  • Added locale flag. Controls display of day names and time formats.

Added 16 Dec 18

  • Tooltips now match icon color scheme (change to .css file)
  • WInd direction localization now works for en, fr, it and de.

Modified 21 Dec 18

  • Refactored the entire card. It is now based on the light weight LitElement class instead of the HTMLElement class.
  • Moved all CSS code into the .js file. (The .css file is no longer needed.)
  • Added several configuration options for controlling the look and feel of the tooltips.

Special note: If you use this version and beyond you must change the resource type for the card to module from js. Failure to do so will result in the card not loading and an error thrown stating there is an invalid token on line 1.

resources:
  - type: module
    url: /local/custom_ui/dark-sky-weather-card.js?v=7.2

Old Instructions (prior to 21 Dec Update)

I will leave these in place in case anyone wants to see how tooltips can be implemented but these notes do not reflect how the card currently works.

For those interested in implementing tooltips in other versions of the card, it is probably easiest to use the dark-sky-weather-card.js file linked above as a reference. Below are the modifications I made to it.

  1. Modify each forecast object by adding a entity summary attribute (last line in block below to each day)
const forecast1 = { date: forecastDate1,
               condition: this.config.entity_forecast_icon_1,
                temphigh: this.config.entity_forecast_high_temp_1,
                 templow:  this.config.entity_forecast_low_temp_1, 
                 summary: this.config.entity_summary_1, };
  1. Add another css class to the ‘daily’ container (I called mine fcasttooltip)
  <div class="forecast clear">
      ${forecast.map(daily => `
          <div class="day fcasttooltip">
  1. Add the following line

<span class="fcasttooltiptext">${hass.states[daily.summary].state}</span>

As seen below:

image

The dark-sky-weather-card.css file also needs modification to implement the visibility and style of the tooltip class. Here are are the additions to the file:

dark-sky-weather-card.css (only showing additions)

.fcasttooltip {
  position: relative;
  display: inline-block;
}

.fcasttooltip .fcasttooltiptext {
  visibility: hidden;
  width: 110px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;

  /* Position the tooltip */
  position: absolute;
  z-index: 1;
  bottom: 50%;
  left: 0%; 
  margin-left: -5px;
}

.fcasttooltip .fcasttooltiptext::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: black transparent transparent transparent;
}

.fcasttooltip:hover .fcasttooltiptext {
  visibility: visible;
}

Also make sure to pass in the summary entities in ui-lovelace.yaml

entity_summary_1: sensor.dark_sky_summary_1
entity_summary_2: sensor.dark_sky_summary_2
entity_summary_3: sensor.dark_sky_summary_3
entity_summary_4: sensor.dark_sky_summary_4
entity_summary_5: sensor.dark_sky_summary_5
4 Likes

Thanks. Replaced with static icons. They also look beautiful and I don’t need the animated effect.

Really love this.
Is it possible to remove the 3-day summary at the bottom of the card?

yup, just remove this from the .js file

      <span class="threedaysum">
          <span style="font-weight:bold">${forecast[0].date}:</span> ${hass.states[this.config.entity_forecast_sum_1].state}<br>
          <span style="font-weight:bold">${forecast[1].date}:</span> ${hass.states[this.config.entity_forecast_sum_2].state}<br>
          <span style="font-weight:bold">${forecast[2].date}:</span> ${hass.states[this.config.entity_forecast_sum_3].state}<br>
      </span>      
1 Like

The tooltip thing is really cool. I will probably play around with it.
No worries about adapting my changes, I really liked the card, but there were a few things that I wanted to add/change for my purposes, and it kinda snowballed from there. Was a good learning experience.

I do think the language stuff I added is pretty useful so that others don’t need to edit the .js file. They just need to edit the yaml file.

Reading your post though, I’m trying to understand the overnight low thing. So forecast_0 (high and low) are both for today. And forecast_1 high is tomorrow daytime, and forecast_1 low is tomorrow night time. But you’re saying that the forecast_0 corresponds to the low for tomorrow hence why you’re putting those together.

Great stuff here. I am just about to move over to using Lovelace and this is the second custom card I have played around with. I currently have Lovelace: Group card working, yet I cannot get this custom card to work.
I have copy/pasted all the configs (.js, .css, darksy sensor, card) from above and also added

    - url: /local/custom_ui/dark-sky-weather-card.js
      type: js

to the ui-lovelace.yaml however I keep getting this error

https://XXXXXX.com/local/dark-sky-weather-card.js:17:13 TypeError: hass.config.core is undefined

Any chance I could get some pointers on how to solve this error? Is there any other configuration that I missed?

@m.p.frankland would an option to have either static or animated icons be possible? I utilise the animated icons and static icons in other places so it doesn’t make sense to just replace the animated with static.

@cjsimmons No need to actually replace the icons… Assuming you have both sets of icons in a directory structure like weather_icons/animated and weather_icons/static, simply replace the references in the dark-sky-weather-card.js file. There are two places that need to be updated. Replace the word animated with the word static in the following two lines of code.

<span class="icon bigger" style="background: none, url(/local/icons/weather_icons/animated/${weatherIcons[currentConditions]}.svg) no-repeat; background-size: contain;">${currentConditions}</span>

<br><i class="icon" style="background: none, url(/local/icons/weather_icons/animated/${weatherIcons[hass.states[daily.condition].state]}.svg) no-repeat; background-size: contain;"></i>

On a related note I am looking at how to pass flags into the card from the ui-lovelace.yaml file. If I can figure that out It would be possible to conditionaly have either set based on a setting.

It sounds like you are using the dark-sky-weather-card.js code from the original post. Unfortunately, there was a breaking change in Lovelace a few revisions ago that broke that code. As I can no longer edit that original post, I can’t update the code listed there. Please use the card source referenced in this post Custom Dark Sky Animated Weather Card. It has corrections that fix that error.

You will also need to add a version to your ui-lovelace.yaml file to get the new version to load. For example:

resources:
  - url: /local/custom_ui/dark-sky-weather-card.js?v=6.8
    type: js

Note the v=6.8 Everytime you change the card source code you must use a different v= number in order for Lovelace to realize that the card has changed. It doesn’t matter what the number is, it just needs to be different than the previous number. You can start at 1.0 as you don’t currently have a v= number specified.

Too easy. Now to decide if I like static or animate… :thinking:

Yah, The language stuff you added does seem pretty helpful. It is definitely one of the updates I would like to make to the base code of the card. Any issue with me “borrowing” your code ?

As far as the forecast goes, The way to think about it is:

Day 0 Forecast High = Today’s forecasted high temp
Day 0 Overnight Low = Tonight into tomorrow morning low temp
Day 1 Forecast High = Tomorrow’s forecasted high temp
Day 1 Overnight Low = Tomorrow night into Day 2’s morning low temp
etc …

The confusion is because the overnight low spans two distinct days. In reality it is really up to the individual if they want the low to be the morning low or night low. The DarySky site uses morning low so I tried to match that.

To add to the confusion the card shows the high temp first (on top). If the temps were displayed side by side from low to high it might make more intuitive sense… (hmmm… maybe a change to the card there)

Perfect! I had previously used the code from the original post, however I did switch to the new code and it still was not working. I had no idea about the version number and I was wondering why it was showing up in different people’s code. I also had my darksky sensor configured with a “name” which was causing some troubles. It now works great! Many thanks!