I am playing with the configuration of the floorplan and I have a question that probably you can answer me…
The idea is to show an icon (light off) when the light is turned off and after click on it, change that icon for another one (light on) and viceversa. Both icon shall share the same home assistant entity.
This one when off:
That one when on:
In this case, I know that they are very similar and the colour can be filled using the .css file, but how can I do it with different icons?
I have tried what it is specified in README.md but the icon appears in the incorrect place. Does anybody faced the same and how do you fix it?
Below is an example of using dynamic images which are swapped out at runtime, based on the sensor's current state. In the example below, the sensor.home_dark_sky_icon entitiy is mapped to a <rect> in the SVG file with the same id (which simply acts as a placeholder). Whenever the temperature sensor changes state, the image_template is evaluated to determine which SVG image should be emebedded within the bounds of the <rect>. Also you need to make sure that the placeholder is placed directly within the svg (e.g. not in a layer in inkscape) or else the calculated coordinates will be wrong.
groups:
- name: Dark Sky Sensors
entities:
- sensor.home_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";
'
I have been able to do what I want but now the problem is that the icon appears with incorrects coordenates. Did you face the same problems? I guess this issues is more related to inkscape than floorplan config.
Yeah, that code looks good. Coordinates shouldn’t change, since it’s just replacing the SVG, but if the images are different aspect ratios, like one is taller than the other or something, it will look weird/out of place. Are you sure that’s not what is happening?
Oh, and in Inkscape, make sure your rectangle has the ID of “light.lampara_salon”