How is the battery power on the Airbus A340's electric system switched?
From A340 FCOM 1.24.20 P2 (REV 8):


  BAT 1 (2) pb sw
  
  Controls the operation of the corresponding Battery Charge Limiter
  
  AUTO: 
  
  The Battery Charge Limiter controls automatically the connection
  and the disconnection of the corresponding battery tot the DC BAT BUS
  by closing and opening of the battery line contactor. 
  
  
  The batteries
  are connected to the DC BAT BUS in the following cases:
  
  
  Battery voltage below 26.5 Volts (battery charge). The charging cycle ends when battery charge current goes below 4 Amperes (for 10 seconds on ground 30 minutes is flight)    
  On the
  ground (with speed below 50 knots) when batteries only are supplying
  the aircraft. 
  
  


My understanding is that for the DC BAT BUS this means when a button is set to AUTO the corresponding battery is connected when that battery needs to be charged or:


The aircraft has a speed below 50 knots AND
The only power source is batteries (i.e. no generators, APU or external power supply are connected to the electrical network)


A note further down mentions that the batteries are disconnected  when the voltage drops below 23 Volts for more than 16 seconds, in order to protect the battery from discharging completely.

For the DC ESS BUS it states: 


  
  The batteries are connected to the DC ESS BUS when batteries only are
  supplying
  
  
  in flight
  on the ground (speed below 50 knots) provided they are
  both selected auto
  
  


That clearly states that both push button switches need to be set to AUTO in order for the DC ESS BUS to be powered from the batteries on the ground.