Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. OT-Therm Werte in Datenpunkte / Open Therm / JSON

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.9k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    2.3k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    16
    1
    3.6k

OT-Therm Werte in Datenpunkte / Open Therm / JSON

Scheduled Pinned Locked Moved Skripten / Logik
javascript
1 Posts 1 Posters 139 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sissiwupS Offline
    sissiwupS Offline
    sissiwup
    wrote on last edited by sissiwup
    #1

    Hallo,

    ich habe ein kleines Skript geschrieben, was Werte aus dem openTherm MQTT in Datenpunkte überführt.
    (https://www.seegel-systeme.de) - Diesen nutze ich ...
    Es wird als Status nur ein JSON geliefert.

    Das Skript kann eigentlich beliebige JSON in Datenpunkte überführen(inkl. Unterstrukturen/Arrays):

    Einmal muss die instanz - Variable angepasst werden. (Ich habe hier historisch immer noch javascript und nicht user stehen ...)

    Und natürlich der Datenpunkt auf das es hört (2. Zeile). Und in der Funktion countAll der state, der Gelesen werden soll.

    Die Werte werden nur geschrieben, wenn sie sich ändern (um die Datenbank zu entlatsen :-))
    Ein paar Werte, die zu oft kommen, werden rausgefiltert.

    Viel Spaß damit und gerne Verbesserungsvorschläge ...

    var instanz = 'javascript.0.ottherm.';
    on('mqtt.0.otthing.31F3A0.state',function(dp) {
        countAll();
    });
    
    function flattenJSON(obj, prefix = '') {
        let result = {};
        for (let key in obj) {
            if (obj.hasOwnProperty(key)) {
                let newKey = prefix ? `${prefix}.${key}` : key;
                if (typeof obj[key] === 'object' && obj[key] !== null) {
                    Object.assign(result, flattenJSON(obj[key], newKey));
                } else {
                    result[newKey] = { value: obj[key], art: typeof obj[key] };
                }
            }
        }
        return result;
    }
    
    function setKeyValuePairs(json) {
        const flattened = flattenJSON(json);
        for (const [key, { value, art }] of Object.entries(flattened)) {
            if (!key.includes("txCount") && !key.includes("rxCount") && !key.includes("runtime") && !key.includes("freeHeap") && !key.includes("rssi")) {
                createState(instanz+key, 0, { name: key , desc: key , type: art });
    //          log(String(key+"->"+getState(instanz+key).val)+"?"+value)
                if (String(getState(instanz+key).val)!=String(value)) {
    //                console.log(`${key} -> ${value} (Type: ${art})`);
                    if (art=="number") setState(instanz+key,Number(value));
                    if (art=="boolean") setState(instanz+key,Boolean(value));
                    if (art=="string") setState(instanz+key,String(value));
                }
            }
        }
    }
    
    function countAll() {
      let ottherm = JSON.parse(getState('mqtt.0.otthing.31F3A0.state').val);
      // log(JSON.stringify(ottherm));
      setKeyValuePairs(ottherm);
    }
    
    schedule("*/15 * * * *", function () {
        countAll();
    });
    
    countAll();
    

    MfG

    Sissi

    –-----------------------------------------

    1 CCU3 1 CCU2-Gateway 1 LanGateway 1 Pi-Gateway 1 I7 für ioBroker/MySQL


    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    Support us

    ioBroker
    Community Adapters
    Donate

    927

    Online

    32.5k

    Users

    81.6k

    Topics

    1.3m

    Posts
    Community
    Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
    ioBroker Community 2014-2025
    logo
    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Home
    • Recent
    • Tags
    • Unread 0
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe