Change Nextion Button State via Serial

Hello,

I am working on a project involving a 7" Nextion display and Arduino Mega.
They control motorized ball valves for an air system.

You can see my previous post here: I/O "States" not Maintaining - Programming Questions - Arduino Forum

Since then I have added a RTC so that at specific times of day, the main valve will turn on/off saving the compressor and machinery excess work.

The RTC works great and turns my relay on/off atthe right time, but since the main control is from the nextion display I want to change the button state during that time as well so everything is copacetic.

Here is the code in question:

if((now.hour()==13) && now.day()!=(1||7)){
    if(valve_states[0]==false){
      myNextion.sendCommand("v0.val=0");
      valve_states[0] = true;
      digitalWrite(valve_pins[0], LOW);
      }
     }

  if((now.hour()==14) && now.day()!=(1||7)){
    if(valve_states[0]==true){
      myNextion.sendCommand("v0.val=1");
      valve_states[0] = false;
      digitalWrite(valve_pins[0], HIGH);
      }
     }

v0 is the name of the button on my nextion, I have also tried using its ID like so:

myNextion.sendCommand("1.val=0");

If I remember correctly my nextion library may be different than most, but I have a pincode screen and logic that works great. The arduino reads the pincode inputs and if they are correct it sends the nextion to the valve control screen.

myNextion.sendCommand("page valves");

I have looked through the nextion instruction set and just cannot find the appriate command to change a button state...

Thanks for your help in advanced!!

I have looked through the Nextion instruction set and just cannot find the appropriate command to change a button state...

Nextion instruction set
Search for click
Note you have to both click and unclick a button otherwise you get strange results.

You sir are the Nextion-meister!

I tried it out, no errors or anything but I think that function just triggers the event, not the state of the DUAL STATE button. I should have been more clear on that, my apologies.

When a button is pressed it turns the valve on the map from green to red, signaling the operator it is closed. I am sure its changing the variables etc. I have set up, though.

You sir are the Nextion-meister!

I thank you :slight_smile:
(Just remember I know nothing about Nextion libraries)

Click works for me, try it in the simulator. However, be aware that you click then click again for a duel state button, so, for example:

click bt0,1
click bt0,1

Will change the state then change it back.

Sorry for the late response, this is a side project and got swamped with other things!

But this is SOLVED!!!

Thank you sir for your knowledge!

troyboy808:
Sorry for the late response, this is a side project and got swamped with other things!

But this is SOLVED!!!

Thank you sir for your knowledge!

You're welcome :slight_smile: