NSPanel/Nextion Button Help - How to update state

I received a Sonoff NSPanel last night and have diligently bumbled through creating a custom 3x3 button grid to match a corresponding Lovelace dashboard.

Following this video I have all the buttons registering in HA.

Goal: I would like each of these dual-state Nextion buttons to correspond to HA entities (either switch or light domains) while following ON or OFF state in HA.

This is where I am coming up short. Looking through ESPHome docs it should support a set_state lamba call but this won’t compile. I am far beyond my depth and any guidance is appreciated.

  - platform: nextion
    name: $device_name bt0
    page_id: 0
    component_id: 2
    on_state:
      lambda: |-
       id(disp1).set_state(state,true,true)
Compiling /data/nspanel/.pioenvs/nspanel/src/main.cpp.o
/config/esphome/nspanel.yaml: In lambda function:
/config/esphome/nspanel.yaml:89:14: error: 'class esphome::nextion::Nextion' has no member named 'set_state'
        id(disp1).set_state(state)
              ^
1 Like

lol, spend far too much time banging my head on the wall trying all manner of combinations (below). Only to be fooled by letter case; doh! I don’t code, haha. But now changing the state of a light/switch in HA reflects in the icon (pic) value of the NSPanel. Yay!

id(disp1).send_command_printf("bright.pic = 2");
id(disp1).set_component_picture("bright.pic","3");
id(disp1).set_component_picture("page0.bright.pic","3");
id(disp1).set_component_picc("bright.pic",3);
id(disp1).set_component_picture("bright.val = 3");
id(disp1).set_component_picture("bright", "2");
id(disp1).set_component_pic("bright",3);
id(disp1).set_component_picc("bright.pic",3);
id(disp1).send_command_printf("bright = 0");
id(disp1).send_command_printf("bright",1);
id(disp1).set_component_value("bright = 0");
id(disp1).set_component_value("bright = 1");
id(disp1).set_component_value("bright",1);
int val_number = 1;
it.send_command_printf("bright.val=%d", val_number);

Now to try and get all these states synchronized on boot…

Will try to demo a gif when it is installed. Apparently my 1 gang box is too small by ~5mm :confused:

[edit] demo: NSPanel - Album on Imgur

Any suggestions on refreshing nextion entities on boot? That’s the last hurdle to posting demo to github

1 Like

I value and respect your opinion.

Did you find a resolution to your issue of synchronising the switch states with the NSPanel? I am in the same position now, I have a switch on my screen that controls a light in home assistant, but setting the state on boot to match what it is in Home Assistant without actually triggering the switch itself is a hurdle I am yet to overcome.

Also, of the different combinations you included above, which one was it that worked in your case?

Yes it was a matter of using on_boot while waiting for the HA API to be connected. I’ll edit this later with the code when at a PC.