Syncronise on/off button in dashboard when variable is changed in sketch

I use a dashboard button to set a global variable in my sketch which updates an external api. This works fine.

However, when the variable in the sketch is changed by a call to the api, the button is not changed. The variable changes but the button does not.

I’m obviously missing something - any help gratefully received.

bool valve_1_sync = 0;

// This is in Setup()

  thing["valve1"] << [](pson& in){
      if(in.is_empty()){
          in = valve_1_sync;
          
      }
      else{
          valve_1_sync = in;
          setServerValveStatus(1, valve_1_sync);  // api call
      }
  };

Hi! Not sure I understand your question correctly, are there two different apis in your setup? Can you further explain your data flows?

Essentially the boolean variable, valve_1_sync, can be set by a button in my dashboard as well as an external routine. When valve_1_sync is changed by an api call the button in the dashboard does not change to match it.