ESPHome and Nextion touch event

Hello All,

I am trying to design a bedside monitoring unit using Nextion display and ESPHome. Following is the simple UI that I designed.
image
Each dual state button calls home assistant service through ESPHome. My question is to keep the UI updated with current state of lights. When lights are switched on using physical switch, I want to send touch event externally to dual state button in Nextion. So the dual state button switches to pressed state showing actual state of light. Does anyone have any idea, how can I achieve that?

have you read this

all the hard work is done just pass some mqtt topic and it works

Thank you. Will take a look at this.

I have done it like this
It loads another pic if the state is changed

        if (id(status_slapen).state) {
           it.send_command_printf("slapen.pic=30");
        } else {
           it.send_command_printf("slapen.pic=26");
        }

Anyone can put some sample HMI file and yaml files to share? I am not able to get it to work with the same issues.

1 Like

where would we put this code? is it on the nextion editor? or yaml file on home assistant? or esphome config?