Tilt function with LSM6DS3 not showing the right values

The built-in tilt detection is extremely limited.

Since you are already reading the acceleration values, why not just calculate the two tilt angles and do whatever you want with them? It takes just a couple of lines of code: How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing-DFRobot

Assuming the Z axis is approximately vertical:

  roll = atan2(ay , az) * 57.3;  //in degrees
  pitch = atan2((- ax) , sqrt(ay * ay + az * az)) * 57.3;