Webform CiviCRM, add contact to a group programatically
After digging deeply into webform_civicrm, I've found that the hook to use is hook_webform_submission_insert

It's important to check that this hook is executed after webform_civicrm's one, so the contact is created first and then we can perform our own actions. We can alter execution order with hook_module_implements_alter

I couldn't access contact_id created in any webform_civicrm entities, so I had to get it from the table webform_civicrm_submissions where is saved

The source code:

// Be sure our module's hook is the last to be executed
function mymodule_module_implements_alter(&amp;$implementations, $hook) {
  if ($hook == 'webform_submission_insert') {
    $group = $implementations['mymodule'];
    unset($implementations['mymodule']);
    $implementations['mymodule'] = $group;
  }
}

function mymodule_webform_submission_insert($node, $submission){
  if (!empty($node-&gt;webform_civicrm)){
    if(... my condition based on $submission values ...){
      $sid = $submission-&gt;sid;
      $result = db_select('webform_civicrm_submissions', 'w')
        -&gt;fields('w', array('contact_id'))
        -&gt;condition('sid', $sid)
        -&gt;execute()
        -&gt;fetchAssoc();

      // contact_id is saved between '-'
      if($result['contact_id'])
        $contact_id = str_replace('-', '', $result['contact_id']);

      civicrm_api3('GroupContact', 'create', array('group_id' =&gt; $mygroup_id, 'contact_id' =&gt; $contact_id));
    }
  }
}




PS: org.civicoop.civiruleswebform looks like a nice alternative, but it has many dependencies (2 extensions and 4 modules need to be installed in Drupal to use it)