Could icons change depending on the variable value in YAML?

Hello guys,

I’ve a short question about the item. I have to give you a bit of background information on this. I have wrote a programme that calculates the position of the sun depending on the longitude and latitude. This calculation is very extensive. As an intermediate result you also get the position of the earth on its orbit (ecliptic longitude Lambda). The position also reflects the time of year:

0° to 90°: Spring
90° to 180°: Summer
180° to 270°: Autumn
270° to 0°: Winter

Is it possible to display a separate icon in a widget with YAML depending on the four possibilities (seasons, see circle)?

And here my current YAML-Code:

component: oh-label-cell
config:
  header: Es ist gerade
  icon: sun_clouds # to be changed depends on the value of the variable L
  item: Tag

Thank you very much! I wish you merry chrismas!

Of course they can. Please see the many weather widgets posted in the community as examples.
Ther you will find expressions to replpace icons depending on the weather condition (iconID).

However, I don’t have an external weather app, but a own JS rule that calculates the data for me. So it is not possible to create an if query under icons like this:

icons = (if items.getItem('L').state > 0 && items.getItem('L').state <= 90) then  f7:spring, if ...

I would be very pleased to receive an example

Might have misunderstood your initial post, just wanted to give you examples how to change icons based on different item states.
Your rule could set your calculated season to a virtual item, which then could be used to change the icon.
Other option would be to use the season information from Astro Binding for setting the icon.
Many ways possible….

No, I’ve wrote a own JS-Script. I thought, YAML can change the icons depends from an item value. My idea was:

Calculate lambda → write to an item → assess the value in YAML and output various symbols depending on the lambda angle

Yes, you can.
You will find it in the widgets i have said earlier. Just check how icons are set based in state of iconId items.


                      - component: f7-icon
                        config:
                          f7: "=(items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '01d') ? 'sun_max' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '01n') ? 'moon_stars' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '02d') ? 'cloud_sun' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '02n') ? 'cloud_moon' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '03d') ? 'cloud' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '03n') ? 'cloud' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '04d') ? 'cloud' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '04n') ? 'cloud' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '09d') ? 'cloud_heavyrain' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '09n') ? 'cloud_heavyrain' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '10d') ? 'cloud_sun_rain' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '10n') ? 'cloud_moon_rain' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '11d') ? 'cloud_sun_bolt' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '11n') ? 'cloud_moon_bolt' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '13d') ? 'cloud_snow' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '13n') ? 'cloud_snow' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '50d') ? 'cloud_fog' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '50n') ? 'cloud_fog' : '?'"

You can use this for oh-icon too….

Many thanks. I understand. I will try it, but now: It’s christmas time. :slightly_smiling_face:

:wink: Merry Christmas :+1:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.