Setting ELECTRICAL MASTER BATTERY:1 to on via js

Hi I have a blank gauge I am using to set simvars from the dataStore. I so far
have got it working and setting the fuel level, but my ulitmate aim to record
the state of each of the switches and tanks in the G36 and save these, so when
reloading the aircraft it’s how you left it. I am using the code as such

//load the left fuel tank from the dataStore or set full and record in dataStore
    var initLeftFuel = GetStoredData('G36XIP_LEFT_FUEL');
    if (initLeftFuel) {
      SimVar.SetSimVarValue("FUEL TANK LEFT MAIN QUANTITY", "number", Number(initLeftFuel));
    } else {
      SimVar.SetSimVarValue("FUEL TANK LEFT MAIN QUANTITY", "number", 40);
      SetStoredData('G36XIP_LEFT_FUEL', '40');
    }


    //load the right fuel tank from the dataStore or set full and record in dataStore
    var initRightFuel = GetStoredData('G36XIP_RIGHT_FUEL');
    if (initRightFuel) {
      SimVar.SetSimVarValue("FUEL TANK RIGHT MAIN QUANTITY", "number", Number(initRightFuel));
    } else {
      SimVar.SetSimVarValue("FUEL TANK RIGHT MAIN QUANTITY", "number", 40);
      SetStoredData('G36XIP_RIGHT_FUEL', '40');
    }

I’m now trying to set the battery master switch ELECTRICAL MASTER BATTERY:1
via

SimVar.SetSimVarValue("ELECTRICAL MASTER BATTERY:1", "number", 1);

or

SimVar.SetSimVarValue("ELECTRICAL MASTER BATTERY:1", "bool", true);

but this doesn’t work. In the SDK it shows it as being settable ELECTRICAL MASTER BATTERY | The battery switch position, true if the switch is ON. Use
a battery index when referencing. | Bool | TYPE_BOOL | Y | -
—|—|—|—|—|—
the documents also mention electrical keys and I wonder if this is where I am
going wrong? There is a key listed as KEY_TOGGLE_MASTER_BATTERY | battery
index | Toggle battery switch state
—|—|—
Do I need to set this as well? UPDATE: I’ve just used the simvarwatcher and I
can set (and turn on) the master battery switch via setting the simvar. I’m
running my code in the connectedCallback function. I wonder if I am being
over-written before the aircraft loads? Is there a command to check if
everything is loaded?

I was on the right track. My switch simvar was being over-written I put the
code in onFlightStart() and it turned on the battery switch. As a test this
works…

onFlightStart() {
    super.onFlightStart();
    SimVar.SetSimVarValue("ELECTRICAL MASTER BATTERY:1", "number", 1);
  }