Underfloor heating with Devireg and NTC Sensors

Underfloor heating with Devireg and NTC Sensors

Control the Shelly based on readings from any NTC temperture sensor (DEVIREG)

Det er muligt at bruge din eksisterende gulvarmeføler (i dette tilfælde Devireg 233 med den tilhørende NTC 15Kohm sensor)
Det virker ved at bruge et script. dvs. scriptet styre enhedens relæer (dataen kan altså ikke ses  i appens brugerfladed)

Scriptet bruger Steinhart–Hart formlen der bruger max, middel og min værdier for at lave udregningen.
https://rusefi.com/Steinhart-Hart.html (OBS!! Temperature er i Fareheit)
https://www.thinksrs.com/downloads/programs/therm%20calc/ntccalibrator/ntccalculator.html
https://github.com/ALLTERCO/shelly-script-examples/blob/main/ntc-conversion.js tilpasset med Devireg føler værdier og ændret, så det viser værdierne i loggen

Devireg føler værdier
Følerenhed NTC 15 kΩ ved 25 °C
Følerværdier:
0°C = 42000Ω
25°C = 15000Ω
50°C = 6000Ω 

Trin 1: Preperation

Hardware

  • Shelly Plus 1PM together with Shelly Plus Add-on
  • Shelly Plus Add-on
  • NTC sensor.

Make sure the device is updatet to latest firmware

Step 2: Add Sensor in the app

We now need to add the sensor in the app
Note. this can also be done from the web interface

  1. Click on the device
  2.  Click on the Add-on symbol
  3. Click Add Peripheral
  4. Select Analog
  5. Click Add Peripheral

                If it ask to reboot just let it

Step 3: Insert and prepare script

Go to the devices web interface by entering it’s ip adress in a browser og from the app go to device -> settings (cogwheel) device information click ip adress.
Note. This can also be done from the app, but i like the Webinterface better.

Turn on Websocket debug

In order to see the status in the log, we must first turn on WebSocket debug (this is not necessary).

  • Press the “cog wheel”.
  • Select Debug.
  • Check “Enable Websocket Debug”
  • Press “Save Settings”

Insert script

  • Tap the script icon (<>)
  • Press “Create new script”
  • Give your script a name

Now copy the entire code below into the new script.
(Press Copy in the top right corner of the script)
Note. this script is based on https://github.com/ALLTERCO/shelly-script-examples/blob/main/ntc-conversion.js with slighlt modifications

/**************** START CHANGE HERE ****************/
let CONFIG = {
  scanInterval: 10, //secs, this will run a timer for every 30 seconds, that will fetch the voltage
  voltmeterID: 100, //the ID of the voltmeter - When we install the add on, the device will define this number

  /**
   * Applies some math on the voltage and returns the result. This function is called every time the voltage is measured
   * @param {Number} voltage The current measured voltage
   * @returns The temperature based on the voltage
   */
  calcTemp: function (voltage) {
    const constVoltage = 10;
    const R1 = 10000;
    const A = 0.0010377385695278978;
    const B = 0.00021633455581572119;
    const C = 2.654857502585547e-7;
    
    const R2 = R1 * (voltage / (constVoltage - voltage));
    const logR2 = Math.log(R2);
    let T = 1.0 / (A + (B + C * logR2 * logR2) * logR2);
    T = T - 273.15; // Celcius
    //T = (T - 273.15) * 9/5 + 32; // Fahrenheit
    
    return { temperature: T, voltage: voltage, resistance: R2 };
  },

  /**
   * This function is called every time when a temperature is read
   * @param {Object} data Object containing temperature, voltage, and resistance
   */
  onTempReading: function (data) {
    const temperature = data.temperature;
    const voltage = data.voltage;
    const resistance = data.resistance;
    
    let relayStatus;
    const currentTime = new Date();
    const currentHour = currentTime.getHours();
    
    // Determine temperature thresholds based on time of day
     
     
    //if the temperature is less than 16, turn the first output on
    let thresholdLow = 10; // Default threshold
    //if the temperature is greater than 22 turn the first output off
    let thresholdHigh = 20; // Default threshold 
 
    
    // Night setback (natsænkning)
    if (currentHour >= 10 || currentHour < 6) { // Between 22:00 and 06:00
      thresholdLow = 10; // Adjust threshold for cooler temperature during the night
      thresholdHigh = 16; // Adjust threshold for cooler temperature during the night
  
    }
    
    // Check temperature against thresholds
    if (temperature > thresholdHigh) {
       Shelly.call("Switch.Set", {
           id: 0,
           on: false
       });
       relayStatus = "Turned off";
    } else if (temperature < thresholdLow) {
       Shelly.call("Switch.Set", {
           id: 0,
           on: true
      });
      relayStatus = "Turned on";
    } else {
       relayStatus = "Unchanged";
    }
    
    console.log("Temperature: " + temperature.toFixed(2) + " °C | Voltage: " + voltage.toFixed(2) + "V | Resistance: " + resistance.toFixed(2) + "Ω | Hour: " + currentHour + ":00 |     Relay: " + relayStatus);

  },
};
/**************** STOP CHANGE HERE ****************/

function fetchVoltage() {
  //Fetch the voltmeter component
  const voltmeter = Shelly.getComponentStatus(
    "voltmeter:" + JSON.stringify(CONFIG.voltmeterID)
  );

  //exit if can't find the component
  if (typeof voltmeter === "undefined" || voltmeter === null) {
    console.log("Can't find the voltmeter component");
    return;
  }

  const voltage = voltmeter["voltage"];

  //exit if can't read the voltage
  if (typeof voltage !== "number") {
    console.log("can't read the voltage or it is NaN");
    return;
  }

  //get the temperature based on the voltage
  const data = CONFIG.calcTemp(voltage);

  //exit if the temp isn't calculated correctly
  if (typeof data !== "object") {
    console.log("Something went wrong when calculating the temperature");
    return;
  }

  if (typeof CONFIG.onTempReading === "function") {
    CONFIG.onTempReading(data);
  }
}

//init the script
function init() {
  //start the timer
  Timer.set(CONFIG.scanInterval * 1000, true, fetchVoltage);

  //fetch the voltage at run
  fetchVoltage();
}

init();

Trin 4: Konfigurere on/off temperaturen

on temperatur

Find linje 44

På linjen 

let  thresholdLow = kkk 10  “3c:2e:f5:6f:77:9b”, (Linie 44)

Indsætt

//if the temperature is less than 16, turn the first output on
    let thresholdLow = 10; // Default threshold
    //if the temperature is greater than 22 turn the first output off
    let thresholdHigh = 20; // Default threshold 

off temperatur

Find linje 46

På linjen 
addr:  “3c:2e:f5:6f:77:9b”, (Linie 44)

Indsætter du den Mac adressen på din Blu Button, som blev noteret i starten.
OBS!!
Det er meget vigtigt der kun bruges små bogstaver.

//if the temperature is less than 16, turn the first output on
    let thresholdLow = 10; // Default threshold
    //if the temperature is greater than 22 turn the first output off
    let thresholdHigh = 20; // Default threshold 

Trin 3: Udregn de rigtige værdier til scriptet

(Hvis det allerede er en Devrig gulvvarme føler, så kan dette springes over)

Konverter din NTC sensors værdier til data vi skal smide ind i scriptet ved at bruge Steinhart-Hart formel.
NTC sensorens oplysninger vi skal bruge er

Modstand ved sensorens min. temperatur.
Modstand ved sensorens max. temperatur.
Midl. værdier har vi da det altid er Sensorens navn (modstand) som er den modstand der måles ved en temepartur på 25 grader celcious


https://rusefi.com/Steinhart-Hart.html (OBS!! Temperature er i Fareheit)

Eksempel

Du har en NTC10k Sensor hvor data er:
Max. temp er 86,11°C / 187°F = modstand på 1034Ω
Middel temp er 25°C / 77°F = modstand på 10000Ω
Min. temp er -39,44°C/ = mostand 323839Ω

Du har en NTC10k Sensor hvor data er:
Max. temp er 86,11°C / 187°F = modstand på 1034Ω
Middel temp er 25°C / 77°F = modstand på 10000Ω
Min. temp er -39,44°C/ = mostand 323839Ω