How does auto-trim work on fly-by-wire aircraft?
In fly-by-wire aircraft (to fix things, let's consider an A320), there is no such effort to maintain as you use sidesticks.


Let's be clear: there is no such effort on the pilot side, but the forces on the surfaces are still there and are taken care of by the electro-hydraulic actuators.


  
  In flight in normal law, how and when does the computer decide it must trim the plane? 
  What does it take into account to trim the plane?
  


I will answer these two together. And let's remember what written above: the actuators are taking care of the control surfaces loads, this means that part of the actuator authority is being used to control a static load.

In an ideal situation all the authority (coming from hydraulic pressure or coil current) can be dedicated to control transients: gusts, configuration changes, turn entering, turn leaving. If you are allocating part of this authority to keep level flight, a gust (for example) that otherwise would have been easily compensated for, will lead to a momentarily loss of coordination, reducing the comfort of the passengers.

That is what (mostly) you use to trim the aircraft: if your actuator is constantly (or on average over several seconds) applying a certain force in a certain direction, the system will use the trim functionality to remove said force while not altering the flight equilibrium.


  
  Does it anticipate the trim?
  


I have no public reference for this.


  
  What happen on the ground?
  


Usually you leave the aircraft with no trim.


  
  What happen if not in normal law (I guess auto-trim would be one of the feature unavailable in alternate law)?
  


Unless you are outside of normal law for actuator-related issues (power/hydraulic losses, for example) I see no reason why trimming would be unavailable, all that is required for trimming, as said above, is the average load on the actuators and trimming actuation capabilities.