For reference, this code creates a new temperature_sensor object named "_hotendSensor2," as an example. This name can be changed, as long as every instance of it is renamed to the name of your choosing. The parameters from lines 3 through 6 are the values assigned to the newly created temperature_sensor object. Refer to the datasheets for your chosen sensor to ensure correct configuration. The "gcode_id" is another variable that you can set to your preference, making sure that changes made to this variable name are made throughout the rest of the code snippet above.
The "gcode_macro" section serves to add functionality to the M105 command. This is done by simply renaming the existing M105 command to M99105 (also set to user preference). This newly created function runs M99105, to keep the unmodified M105 functionality intact, and then runs a check ensuring that the temperature values between the two temperature sensors are within 15 degrees Celcius of one another. You may alter that fluctuation margin of error by changing the "15.0" found in line 18. If any fluctuations outside of the desired range are detected, the printer will halt and shut down.
Finally, "[respond]" needs to be added in, as shown above. This allows for the use of M118, which is important in sending the status message into the serial monitor/ terminal, as soon as a fluctuation is detected. Without the inclusion of "[respond]," you may still get core functionality from this code, as long as lines 19 and 20, which contain the M118 commands, are removed.