Skip to content

Using Shelly H&T sensors as a room unit

fredlcore edited this page Jun 25, 2024 · 4 revisions

Shelly temperature sensors can be used to send their measured temperature to the heating system via BSB-LAN. To do that, you need to go to the Shelly's web configuration, select Scripts and then New Script. Then give it a name and copy and paste this script, adjust the configuration and then save it and click "Start" to have it running. This example script will then send the current temperature from the Shelly to the heating system directly every 61 seconds:

let CONFIG = {
  host: "bsb-lan.local",
  passkey: "1234",
  username: "abc",
  password: "xyz",
  parameter: "10000",
  
  component: "temperature:0",
  propertyPath: "tC"
}

function getNestedProperty(obj, path) {
  var parts = path.split('.');
  for (var i = 0; i < parts.length; i++) {
    if (obj === undefined || obj === null) {
      return undefined;  // Return undefined if any part of the path is undefined
    }
    obj = obj[parts[i]];  // Update obj to the next nested property
  }
  return obj;
}

function sendTemperature() {

  let temperature = getNestedProperty(Shelly.getComponentStatus(CONFIG.component), CONFIG.propertyPath);
  
  let bsb_lan_url = "http://";
  bsb_lan_url += CONFIG.host + "/";
  if (CONFIG.passkey) {
    bsb_lan_url += CONFIG.passkey + "/";
  }
  bsb_lan_url += "I" + CONFIG.parameter + "=" + temperature;
  let user_pass = btoa(CONFIG.username + ":" + CONFIG.password);

  let header = {
    method: "GET",
    url: bsb_lan_url,
    headers: {},
    timeout: 20,
  };
  if (CONFIG.username) {
    header.headers.Authorization = "Basic " + user_pass;
  }
  print("It is ", temperature, " degrees.");
  print("Calling URL ", bsb_lan_url);
  Shelly.call("HTTP.Request", header, function (result, error_code, error_message) {}, null);
}

Timer.set(61000, true, sendTemperature);
Clone this wiki locally