How do I get the current light vs dark mode in template code?

I’m trying to write some conditional icon color logic based on the light vs dark mode. How do I get the current value (to know if it’s light vs dark mode)?

For example if it’s light mode I’d want an icon to be black but if it’s fake mode I’d want an icon to be white

Because the theme can be set per browser, the only thing I can think to do is to is to install browser_mod. It has a binary sensor for each browser that will tell you if it’s in light or dark mode. The challenge is that you’d have to then have the logic set to show the right color to the right browser.

An alternative might be set every client to “backend selected” and then write an automation to force every client to change from dark to light (or light to dark) depending on the sun condition. Then you could use the sun condition logic for the icon color too.

I found a random blog post on changing themes based on the sun condition.

This one changes the entire theme, but you can just change the mode by using the mode keyword (light or dark).

Is it just one icon, or a domain/class of icons. If it’s the latter, you might be able to do it from the theme if you’re on 2023.02.0 or later. There have been some updates to color control for themes in that and later releases.