Jump to content

Shelly 1PM Add-On - Getting NTC to display temperature


Ian

Recommended Posts

Hi All,

I want to link my existing underfloor heating NTC temperature sensor to an Add-On, I have followed the NTC connection instructions and as this is connected to an analogue input I get a % displayed value, is it possible to convert this % value into Centigrade so I can automate based on temperature.

Many thanks

 

Link to comment
Share on other sites

  • Members

The script library, accessible with every generation 2 and 3 Shelly, lists a specific script to handle NTC temperature sensors:

IMG_1620.thumb.jpeg.d7f3945b3e3a48e865416c498f26c668.jpeg

Just click ‚Library‘ in menu tab ‚Scripts‘. And use the WebUI for entering the configuration menu.

Edited by thgoebel
Link to comment
Share on other sites

3 minutes ago, thgoebel said:

If I understand the script correctly, the calculated temperature is delivered in a variable „T“. You‘ll have to print the variable to the debug console or transfer it to another function.

Ah, I fear this may be outside of my very limited knowledge.

Really appreciate your help here, off to google and YouTube again lol

Link to comment
Share on other sites

I've done a fair bit of searching and this has come up a lot before but without any satisfactory resolution for basic shelly users.

The common scenario is that a Shelly1PM and Add-On are bought together to replace existing Under Floor Heating controls which have floor embedded NTC temperature sensors, unfortunately, although the Add-On specifies NTC compatibility, this only gives a displayed output of either a voltage or percentage when connected, NOT temperature straight out of the box, which is a massive disappointment as NTC thermistors only measure temperature!

I'll add to the Shelly 'wish list' the ability to select 'NTC thermistor' from the peripheral list.

Hope this helps others.

 

Edited by Ian
Link to comment
Share on other sites

  • Members

Try to add more clarity to the NTC script in the library:

(a) At first, one has to read (and possibly understand) the code of the script:

// SH Coefficient Calculator
// https://rusefi.com/Steinhart-Hart.html
//
// Thermistor wiki page
// https://en.wikipedia.org/wiki/Thermistor

/**************** START CHANGE HERE ****************/
let CONFIG = {
  scanInterval: 30, //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.0011252791214670555;
    const B = 0.00023471763897744966;
    const C = 8.563489971304025e-8;

    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 T;
  },

  /**
   * This function is called every time when a temperature is read
   * @param {Number} temperature The current calculated temperature
   */
  onTempReading: function (temperature) {
    //if the temperature is greater than 20.5 turn the first output off
    if (temperature > 20.5) {
      // Shelly.call("Switch.Set", {
      //     id: 0,
      //     on: false
      // });
    }
    //if the temperature is less than 15, turn the first output on
    else if (temperature < 15) {
      // Shelly.call("Switch.Set", {
      //     id: 0,
      //     on: true
      // });
    }
  },
};
/**************** 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 temp = CONFIG.calcTemp(voltage);

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

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

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

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

init();

Above the complete script.

(b) One function is remarkable, cause it gives an answer to @Ian 's question:

/**
   * This function is called every time when a temperature is read
   * @param {Number} temperature The current calculated temperature
   */
  onTempReading: function (temperature) {
    //if the temperature is greater than 20.5 turn the first output off
    if (temperature > 20.5) {
      // Shelly.call("Switch.Set", {
      //     id: 0,
      //     on: false
      // });
    }
    //if the temperature is less than 15, turn the first output on
    else if (temperature < 15) {
      // Shelly.call("Switch.Set", {
      //     id: 0,
      //     on: true
      // });
    }
  },
};

We learn that a switching function is implemented: Above 20,5 °C the relay of the hosting Shelly device is switches off. Below 15 °C, the relay is switches on! These limits can be amended at discretion. Replacing this function by another is even possible. And - may be - some help of forum's members will be available...

Link to comment
Share on other sites

Hi,

Thanks for the expanded explanation, as a really basic user, all I'm after is the device to show a temperature from the NTC in degrees, but I do appreciate the level of skill and expertise in compiling the script and the time taken to explain it.

 

Ian

Link to comment
Share on other sites

  • 2 weeks later...

I'm in the same boat as you @Ian and have been unable to get a simple temperature readout from the NTC thermistor in the floor.  Like many systems installed these electric underfloor systems usually have NTC thermistors for temperature measurement.  

Have you got any further with this?  It seems odd for the addon to support NTC connection as outlined in the wiring diagram for the addon yet not be able to output a displayed temperature.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...