OK, I finally have it all figured out, so here’s everything in case anyone wants to use this to make a battery indicator for floorplan in this style:
Create your svg file. You can use this if you want the specific style of indicator (100 colored segments in a red-to-green gradient) to insert into your svg file, there’s 100 rectangles that make up the colored circular bar (you might want to group them), and the circle obscuring those (id: battery_circle.p30_pro_battery_level
):
Minimal svg file with only the status bar and obscuring circle - you can copy-paste it into your svg file - can be found here: HomeAssistantConfig/battery.svg at 17dcdbcaa87f8d3811708f9b9326238bc39be7f0 · Aephir/HomeAssistantConfig · GitHub
Take note of a few things, in case you want to change/scale anything.
The radius of battery_circle.p30_pro_battery_level
is 28.786091
, and that informs the stroke-dasharray
and stroke-dashoffset
in the floorplan.yaml. These correspond to the circumference of the circle, given by c = 2 * pi * r
so in my case c = 2 * 3.14... * 28.786091 = 180.868
.
floorplan.yaml file
- name: Battery Level
entities:
- entity: sensor.p30_pro_battery_level
element: battery_circle.p30_pro_battery_level
tap_action: disable
hover_action: disable
state_action:
service: floorplan.style_set
service_data:
style: |
>
return `
stroke-dasharray: 180.868 180.868;
stroke-dashoffset: ${-(180.868*(entity.state/100))};
transform-box: fill-box;
transform-origin: center;
transform: rotate(181.3deg);
vector-effect:"none" !important;
`;
You can of course add as many as you’d like by just adding svg objects and entity
/ element
lines under entities
. Also note that if you, like me, copied your floorplan.css from any of the examples, you’ll likely have in your css file:
svg, svg * {
vector-effect: non-scaling-stroke !important;
pointer-events: all !important;
}
This won’t work, you need to delete this (at least the vector-effect: non-scaling-stroke !important;
, although I’ve been recommended to not use *
or !important
at all in css!)
Now it’s just a few tweaks to make it look nicer, but the functionality is there. Thanks a lot to a few people who have helped with troubleshooting, especially @OzGav both here and in the github issue.