Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Visualisierung
    4. Javascript für Prozentangabe gesucht

    NEWS

    • Neues Video "KI im Smart Home" - ioBroker plus n8n

    • Neues Video über Aliase, virtuelle Geräte und Kategorien

    • Wir empfehlen: Node.js 22.x

    Javascript für Prozentangabe gesucht

    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      TOBO last edited by

      Hallo,

      kann mir bitte jemand beim erstellen eines Scriptes helfen, welches einen Wert berechnet.

      ID_out = Runden(ID_in / 2,55)

      Das hätte ich gern als script, jedesmal wenn sich die ID_in Variable ändert. Hätte gern den Wert für DMX Dimmer als Prozent angezeigt.

      Da der Maxwert 255 ist, also einfach durch 2,55 teilen und auf Ganze Zahl runden.

      Gruß.

      ToBo

      1 Reply Last reply Reply Quote 0
      • AlCalzone
        AlCalzone Developer last edited by

        Ich weiß zwar nicht wie man das in vis einbindet, aber:

        function inProzent(wert, max) {
        	if (max == undefined) max = 255;
        	return Math.round(wert / max * 100);
        }
        
        on(ID_in, function(obj) {
        	setState(ID_out, inProzent(obj.state.val));
        });
        
        

        sollte der Max-Wert einer Variable mal nicht 255 sein, sondern bspw 123, dann ist eine kleine Anpassung nötig:

        on(ID_in, function(obj) {
        	setState(ID_out, inProzent(obj.state.val, 123));
        });
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post

        Support us

        ioBroker
        Community Adapters
        Donate

        649
        Online

        32.1k
        Users

        80.6k
        Topics

        1.3m
        Posts

        2
        2
        294
        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