The plugin adds the collapsed class to the sidebar when it is collapsed, so you can use that to check its status. Borrowing a function from this answer to check whether an element has a particular class (and assuming that your sidebar div has the id sidebar), you can toggle it like so:
var sidebar = L.control.sidebar('sidebar').addTo(map);
var sidebarDiv = document.getElementById('sidebar');
toggleSidebar = function() {
  if (hasClass(sidebarDiv,'collapsed')) {
    sidebar.open();
  } else {
    sidebar.close();
  }
}
function hasClass(element, cls) {
  return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
}
Example fiddle:
http://fiddle.jshell.net/nathansnider/gpqbvs50/