joBr99 / nspanel-lovelace-ui

Custom Firmware for NsPanel with the design of HomeAssistant's lovelace UI in mind, works with Tasmota.
GNU General Public License v3.0
883 stars 191 forks source link

[Feature Request] Dynamic icons from a template on the screensaver #951

Closed testerOfHardware closed 1 year ago

testerOfHardware commented 1 year ago

FEATURE DESCRIPTION

Pls implement the feature of showing template icons from homeassistant on a screensaver 2 or making me own template, that shows me a dynamic icon, depends on params. I have a garbage sensor, that shows me the correct icon depends on which garbage type i have to bring out in next days. This icon comes from homeassistant icon_template. In homeassistant i can see the icon normal, and works. On the nspanel it shows me just a circle with a exclamation mark.

ADDITIONAL CONTEXT

So in this way i tried what you wrote in a docu, that you can get icon from a template in this way:

 statusIcon2:
        entity: climate.wohnzimmer_boden
        icon: 'ha:{{ state_attr("climate.wohnzimmer_boden","current_temperature")}}'
If you want to display icons from a template you can put them between <I></I>

        icon: 'ha:{{ iif(is_state('light.kitchen', 'on'), '<I>mdi:flashlight</I>', '<I>mdi:flashlight-off</I>') }}'

but this shows me only the name of the icon, not the icon self.

I tried a simpler version, just to test it:

 screensaver:
      type: screensaver2
      entities: 
        - entity: weather.smarthome
        - entity: weather.smarthome
          type: 0
          name: test
        - entity: sensor.lightlevel_7_battery_level
          type: 1 
        - entity: sensor.abfall_reminder
          icon: 'ha:{{state_attr("sensor.abfallbio", "icon")}}'
        - entity: weather.smarthome
          type: 3

same result, just a text shows with the name of icon, not the icon self. In this example the icon is coming simple from the icon. I just wanted to test if i can get it through this template, and displaying the icon. But i get just a text with the name of the icon.
So i think, there is no option, to show an icon from a template.

If yes, could you put a working example, pls?

PANEL / FIRMWARE VERION

EU

joBr99 commented 1 year ago

this is an working example:

        icon: 'ha:{{ iif(is_state('light.kitchen', 'on'), '<I>mdi:flashlight</I>', '<I>mdi:flashlight-off</I>') }}'

assuming state_attr("sensor.abfallbio", "icon") is retuning an icon name, you probably need something like this:

icon: 'ha:{{<I>state_attr("sensor.abfallbio", "icon")</I>}}'

testerOfHardware commented 1 year ago

thx for the answer. I have only time to try it out on the weekend. so sorry for some days to answer.

But you example

icon: 'ha:{{<I>state_attr("sensor.abfallbio", "icon")</I>}}'

shows me only a dark space in the left column. I tried also to put it on the right side under the clock, also black space. The icon is mdi:leaf, so a normal material icon, that works in HA image

I also tried to set a color, still the space is black.

So it is a bug then for me. Or I have to take care of something on the icons that come on the screensaver?

joBr99 commented 1 year ago

Yes, only icons from here are available, however the leaf icon is there.

https://docs.nspanel.pky.eu/icon-cheatsheet.html

joBr99 commented 1 year ago

You can check templates in the Homeassistant Development tools.

Try this:

{{"<I>"+state_attr("sensor.abfallbio", "icon")+"</I>"}}