Jump to content
🌟 NOTIFICATION/Benachrichtigung: Welcome to our New Store! - shelly.com 🌟 ×

Gaszähler / gas meter


Recommended Posts

Der Weisheit letzter Schluss ist es nicht - meine Erfahrungen habe ich hpts. mit VB6, VB.Net und ein bisschen C/C++ gemacht. Aber grundsätzlich funktioniert es so:

Reed-Sensor in der Aussparung eines Kromschröder Balgengaszählers. Das letzte Rad (eine Umdrehung = 10 l) hat einen Magneten, der bei "9" den Reed-Sensor aktiviert und bei "0" wieder deaktiviert.  Das Logging läuft über eine Webseite wo ein php Script die Daten entgegennimmt und in einer MySQL DB speichert. Von dort holt sich der Shelly beim Starten auch den Anfangsstand des Gas-Zählers.

Klar, da ist jetzt kein Fehler abfangen etc drin, aber für den Anfang bin ich schon mal voll zufrieden. Aktuell kann ich sehen, wie viel Gas ich fürs Kochen (Gaskochfeld) brauche, wie viel Gas für warmes Wasser und in 1-2 Monaten kommt noch die Heizung dazu. Anhand des Verbrauchs der Heizung kann ich dann abschätzen wie die Leistung der Wärmepumpe sein muss, die ich mir nächstes Jahr einbauen lassen will. Dazu wird dann noch die Außentemperatur geloggt und (nächstes Script-Projekt) die Temperaturen für VL der Heizung usw., jeweils mit DS18B20 Temp.Sensoren.

 

/// <reference path="../../shelly-script.d.ts" />
// report for switch status

let DEBUG = true;

function GetGasTotal()
{
  let uri = BaseURL + "logging.php?logtype=get&id=gastotal";
  if (DEBUG) print("Now calling into: " + uri);
  Shelly.call("HTTP.GET", {url: uri},
        function (response)
        {
          if (response && response.code)
          {
            if (response.code === 200)
            {
              if (DEBUG) print("Received: " + response.body);
              GasTotalCurrent=parseInt(response.body);
              return(response.body);
            }
          }
          else {
            if (DEBUG) print("unknown error in GetGasTotal while calling URL!");
          }
          return -1;
        });
}

if (DEBUG) print("running");

/*
   Initialziation sequence
   
*/
let BaseURL = "https://<mywebsite>/";
let GasTotalCurrent = 0;
let GasTotalCurrentTemp = 0;
let Last_Trigger_On = -1;
let Last_Trigger_MaxValue = 60 * 1000; // discard measurement if off follows on "too late" (60 seconds here)
GetGasTotal(); // async call!


/*
   End Init
*/

Shelly.addStatusHandler(
    function (event, ud) {
        // while we don't have better selectivity for events if (typeof (event.info.state) !== 'undefined') {
        //print(JSON.stringify(event));
        // which event?
        if (DEBUG) print("Any Event: " + JSON.stringify(event));
        if (typeof (event.name) !== 'undefined')
        {
          if (event.name == "input")
          {
            if (DEBUG) print("Input Event: " + JSON.stringify(event));
            {
              // event.component, .name, .now, .info {.component, .id, .event, .state, .ts) }
              //print("input:100 ->");
              if (!event.delta.state) // only OFF events
              {
                InputEvent(event);
              }
              else
              {
                Last_Trigger_On = Date.now();
                if (DEBUG) print(Last_Trigger_On);
              }
              
            }
          }
            
        }

        
    },
    null
); // end of Shelly.Call()


/*
Handle Event(s) from input device -> digital input
only logging "on" trigger!
*/
function InputEvent(inp_evt_data) {
    
    let d = Date.now();
    if (GasTotalCurrent == 0) // save intermediate value and leave
    {
        GasTotalCurrentTemp += 10;
        if (DEBUG) print('no value for GasTotalCurrent');
        return;
    }

    if (GasTotalCurrentTemp != 0) // update GasTotalCurrent with our saved data
    {
        GasTotalCurrent += GasTotalCurrentTemp;
        GasTotalCurrentTemp = 0;
    }

    let liter_per_hour=-1;
    if (Last_Trigger_On > 0)
    {
      if ((d - Last_Trigger_On) < Last_Trigger_MaxValue)
      {
        liter_per_hour = 3600 / ((d - Last_Trigger_On)/1000);
        Last_Trigger_On = -1;
      }
    }
    

    GasTotalCurrent += 10;
    let uri = BaseURL + "logging.php?logtype=gas&ts=" + Math.round(d / 1000) + "&gt=" + GasTotalCurrent + "&lph=" + Math.round(liter_per_hour);
    if (DEBUG) print ("calling: " + uri);
    Shelly.call("HTTP.GET", {url: uri},
       function (response)
       {
         if (DEBUG) print("Response " + response.code);
       }
    ); // shelly.call
      
}

 

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.

×
×
  • Erstelle neue...