Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. [gelöst] Xiaomi Motion Sensor & Zeitsteuerung

    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

    [gelöst] Xiaomi Motion Sensor & Zeitsteuerung

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

      Hallo zusammen

      Seit einigen Tagen arbeite ich mich in das Thema ioBroker ein und erstelle nun die ersten Scripts mit Blockly.

      Aktuell habe ich ein Script erstellt, welche die Deckenlampen in der Küche anstellt, sobald jemand in den Range des Bewegungsmelder kommt. Wenn dieser aktiviert ist, sollen die Lampen 90 Sekunden leuchten, bevor diese wieder ausgehen. Da ich keinen Datenpunkt "lastMotion" habe, habe ich dies über eine Abfrage gelöst.

      Ich habe nun ein Script, welches in etwa funktioniert, allerdings den Raspberry Pi an den Anschlag bringt und nebenbei noch ein paar komische Effekte in Form von aufflackern der Lichter hat.

      Zur Hardware:
      Raspberry Pi 4
      1x Xiaomi Motion Sensor, verbunden über einen ConBee II (ohne Xiaomi Gateway, da nicht möglich)
      3x Philips Hue Lampen, verbunden über die Hue Bridge.

      Blockly:
      Code.JPG

      Code:

      <xml xmlns="http://www.w3.org/1999/xhtml">
        <variables>
          <variable type="undefined" id="Intervall">Intervall</variable>
        </variables>
        <block type="timeouts_setinterval" id="s~!P.rH4usTn:!G#[hWQ" x="88" y="-412">
          <field name="NAME">Intervall</field>
          <field name="INTERVAL">1</field>
          <field name="UNIT">sec</field>
          <statement name="STATEMENT">
            <block type="debug" id="GR^B;:izHJ!]7,);+q]q">
              <field name="Severity">log</field>
              <value name="TEXT">
                <shadow type="text" id="%=n`AFb+PtVU_`nFX)*O">
                  <field name="TEXT">test</field>
                </shadow>
                <block type="text_join" id="~${o6_dtCM~hJbxV|_GG" inline="false">
                  <mutation items="2"></mutation>
                  <value name="ADD0">
                    <block type="text" id="bkKve-+}q%;K(/%fU*_H">
                      <field name="TEXT"> Differenz </field>
                    </block>
                  </value>
                  <value name="ADD1">
                    <block type="math_arithmetic" id="RcimFA080JOg;[y~{SHt">
                      <field name="OP">DIVIDE</field>
                      <value name="A">
                        <shadow type="math_number" id="^+1}ge[5`p48*#U((T9/">
                          <field name="NUM">1</field>
                        </shadow>
                        <block type="math_arithmetic" id="IgX`l5|{wf$y)~L)C=Js">
                          <field name="OP">MINUS</field>
                          <value name="A">
                            <shadow type="math_number" id="he=8Lm=mk8EppnjCVh/$">
                              <field name="NUM">1</field>
                            </shadow>
                            <block type="time_get" id="Akei^dtA_G]d=BnF_|1y">
                              <mutation format="false" language="false"></mutation>
                              <field name="OPTION">object</field>
                            </block>
                          </value>
                          <value name="B">
                            <shadow type="math_number" id="sOLCZJEFycmRT2ua6Fsd">
                              <field name="NUM">1</field>
                            </shadow>
                            <block type="get_value" id="a2jYe}4(@`;JSPDmN%!5">
                              <field name="ATTR">ts</field>
                              <field name="OID">deconz.0.Sensors.6.lastupdated</field>
                            </block>
                          </value>
                        </block>
                      </value>
                      <value name="B">
                        <shadow type="math_number" id="v=D+wk@AU,-co/VARFG%">
                          <field name="NUM">1000</field>
                        </shadow>
                      </value>
                    </block>
                  </value>
                </block>
              </value>
              <next>
                <block type="controls_if" id=".TNIQkX}*5{z{l@4tVLq">
                  <mutation elseif="1"></mutation>
                  <value name="IF0">
                    <block type="logic_compare" id="L}a)@A(i5LDo%YHbw{wl">
                      <field name="OP">LTE</field>
                      <value name="A">
                        <block type="math_arithmetic" id="5Iq^z-l^m[s|umJUnS9=">
                          <field name="OP">MINUS</field>
                          <value name="A">
                            <shadow type="math_number" id="Gl%P[a,sNzws1k%$CIl{">
                              <field name="NUM">1</field>
                            </shadow>
                            <block type="time_get" id="/b_UVn.JINcsmS#c1!/y">
                              <mutation format="false" language="false"></mutation>
                              <field name="OPTION">object</field>
                            </block>
                          </value>
                          <value name="B">
                            <shadow type="math_number" id=")9bd/=PAZC?oFH0iIduJ">
                              <field name="NUM">1</field>
                            </shadow>
                            <block type="get_value" id="xFQmw4:MkjFhguFp?w6t">
                              <field name="ATTR">ts</field>
                              <field name="OID">deconz.0.Sensors.6.lastupdated</field>
                            </block>
                          </value>
                        </block>
                      </value>
                      <value name="B">
                        <block type="math_number" id="X85faKp})P:wmi:=(gSe">
                          <field name="NUM">90000</field>
                        </block>
                      </value>
                    </block>
                  </value>
                  <statement name="DO0">
                    <block type="control" id="3.$7_hnaDQ@mnJ}z|42i">
                      <mutation delay_input="false"></mutation>
                      <field name="OID">hue.0.Küche_Deckenlampe_1.on</field>
                      <field name="WITH_DELAY">FALSE</field>
                      <value name="VALUE">
                        <block type="logic_boolean" id="Y6*car4dxD#}.Xk:Z_P~">
                          <field name="BOOL">TRUE</field>
                        </block>
                      </value>
                      <next>
                        <block type="control" id="xSQF|zZR%qKe_36/5{dg">
                          <mutation delay_input="false"></mutation>
                          <field name="OID">hue.0.Küche_Deckenlampe_2.on</field>
                          <field name="WITH_DELAY">FALSE</field>
                          <value name="VALUE">
                            <block type="logic_boolean" id="*SO3M1D!}(K~tD#G~m{T">
                              <field name="BOOL">TRUE</field>
                            </block>
                          </value>
                          <next>
                            <block type="control" id="kZh^QaWJP:-BC6rl@.,#">
                              <mutation delay_input="false"></mutation>
                              <field name="OID">hue.0.Küche_Deckenlampe_3.on</field>
                              <field name="WITH_DELAY">FALSE</field>
                              <value name="VALUE">
                                <block type="logic_boolean" id="5)OLwlj^K8RgEiog0Af]">
                                  <field name="BOOL">TRUE</field>
                                </block>
                              </value>
                            </block>
                          </next>
                        </block>
                      </next>
                    </block>
                  </statement>
                  <value name="IF1">
                    <block type="logic_compare" id="%w5X6.n#mTlecqP.;Rj*">
                      <field name="OP">GT</field>
                      <value name="A">
                        <block type="math_arithmetic" id="H8V6iOLx%.4TV(oh`J9%">
                          <field name="OP">MINUS</field>
                          <value name="A">
                            <shadow type="math_number" id="Gl%P[a,sNzws1k%$CIl{">
                              <field name="NUM">1</field>
                            </shadow>
                            <block type="time_get" id="E6B2ak8/ze0M.|eWyY^7">
                              <mutation format="false" language="false"></mutation>
                              <field name="OPTION">object</field>
                            </block>
                          </value>
                          <value name="B">
                            <shadow type="math_number" id=")9bd/=PAZC?oFH0iIduJ">
                              <field name="NUM">1</field>
                            </shadow>
                            <block type="get_value" id="uj~]L{wZr|gzYrTMe]p;">
                              <field name="ATTR">ts</field>
                              <field name="OID">deconz.0.Sensors.6.lastupdated</field>
                            </block>
                          </value>
                        </block>
                      </value>
                      <value name="B">
                        <block type="math_number" id="OkLX3c-F+jd*2zril2QG">
                          <field name="NUM">90000</field>
                        </block>
                      </value>
                    </block>
                  </value>
                  <statement name="DO1">
                    <block type="control" id="`.,QPX}:rk1%dsEo2vdO">
                      <mutation delay_input="false"></mutation>
                      <field name="OID">hue.0.Küche_Deckenlampe_1.on</field>
                      <field name="WITH_DELAY">FALSE</field>
                      <value name="VALUE">
                        <block type="logic_boolean" id="gaAJ^A/aw:,KC8p{Wm8*">
                          <field name="BOOL">FALSE</field>
                        </block>
                      </value>
                      <next>
                        <block type="control" id="CAe%NKwg*xH;AOPsNLI:">
                          <mutation delay_input="false"></mutation>
                          <field name="OID">hue.0.Küche_Deckenlampe_2.on</field>
                          <field name="WITH_DELAY">FALSE</field>
                          <value name="VALUE">
                            <block type="logic_boolean" id="4jR|ob1yjC%G*f(o:Ihk">
                              <field name="BOOL">FALSE</field>
                            </block>
                          </value>
                          <next>
                            <block type="control" id="!Yrz2`U=hqiF)`{ou{bp">
                              <mutation delay_input="false"></mutation>
                              <field name="OID">hue.0.Küche_Deckenlampe_3.on</field>
                              <field name="WITH_DELAY">FALSE</field>
                              <value name="VALUE">
                                <block type="logic_boolean" id="lo+sC8s)nBwfr(n]c}Yu">
                                  <field name="BOOL">FALSE</field>
                                </block>
                              </value>
                            </block>
                          </next>
                        </block>
                      </next>
                    </block>
                  </statement>
                </block>
              </next>
            </block>
          </statement>
        </block>
      </xml>
      

      Nun die Frage in die Runde, wie könnte ich dies besser lösen? Gibt es grundsätzliche Fehler? Falls ja, in welchen Teilbereich soll ich mich schlau machen?

      Danke für eure Tipps.

      Gruss Michael

      crunchip 1 Reply Last reply Reply Quote 0
      • crunchip
        crunchip Forum Testing Most Active @Dimivo last edited by

        @Dimivo nur mal so nebenbei, vllt ist das etwas für dich
        https://forum.iobroker.net/topic/22034/

        D 1 Reply Last reply Reply Quote 0
        • D
          Dimivo @crunchip last edited by

          @crunchip Danke für den Tipp. Habe ich gleich mal ausprobiert, hat allerdings noch nicht geklappt. Liegt entweder daran, dass ich kein Mihome verwende, oder schlicht und einfach daran, dass ich die Datenpunkte falsch im Script eintrage. Ich verfolge die Idee weiter, freue mich aber auch über Ideen zum Script im ersten Post.

          D 1 Reply Last reply Reply Quote 0
          • D
            duffbeer2000 @Dimivo last edited by

            @Dimivo so hab ich es gelöst. Aktuell läuft dein Script einemal pro Sekunde deshalb ist dein Pi irgendwann am Anschlag.

            854d73bf-e8cb-4a79-8928-1e96935bbc6d-grafik.png

            441f1c6b-3ac9-45b6-92c5-16a7fc376781-grafik.png

            41407663-2d3a-443a-a728-1786d452728a-grafik.png

            D 1 Reply Last reply Reply Quote 0
            • D
              Dimivo @duffbeer2000 last edited by

              @duffbeer2000 Perfekt, mit diesem Ansatz konnte ich meine Herausforderung problemlos lösen und durfte dabei noch ein paar Sachen lernen. Vielen Dank!

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

              Support us

              ioBroker
              Community Adapters
              Donate

              847
              Online

              31.9k
              Users

              80.3k
              Topics

              1.3m
              Posts

              3
              5
              695
              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