Detect dark or light theme from rules

Hi,

From rules, I can detect the theme that I’m using? I want to generate grafana graphs according the theme I’m using…

Best Regards,
Fernando Gomes

The short answer is no, of course not. Given that you can have any number of browsers and/or phone apps up showing your OH’s UI at the same time, which one of those computer’s theme be used by the rule? You could have one showing a dark theme and three showing a light theme.

In general, nothing in Rules knows anything about who is logged in to a UI or anything specific about the UI that a user is logged in as.

The one that call an item, for example… In you example, I want one showing dark (in rules) and three showing light.

Thanks, it’s a good feature for future, right now, I’ve one phone dark, that shows me light grafana graphs… because I’ve the rest of the phones an light.

Thanks again.

But there is only one rule. So your three light themed UIs will then start showing dark charts. Or worse, the charts will flicker between dark and light as the rule flips between them.

I think the likelihood of that happening is slim to none. It would be a huge effort that would need to be synchronized across multiple projects. And, as I mentioned, it wouldn’t work in the end anyway, at least not for Grafana. However, note, that if you use the MainUI built in charting the graphs will follow the theme.

Or your rule that generates the Grafana charts can generate both the light and dark versions and in MainUI, where you can determine whether you are showing the light or dark theme, you can choose the dark or light version of the chart as is appropriate.

1 Like

I’m using the basicui because his structure. But in the MainUI how I can do that?

Thanks,

There are a number of tutorials on the forum. There is a variable and expressions you can use the test that variable and select which image to load as appropriate. Though, the built in charts for MainUI are very good. I abandoned Grafana a long time ago.

In Grafana you can change the theme on the fly with &theme=lignt or &theme=dark in the URL:

:heart: :computer: Grafana - change from dark mode to light mode from URL GET parameter - Dirask

In UI expressions the dark mode setting can be retrieved with themeOptions.dark and it incidentally either dark or light which Grafana expects in its parameter.

So you can set the URL of the webframe widget to e.g.

="https://play.grafana.org/d/000000012/grafana-play-home?orgId=1&theme=" + themeOptions.dark
1 Like