Nextion Display Touch button 2 way with Home Assistant

Is the a way to create buttons on the Nextion display that will also show the currect status with manual wall switches. So far all the examples only show the buttons on the screen but it does not reflex the correct status when you turn on the light on the HA or wall switches. Any sample yaml files would be great.

ESPHome supports these displays.

Thanks for replying. I finally figure out how do do this by using the binary sensors.

Hello MrTea,

I also would lik to show the current status of the switches on the Nextion display. Can you maybe explain to me how you have accomplished this?

Regards,

Huub

1 Like

how did you do it? could you show some example code?

1 Like

Hi @MrTeaIOT
Can you let us know how you managed to get it working. Please.

1 Like

I was searching on how to get this done when I came upon this topic a few weeks ago. With some research I got the following:

binary_sensor:
  - platform: nextion
    name: name
    page_id: pagenumber
    component_id: nextioncomponentnumber
    id: yournextioncomponentname
    on_click:
      then:
        - homeassistant.service:
            service: light.toggle
            data:
              entity_id: light.yourlight

  - platform: homeassistant
    entity_id: light.yourlight
    id: somename
    on_state:
      then:
        - lambda: |-
            if (id(somename).state) {
            id(disp1).send_command_printf("yournextionpiccomponent.pic=yourONpicnumber");
            } else {
            id(disp1).send_command_printf("yournextionpiccomponent.pic=yourOFFpicnumber");
            }

So instead of a button I used a nextion picture frame. This picture also has a “on press” and “on release”. U have to check the boxes “send component ID” for both of these.

The first binary sensor is the button function for these inputs. So when the picture gets clicked (on_click) the light gets toggled.

The second binary sensor is for updating the state of the light to the nextion display. Whenever the state of the light changes, it checkes in what state the light is and updates the picture in the frame. The same frame we used as a button.

Only downside yet:
I am using a D1 mini, when I reset my board (f.e. after uploading my esphome scetch) the code doesnt update the picture frame to the actual value of the light. It only changes after you switch the corresponding light, because of the on_value. This can either be from the HA dashboard, the nextion screen or wherever you switch your lights.

I hope this was usefull for you guys. If you got any questions I would love to hear them.

1 Like