Diff between values

put node.warn() in the code to understand what is going on...

var TempD = flow.get("Temp-Diff") || 0;
node.warn("TempD = " + TempD);
if (TempD>8) {
  node.warn("TempD is > 8, setting msg.payload= 'on'");
  msg.payload='on'
} else if (TempD<=8) {
  node.warn("TempD is <= 8, setting msg.payload= 'off'");
  msg.payload='off'
}
return msg;

You really should read up...