Displaying weather symbol on Nextion

Hello, I am currently working on a project where I am using the Sonoff NSPanel device integrated with ESPHome and Nextion Editor to create a user interface. Everything has been going smoothly so far, but I’ve encountered a roadblock when trying to display a weather symbol on the screen.

I have successfully connected the Sonoff NSPanel to my ESPHome project and have been able to display other elements on the screen using the Nextion Editor. However, when I try to display the weather symbol, my code doesn’t seem to work as expected.
- platform: homeassistant id: weather_symbol entity_id: weather.home on_value: then: - wait_until: switch.is_on: nextion_init - lambda: |- int symbol=8; // 5 is a empty box. if (id(weather_symbol).state == "clear-night") { symbol=9; } else if (id(weather_symbol).state == "cloudy") { symbol=10; if (id(sun_sun).state == "below_horizon") { symbol=9; } } else if (id(weather_symbol).state == "fog") { symbol=11; } else if (id(weather_symbol).state == "hail" || id(weather_symbol).state == "snowy-rainy") { symbol=15; } else if (id(weather_symbol).state == "lightning") { symbol=14; } else if (id(weather_symbol).state == "lightning-rainy" || id(weather_symbol).state == "exceptional") { symbol=21; if (id(sun_sun).state == "below_horizon") { symbol=20; } } else if (id(weather_symbol).state == "partlycloudy") { symbol=16; if (id(sun_sun).state == "below_horizon") { symbol=17; } } else if (id(weather_symbol).state == "pouring") { symbol=12; } else if (id(weather_symbol).state == "rainy") { symbol=18; } else if (id(weather_symbol).state == "snowy") { symbol=13; } else if (id(weather_symbol).state == "sunny") { symbol=22; if (id(sun_sun).state == "below_horizon") { symbol = 9; } } else if (id(weather_symbol).state == "windy" || id(weather_symbol).state == "windy-variant") { symbol=23; } else { symbol=16; } id(disp1).send_command_printf("Thermostat.weather_symbol.pic=%i", symbol);
I use Picture component in Nextion Editor, objname is weather_symbol and number in pic indicates which image should be displayed.
Code is installed correctly, but weather_symbol is still a default image.
I would greatly appreciate any guidance or suggestions to help me resolve this issue.

Hi and welcome. You have sort have got the idea about posting your yaml - but not quite right. It should look the same in your post as in the ESPHome editor, i.e.:

sensor:
  - platform: homeassistant  
    id: weather_symbol 
    entity_id: weather.home 
    on_value: 
      then: 
        - wait_until: 
            switch.is_on: nextion_init 
        - lambda: |- 
            int symbol=8; // 5 is a empty box. 
            if (id(weather_symbol).state == "clear......  
            # etc...

yaml is all about indentation and if we can’t see that it makes it impossible to debug.

- platform: homeassistant

    id: weather_symbol

    entity_id: weather.home

    on_value:

      then:

        - wait_until:

            switch.is_on: nextion_init

        - lambda: |-

            int symbol=8; // 5 is a empty box.

            if (id(weather_symbol).state == "clear-night") {

              symbol=9;

            } else if (id(weather_symbol).state == "cloudy") {

              symbol=10;

              if (id(sun_sun).state == "below_horizon") {

                symbol=9;

              }

            } else if (id(weather_symbol).state == "fog") {

              symbol=11;

            } else if (id(weather_symbol).state == "hail" || id(weather_symbol).state == "snowy-rainy") {

              symbol=15;

            } else if (id(weather_symbol).state == "lightning") {

              symbol=14;

            } else if (id(weather_symbol).state == "lightning-rainy" || id(weather_symbol).state == "exceptional") {

              symbol=21;

              if (id(sun_sun).state == "below_horizon") {

                symbol=20;

              }

            } else if (id(weather_symbol).state == "partlycloudy") {

              symbol=16;

              if (id(sun_sun).state == "below_horizon") {

                symbol=17;

              }

            } else if (id(weather_symbol).state == "pouring") {

              symbol=12;

            } else if (id(weather_symbol).state == "rainy") {

              symbol=18;

            } else if (id(weather_symbol).state == "snowy") {

              symbol=13;

            } else if (id(weather_symbol).state == "sunny") {

              symbol=22;

              if (id(sun_sun).state == "below_horizon") {

                symbol = 9;

              }

            } else if (id(weather_symbol).state == "windy" || id(weather_symbol).state == "windy-variant") {

              symbol=23;              

            }

            else {

              symbol=16;

            }

            id(disp1).send_command_printf("Thermostat.weather_symbol.pic=%i", symbol);

Your logic looks fine - maybe someone with a Nextion display can chime in with an idea. I would change the topic title to include the fact that this is Nextion as they have their own user-base who may not spot the topic.

There is also a quiet long thread on the Sonoff panel that may be worth a look.

I have almost the samecode for my nspanel, except for the last ‘else’ presenting symbol 16…is that your ‘default’ one? Or…is the one you call ‘default’ anywhere in this picture set?

Default one that is set in Nextion Editor is 19 and that one is being displayed.

Are other HA data properly displayed? I compared via notepad++ and I can only assume that you are not getting the data from the sensor

anything in th elog? after flashing it?

Example, I setup logging via esphome and then changed the state of my weather sensor in HA…this is shown and immediately changed the panel symbol

Yes, I use HA to display temperature and it is displayed correctly.
[C][homeassistant.text_sensor:023]: Homeassistant Text Sensor ‘sun_sun’
[C][homeassistant.text_sensor:024]: Entity ID: ‘sun.sun’

Again…logs… and have you defined the weather_symbol as a TEXT sensor too?

Logs of your WEATHER sensor …sun has nothing to do with it neither for temp (but you know that)

No, I have not.

so…try that then I guess :slight_smile:

But, how to do that?

I assumed you had a group for that, like this one

text_sensor:
  # Weather symbol, HA weather entity to pull data from
  - platform: homeassistant
    id: weather_symbol
    entity_id: weather.mytown
    on_value:
      then:
        - wait_until:
            switch.is_on: nextion_init
        - lambda: |-
            int symbol=5; // 5 is a empty box.
            if (id(weather_symbol).state == "clear-night") {
......

Yes, I have a group for that and code for weather symbol is inside that group.

so what happens in the log if you update the state for weather.home ?

[C][homeassistant.text_sensor:023]: Homeassistant Text Sensor 'weather_symbol' [14:15:22][C][homeassistant.text_sensor:024]: Entity ID: 'weather.home'
I am not sure where I can find that in the log.

open the log, open another window HA dev tools and go to states tab, find weather.home and update the state…not sure if this is too cryptic as not sure how far your knowledge goes …not meant patronising