I can configure the switch on an HA dashboard. When I toggle the dashboard switch the Nextion button toggles state. At least I see the button’s color change. However, when I press the button on the display, I don’t see the switch toggle in the HA dashboard.
If I define the dual-state button as a binary sensor:
I can configure the sensor on a HA dashboard and when I press the button on the Nextion Display it will change one time, from OFF to ON, on the dashboard. It won’t switch OFF on the dashboard when using the Nextion button.
Is anyone out there using the Nextion’s dual-state button with ESPHome?
With the update_interval specified the dual-state button’s state is forwarded up to HA and shown on the dashboard. Likewise if the dashboard switch is toggled it is reflected as such on the Nextion display.
Liffe is good.
The problem isnt update_interval and polling a switch state every second is unnecessary. Your basically sending a request every second that’s asking the device, “did the switch change”? “did the switch change”?
“did the switch change”? “did the switch change”?
Instead of asking each second, “are we there yet Dad”? over and over lagging it down.
You specifically force it to update only when the state changes. It specifically tells you how to do this in the nextion switch documentation. “Publish new state to HASS” is pretty clear about what it does.
Also, in your OP you keep referring to both “switch” and “button” as if they mean the same thing and they dont.
A switch and a button are two different things and they function differently. Its kind of important to know the difference especially if your asking a question. It can be very confusing to people reading it and trying to figure out which one you mean.
Hi Fallingaway24,
Would you be so kind to help me with some small code? I can’t use this dual state button, because of the problem was mentioned by vbphil. I don’t want to use update_interval oprion because of what you wrote. However, the lambda is not accpeted by ESPHome. It says [lambda] is an invalid option for [switch.nextion]…
Thanks in advance!
I made some progress on getting the Nextion Dual-State button to work without using the update_interval setting. The Nextion Editor calls it a button but I’m using the switch component in esphome. For now all I’ve done is write to the log so it isn’t performing any actions yet on the esp32 device. I’ll start working on that later.
Here’s what I see in the esphome log for my esp32 device. I pressed the button on and then off.
[18:54:17][D][switch:055]: 'mode_switch': Sending state ON
[18:54:17][I][nextion switch:182]: Hi Phil turned on
[18:54:17][D][nextion_switch:016]: Processed switch "page0.bMode" state ON
[18:54:23][D][switch:055]: 'mode_switch': Sending state OFF
[18:54:23][I][nextion switch:186]: Hi Phil turned off
[18:54:23][D][nextion_switch:016]: Processed switch "page0.bMode" state OFF
From the Nextion Editor here’s the code I put in the Touch Press Event. I also have unchecked the box for Send Component ID in both events. The dual-state button is set as global, is on page0, and its name is bMode.
printh 90
prints "page0.bMode",0
printh 00
prints page0.bMode.val,0
printh FF FF FF