@kevinfcook Getting back to your idea about integrating the Dark Sky icons (Skycons). That looked promising, but I then noticed the positioning was out of whack on different devices, and even on different laptops, and Chrome was used in all cases. Ended up abandoning that idea. I don’t think there is good browser support for embedding non-SVG stuff (i.e. HTML5 canvas) into SVGs. Too bad Skycons aren’t available as SVG (from what I could see anyway).
Not all is lost though. I manged to get dynamic SVG images working in the floorplan. To test it, I found an alternative source for animated weather icons, and they are in SVG format:
I tried on several browsers, on different devices and it seems to work well. The only catch is that they don’t animate in the Microsoft Edge browser. I read some posts about this not being supported, but still need to look further into this. Not a problem - the icons are still there
In any case, below is how it looks. You can see the ‘partly cloudy’ weather icon (the rays around the sun spin around slowly).
The latest code on GitHub has been updated to support this. It was a relatively simple change is and is totally non-intrusive. The new functionality only kicks in if you add the relevant option in your floorplan config.
Below is an example of how to use it. As you can see, there is a new section image_template
that lets you write some rules around which image should be displayed based on the state of your entity. In this example, my entity is a Dark Sky weather sensor that I added in HA. Of course, I had to create the associated element in the SVG file, which I simply implemented as a `rect, as it’s only purpose is to serve as a placeholder (bounding box for the image being loaded). The dynamic image gets scaled to fit exactly within the SVG element.
groups:
- name: Dark Sky Sensors
entities:
- sensor.melbourne_dark_sky_icon
image_template: '
var imageName = "";
switch (entity.state) {
case "clear-day":
imageName = "day";
break;
case "clear-night":
imageName = "night";
break;
case "partly-cloudy-day":
imageName = "cloudy-day-1";
break;
case "partly-cloudy-night":
imageName = "cloudy-night-1";
break;
case "cloudy":
imageName = "cloudy";
break;
case "rain":
imageName = "rainy-1";
break;
case "snow":
imageName = "snowy-1";
break;
}
return "/local/custom_ui/floorplan/images/weather/" + imageName + ".svg";
'
One thing I found with the weather icons I mentioned above, is that the weather SVG files had the wrong case for the viewBox
attribute. It was originally all lower case, but the B
is supposed to be upper case. I changed it in all the files, and that allowed the image to resize properly.
<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="64"
height="64"
viewBox="0 0 64 64">
Anyway, this is ready to be used, so let me know if you give it a go.
BTW, this is actually a very powerful new feature. It means we finally have the ability to use dynamic images, with the ability to swap out different images based on the states of our entities.