Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Русский
    3. ioBroker
    4. Скрипты
    5. ioBroker скрипты
    6. Управление цветом подсветки шлюза Xiaomi с помощью HomeKit

    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

    Управление цветом подсветки шлюза Xiaomi с помощью HomeKit

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

      1. Нужно добавить новый объект, например "color".

      2. В настройках драйвера прописываем, что значение нужно писать в "color" ~~![](</s><URL url=)http://joxi.ru/Vm6y1Q4CDlZVvr.jpg" />

      3. Создаем скрипт и все "mihome.0.devices.gateway_7811dcdebfa0.rgb" и "mihome.0.devices.gateway_7811dcdebfa0.color" меняете на свои значения

      function setRGB(r, g, b){
          var val = '#'+('00'+r.toString(16)).slice(-2)+('00'+g.toString(16)).slice(-2)+('00'+b.toString(16)).slice(-2);
          //console.log(val);
          setState('mihome.0.devices.gateway_7811dcdebfa0.rgb', val);
      }
      
      on({id: "mihome.0.devices.gateway_7811dcdebfa0.color", ack: false, change: 'any'}, function (obj) {
          var hue = parseInt(obj.state.val);
          var sat = parseInt(getState('mihome.0.devices.gateway_7811dcdebfa0.color').val);
          //console.log(hue + '  ' + sat);
          var res = hsvToRgb(hue, sat, 100);
          //console.log(res);
          setRGB(parseInt(res[0]), parseInt(res[1]), parseInt(res[2]));
      });
      
      function hsvToRgb(h, s, v) {
          var r, g, b;
          var i;
          var f, p, q, t;
      
          // Make sure our arguments stay in-range
          h = Math.max(0, Math.min(360, h));
          s = Math.max(0, Math.min(100, s));
          v = Math.max(0, Math.min(100, v));
      
          // We accept saturation and value arguments from 0 to 100 because that's
          // how Photoshop represents those values. Internally, however, the
          // saturation and value are calculated from a range of 0 to 1\. We make
          // That conversion here.
          s /= 100;
          v /= 100;
      
          if(s == 0) {
              // Achromatic (grey)
              r = g = b = v;
              return [
                  Math.round(r * 255), 
                  Math.round(g * 255), 
                  Math.round(b * 255)
              ];
          }
      
          h /= 60; // sector 0 to 5
          i = Math.floor(h);
          f = h - i; // factorial part of h
          p = v * (1 - s);
          q = v * (1 - s * f);
          t = v * (1 - s * (1 - f));
      
          switch(i) {
              case 0:
                  r = v;
                  g = t;
                  b = p;
                  break;
      
              case 1:
                  r = q;
                  g = v;
                  b = p;
                  break;
      
              case 2:
                  r = p;
                  g = v;
                  b = t;
                  break;
      
              case 3:
                  r = p;
                  g = q;
                  b = v;
                  break;
      
              case 4:
                  r = t;
                  g = p;
                  b = v;
                  break;
      
              default: // case 5:
                  r = v;
                  g = p;
                  b = q;
          }
      
          return [
              Math.round(r * 255), 
              Math.round(g * 255), 
              Math.round(b * 255)
          ];
      }
      
      ````~~
      1 Reply Last reply Reply Quote 0
      • First post
        Last post

      Support us

      ioBroker
      Community Adapters
      Donate

      426
      Online

      31.8k
      Users

      80.0k
      Topics

      1.3m
      Posts

      1
      1
      1391
      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