Custom Dark Sky Animated Weather Card

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!

Added configuration flag ability to the card. So far the following two flags are available.

  1. tooltips (Turns daily summary tooltips on and off)
  2. static_icons (switches between static and animated icons)

Flags are entered into ui-lovelace.yaml file which should allow for some interesting configuration changes without having to edit the source js file.

        entity_summary_4: sensor.dark_sky_summary_4
        entity_summary_5: sensor.dark_sky_summary_5
        tooltips: true
        static_icons: false

Did you test it on HA 0.84.1 with new lovelace with config in /.storage ?

HI,

followed all your install instructions with the latest (dl’d today) and this is what shows:

18

no temp…and no station name or location?

suggestion/feature request: please add sun up/sun down to your card? I use this in my other custom crd, and it really is a nice addition as is the feels like below the temp:

28

code:

const windBft = hass.states[this.config.entity_wind_force].state;
const forecast = entity.attributes.forecast.slice(0, 5);
const apparent_temperature = hass.states[this.config.entity_apparent_temperature].state;

var sunSetOrRiseA = new Date(hass.states[this.config.entity_sun].attributes.next_setting);
var sunSetOrRiseIconA = "mdi:weather-sunset-down";
var sunSetOrRiseB = new Date(hass.states[this.config.entity_sun].attributes.next_rising);
var sunSetOrRiseIconB = "mdi:weather-sunset-up";
// A == sunset   B == sunrise
if ( hass.states[this.config.entity_sun].state == "above_horizon" ) {
    // sun has risen, but hasn't set
    // sunset is today (no date displayed). sunrise is tomorrow (display date)
    // next is sunset == A
    
    sunSetOrRiseA = sunSetOrRiseA.toLocaleTimeString();
    var ssrI = sunSetOrRiseA.lastIndexOf(":");
    sunSetOrRiseA = sunSetOrRiseA.substr(0,ssrI) + sunSetOrRiseA.substr(ssrI+4);
    sunSetOrRiseB = sunSetOrRiseB.toDateString().substr(0,3) + " " + sunSetOrRiseB.toLocaleTimeString();
    ssrI = sunSetOrRiseB.lastIndexOf(":");
    sunSetOrRiseB = sunSetOrRiseB.substr(0,ssrI) + sunSetOrRiseB.substr(ssrI+4);
} else {
    // next is sunrise == B
    var ss = sunSetOrRiseA;
    if ( new Date().getDate() != sunSetOrRiseB.getDate() ) {
        // sun hasn't risen, and it's not same day
        // so display dates for both
        sunSetOrRiseA = sunSetOrRiseB.toDateString().substr(0,3) + " " + sunSetOrRiseB.toLocaleTimeString();
        sunSetOrRiseB = ss.toDateString().substr(0,3) + " " + ss.toLocaleTimeString();
    } else {
        // sun hasn't risen, but it's the same day
        // since rise and set are today, no dates displayed
        sunSetOrRiseA = sunSetOrRiseB.toLocaleTimeString();
        sunSetOrRiseB = ss.toLocaleTimeString();
    }
    var ssrI = sunSetOrRiseA.lastIndexOf(":");
    sunSetOrRiseA = sunSetOrRiseA.substr(0,ssrI) + sunSetOrRiseA.substr(ssrI+4);
    ssrI = sunSetOrRiseB.lastIndexOf(":");
    sunSetOrRiseB = sunSetOrRiseB.substr(0,ssrI) + sunSetOrRiseB.substr(ssrI+4);
    sunSetOrRiseIconA = "mdi:weather-sunset-up";
    sunSetOrRiseIconB = "mdi:weather-sunset-down";
}

this.content.innerHTML = `
  <span class="header" >${currentCondition}</span><span class="weather">${station}</span>
  <span class="icon bigger" style="background: none, url(/local/weather/animated/${weatherIcons[currentCondition]}.svg) no-repeat; background-size: contain;"> </span>
  <ul style="list-style-type:none">
    <li><span class="temp">${temperature}</span><span class="tempc"> ${getUnit('temperature')}</span></li>
    <li><span class="tempa">Feels like ${apparent_temperature}</span><span class="unitc"> ${getUnit('temperature')}</span></li>
  </ul>
  <span>
    <ul class="variations right">
        <li><span class="ha-icon"><ha-icon icon="mdi:water-percent"></ha-icon></span>${humidity}<span class="unit"> %</span></li>
        <li><span class="ha-icon"><ha-icon icon="mdi:gauge"></ha-icon></span>${pressure}<span class="unit"> ${getUnit('air_pressure')}</span></li>
        <li><span class="ha-icon"><ha-icon icon=${sunSetOrRiseIconB}></ha-icon></span>${sunSetOrRiseB}</li>
    </ul>
    <ul class="variations">
        <li><span class="ha-icon"><ha-icon icon="mdi:weather-windy"></ha-icon></span>Bft: ${windBft} - ${windBearing} ${windSpeed}<span class="unit"> ${getUnit('length')}/h</span></li>
        <li><span class="ha-icon"><ha-icon icon="mdi:weather-fog"></ha-icon></span>${visibility}<span class="unit"> ${getUnit('visibility')}</span></li>
        <li><span class="ha-icon"><ha-icon icon=${sunSetOrRiseIconA}></ha-icon></span>${sunSetOrRiseA}</li>
    </ul>
  </span>
  <div class="forecast clear">
      ${forecast.map(daily => `
          <div class="day">
              <span class="dayname">${(new Date(daily.datetime)).toLocaleDateString((navigator.language) ? navigator.language : navigator.userLanguage, {weekday: 'short'}).split(' ')[0]}</span>
              <br><i class="icon" style="background: none, url(/local/weather/animated/forecast/${weatherIcons[daily.condition]}.svg);"></i>
              <br><span class="highTemp">${daily.temperature}${getUnit('temperature')}</span>
              <br><span class="lowTemp">${daily.templow}${getUnit('temperature')}</span>
          </div>`).join('')}
  </div>`;

}

I have mixed experiences with changing the code of the custom card myself, so would like to ask if you could have a look, and update yours (if you would) yourself to keep it all in working order…

never mind the big -1 in the screen shot, it is a remnant of the transition to HA 0.84.1 and issues with the weather cards… --UPDATE–(fixed that for now, a and the temp in your card also. I had another cuts weather card in the yaml and it was listed in succession. Apparently the css didn’t like that? dont know if that is even possible, but now that I’ve split this view up, have 1 at the top and the other further down the view, the cards she alright.??):

01

and

06

station name, condition and sunrise/set…

Another update…

This version adds two new flags.

  1. sunset : this flag enables or disables the display of sunset and sunrise icons. (Defaults to false/off)
  2. locale : this flag controls the locale used to display day names and time formats. (Defaults to en/english)
 sunset: true

locale: fr

2 Likes

nice!
will test immediately.

please help me out, I am wondering why this currentConditions variable is not displayed at all unless you comment out the icon:

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

AS said before, I wanted it to show in my card, so changed the config to:

this.content.innerHTML = `
  <span class="header" >${currentCondition}</span><span class="weather">${station}</span>
  <span class="icon bigger" style="background: none, url(/local/weather/animated/${weatherIcons[currentCondition]}.svg) no-repeat; background-size: contain;"> </span>

  <ul style="list-style-type:none">
    <li><span class="temp">${temperature}</span><span class="tempc"> ${getUnit('temperature')}</span></li>
    <li><span class="tempa">Feels like ${apparent_temperature}</span><span class="unitc"> ${getUnit('temperature')}</span></li>
  </ul>
  <span>

maybe you could try and see what happend if you added that?

station is:

const station = entity.attributes.friendly_name;

I just added your code but I get the following error :

dark-sky-weather-card.js:132:47 Uncaught TypeError: nextSunRise.getDate is not a function

Any idea what’s up ?

I did copy your dark-sky-weather-card.js and lovelace config.

I’m having the same exact error.

@Mariusthvdb] The value of currentConditions is actually displayed… It’s just hidden behind the icon. The purpose is to show a value if something bad happens to the icon or if Dark Sky adds a condition that isn’t mapped to an icon.

Not quite sure what your “Station” is. You are referencing an object called entity. What is that object? Where does it come from ?

@Kaostral @Narfel Do you have the sun entity defined in your ui-lovelace.yaml

entity_sun: sun.sun

I do.

 - type: custom:dark-sky-weather-card
        entity_sun: sun.sun

Ok… looks like a bug… The sun was above the horizon when I wrote the code so this code path didn’t get thoroughly tested… will put out an update soon

If you comment out the 132 and 135 it “works”. So it has to be something about that method.

edit: man, you’re too fast :slight_smile:

I figured as much. Still, I want it to show always, sort of a header for the card… I might rethink the options then, and think of some default icon to show if the weather component goes wrong…

i use the buienradar component for this card.

  - type: custom:card-modder
    style:
      background-image: url("/local/lovelace/images/weather-background-[[ sun.sun.state ]].png")
      background-size: 100% 400px
      --primary-text-color: var(--primary-text-color)
      --secondary-text-color: var(--secondary-text-color)
      --paper-item-icon-color: var(--primary-text-color) #small variation icons
    card:
      type: custom:weather-card
      title: Modded Woensdrecht
      entity_weather: weather.woensdrecht
      entity_sun: sun.sun
      entity_apparent_temperature: sensor.jagti_windchill
      entity_wind_force: sensor.br_wind_force

which has the station name as attributes.friendly_name.