Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Praktische Anwendungen (Showcase)
    4. [Javascript] Wetterstation Renkforce WH2600

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [Javascript] Wetterstation Renkforce WH2600

    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Johannes 3 last edited by

      Hallo,

      ich habe vor Jahren diese Wetterstation gekauft und sie an FHEM angebunden. Ich will jetzt aber zu ioBroker wechseln. Leider fand ich keinen passenden Adapter für den ioBroker. Deshalb habe ich ein Skript geschrieben, dass die Wetterdaten entgegennimmt und umrechnet. Vielleicht kann es ja noch wer gebrauchen.
      Ich bin kein Programmierer und würde mich deshalb über Verbesserungsvorschläge freuen.

      
      const express = require('express');
      const app = express();
      const PORT = 3011;
      const adapterInstance = 'javascript.0.Wetter';
      const stateMappings = {
          temp: {type: 'number', unit: '°C', role: 'value' },
          dewpt: {type: 'number', unit: '°C', role: 'value' },
          windchill: {type: 'number', unit: '°C', role: 'value' },
          indoortemp: {type: 'number', unit: '°C', role: 'value' },
          humidity: {type: 'mixed', unit: '%', role: 'value' },
          indoorhumidity: {type: 'mixed', unit: '%', role: 'value' },
          windspeed: {type: 'number', unit: 'm/s', role: 'value' },
          windgust: {type: 'number', unit: 'm/s', role: 'value' },
          winddir: {type: 'mixed', unit: '°', role: 'value' },
          rain: {type: 'number', unit: 'l', role: 'value' },
          dailyrain: {type: 'number', unit: 'l', role: 'value' },
          weeklyrain: {type: 'number', unit: 'l', role: 'value' },
          monthlyrain: {type: 'number', unit: 'l', role: 'value' },
          yearlyrain: {type: 'number', unit: 'l', role: 'value' },
          UV: {type: 'mixed', role: 'value' },
          solarradiation: {type: 'mixed', unit: 'W/m²', role: 'value' },
          barom: {type: 'string', unit: 'l', role: 'value' },
          lowbatt: {type: 'mixed', role: 'value' },
          dateutc: {type: 'mixed', role: 'value' }
      };
      
      Object.keys(stateMappings).forEach(key => {
          const stateId = `javascript.0.Wetter.${key}`;
          if (!existsState(stateId)) {
              const mapping = stateMappings[key];
              createState(stateId, null, {
                  name: key,
                  type: mapping.type,
                  role: mapping.role,
                  unit: mapping.unit
              });
          }
      });
      
      const conversions = {
          // Temperaturumrechnungen von Fahrenheit nach Celsius
          'tempf': { target: 'temp', convert: value => (value - 32) * 5/9 },
          'dewptf': { target: 'dewpt', convert: value => (value - 32) * 5/9 },
          'windchillf': { target: 'windchill', convert: value => (value - 32) * 5/9 },
          'indoortempf': { target: 'indoortemp', convert: value => (value - 32) * 5/9 },
      
          // Windgeschwindigkeitsumrechnung von mph nach m/s
          'windspeedmph': { target: 'windspeed', convert: value => value * 0.44704 },
          'windgustmph': { target: 'windgust', convert: value => value * 0.44704 },
      
          // Regenmengenumrechnungen von inches nach l/m²
          'rainin': { target: 'rain', convert: value => value * 25.4 },
          'dailyrainin': { target: 'dailyrain', convert: value => value * 25.4 },
          'weeklyrainin': { target: 'weeklyrain', convert: value => value * 25.4 },
          'monthlyrainin': { target: 'monthlyrain', convert: value => value * 25.4 },
          'yearlyrainin': { target: 'yearlyrain', convert: value => value * 25.4 },
      
          //Rest
          'humidity': { target: 'humidity', convert: value => value   },
          'indoorhumidity': { target: 'indoorhumidity', convert: value => value   },
          'winddir': { target: 'winddir', convert: value => value   },
          'solarradiation': { target: 'solarradiation', convert: value => value   },
          'UV': { target: 'UV', convert: value => value   },
          'baromin': { target: 'barom', convert: value => value   },
          'lowbatt': { target: 'lowbatt', convert: value => value   },
          'dateutc': { target: 'dateutc', convert: value => value   }
      };
      
      function isValidData(data) {
          return typeof data === 'object' && data !== null;
      }
      
      function convertData(key, value) {
          if (conversions[key]) {
              return conversions[key].convert(value);
          }
          return null;
      }
      
      function updateState(key, value) {
          setState(`${adapterInstance}.${key}`, value, true, (err) => {
              if (err) {
                  console.error(`Fehler beim Aktualisieren des Zustands ${key}: ${err}`);
              }
          });
      }
      
      app.get('/weatherstation/updateweatherstation.php', (req, res) => {
          const data = req.query;
          console.log(data);
      
          if (!isValidData(data)) {
              return res.status(400).send('Ungültige Daten empfangen');
          }
      
          for (const key in data) {
              if (data.hasOwnProperty(key)) {
                  const convertedValue = convertData(key, data[key]);
                  if (convertedValue !== null) {
                      updateState(conversions[key].target, convertedValue);
                  }
              }
          }
      
          res.send('success');
      });
      
      app.use((err, req, res, next) => {
          console.error(err.stack);
          res.status(500).send('Etwas ist schief gelaufen!');
      });
      
      app.listen(PORT, () => {
          console.log(`Server läuft auf http://localhost:${PORT}`);
      });
      

      In der Wetterstation muss man nur noch die IP und den Port eintragen.
      b73241e9-c640-4a9d-a4e9-10c81508b885-grafik.png

      1 Reply Last reply Reply Quote 1
      • First post
        Last post

      Support us

      ioBroker
      Community Adapters
      Donate

      900
      Online

      31.9k
      Users

      80.2k
      Topics

      1.3m
      Posts

      1
      1
      189
      Loading More Posts
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      Community
      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
      The ioBroker Community 2014-2023
      logo