Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • 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

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. Blockly
  5. Blockly um Rollo zu blockieren?

NEWS

  • Jahresrückblick 2025 – unser neuer Blogbeitrag ist online! ✨
    BluefoxB
    Bluefox
    17
    1
    3.5k

  • Neuer Blogbeitrag: Monatsrückblick - Dezember 2025 🎄
    BluefoxB
    Bluefox
    13
    1
    1.1k

  • Weihnachtsangebot 2025! 🎄
    BluefoxB
    Bluefox
    25
    1
    2.5k

Blockly um Rollo zu blockieren?

Geplant Angeheftet Gesperrt Verschoben Blockly
blockly
37 Beiträge 6 Kommentatoren 3.7k Aufrufe 5 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • R Offline
    R Offline
    R1Snake
    schrieb am zuletzt editiert von
    #17

    Was du machen könntest wäre eine Dummy Variable.

    Wenn 100 eingegeben wird, dann wird die Rollade hochgefahren, wenn 0 eingegeben wird dann wird die Rollade runter gefahren.

    Dann kannst du die Variable in den Adapter hinterlegen und so ausprobieren.

    Wichtig wäre dann nur Werte von 0 oder 100 zu verwenden.

    Aktuell wäre ein Blockly besser.

    Hoffe du kannst programmieren dann kannst du folgenden Code anpassen:

    var device, direction;
    var position = 0;
    var groups = {
        'Balkon': 'javascript.0.home.Wohnzimmer.Rolläden.Gruppe.Balkon.position',
        'Balkontuer': 'shelly.0.SHSW-25#10F917#1.Shutter.Position'
    };
    
    on({id: 'alexa2.0.History.summary', change: "ne"}, function (obj) {
      var value = obj.state.val;
      var oldValue = obj.oldState.val;
    
      if(value.indexOf('rollladen') + 1)
        device = groups.Balkon;
      else if (value.indexOf('balkon tür') + 1)  
        device = groups.Balkontuer;
      
      if (value.indexOf('runter') + 1)
        direction = 0;
      else if (value.indexOf('hoch') + 1)
        direction = 100;
      else if (value.indexOf('rauf') + 1)
        direction = 100;
      
        
      if (device) {
        if (direction)
            setPosition(device,position);
      }  
    });
    
    function setPosition(obj, position) {
        setState(obj, position);
    }
    

    Der Code fragt den Kommand der Alexa geräte ab und prüft diese auf Inhalt.

    Hier könntest du es so machen das wenn die rollade angesprochen wird kannst du mit SetState die Rollade "Sperren" wenn die Tür offen ist

    Hoffe das Hilft

    1 Antwort Letzte Antwort
    0
    • X Offline
      X Offline
      xbow42
      schrieb am zuletzt editiert von
      #18

      Das Problem ist dass du mit deinen in Alexa konfigurierten Routinen z.Z nicht in die Steuerung eingreifen kannst.
      Daher bleibt IMO nur die Möglichkeit die Steuerung der Routinen im ioBroker zu machen. Entweder mit dem Shuttercontrol und eigenem Datenpunkt(en) Level(auch wenn der dann nur 0und100 oder 0und1 kann) und dem Sperren alias Kollision.state. Wenn ich mich recht erinnere hat der Adapter auch schon DP zum sperren ("autoDown" könnte dein Kandidat sein). Diesen kannst du auch von deinem eigenen Script setzen durch Fensterkontakt-Statusänderung.

      1 Antwort Letzte Antwort
      0
      • B Offline
        B Offline
        biker1602
        schrieb am zuletzt editiert von
        #19

        Das ist mir jetzt alles zu hoch. Ich dachte, es geht einfacher umzusetzen. Mir fällt es mit Blockly schon schwer etwas umzusetzen da ich in der Materie noch in den Kinderschuhen stecke. Für mich sollte es nur eine Sicherheit sein das, wenn ich im Sommer Abends draußen sitze, die Balkontür auf ist und das Rollo automatisch heruntergeht das es nicht auf die offene Tür läuft .

        1 Antwort Letzte Antwort
        0
        • R Offline
          R Offline
          R1Snake
          schrieb am zuletzt editiert von
          #20

          Ich habe eine neue Idee für dich.

          Lösche in Alexa die routine die das ausführt.

          Dann erstellst du dir ein Virtual device welches du auf An/Aus setzen kannst. Dieser ist verknüpft mit den Schaltern für dein Rollo. Das einzige was dann dazu kommt ist wenn dein VD gesetzt wird, prüft dieser vorher ob die tür offen ist. Wenn ja wird nichts gesetzt, wenn nicht dann wird der Button für deine Rollade gedrückt.

          Für Alexa erstellst du dir ein IOT Device und nennst es wie deine Routine.

          Denke so kannst du alles umsetzen und hast deinen Schutz

          B 1 Antwort Letzte Antwort
          0
          • R R1Snake

            Ich habe eine neue Idee für dich.

            Lösche in Alexa die routine die das ausführt.

            Dann erstellst du dir ein Virtual device welches du auf An/Aus setzen kannst. Dieser ist verknüpft mit den Schaltern für dein Rollo. Das einzige was dann dazu kommt ist wenn dein VD gesetzt wird, prüft dieser vorher ob die tür offen ist. Wenn ja wird nichts gesetzt, wenn nicht dann wird der Button für deine Rollade gedrückt.

            Für Alexa erstellst du dir ein IOT Device und nennst es wie deine Routine.

            Denke so kannst du alles umsetzen und hast deinen Schutz

            B Offline
            B Offline
            biker1602
            schrieb am zuletzt editiert von
            #21

            @R1Snake meinst du mit dem LinkedDevices Adapter

            1 Antwort Letzte Antwort
            0
            • R Offline
              R Offline
              R1Snake
              schrieb am zuletzt editiert von
              #22

              So in der Art, hab ihn jedoch noch nie benutzt.

              Sekunde ich such dir mal ein Script raus

              1 Antwort Letzte Antwort
              0
              • R Offline
                R Offline
                R1Snake
                schrieb am zuletzt editiert von
                #23

                So hab es mal quick and dirty umgeschrieben.

                dieses script legst du bei common an:

                virtualGosundSwitch('MQTT', 'Abstellraum','Gosund6', 'mqtt.0.SmartHome.Gosund.Gosund6');
                
                function virtualGosundSwitch(room, name, devname, deviceId) {
                    var config = {
                        namespace: room,
                        name: name,
                        copy: {common: {name: devname, role: 'variable'}, native: {type: 'switch'}},
                        states: {
                            'state': {
                                common: {type: 'boolean', def: '', read: false, write: true},
                                write: {
                                    [deviceId + '.cmnd.POWER']: { // Pfad von deinem Button
                                        convert: function(val) {
                                            if (val == true)
                								if (getState()) //hier den Pfad von deinem Türsensor 
                									return false;
                                                return true;
                                            else
                                                return false;                              
                                        }
                                    }
                                }
                            }           
                        }
                    }
                    return new VirtualDevice(config);
                }
                

                und das bei main:

                function VirtualDevice(config) {
                    //sanity check
                    if (typeof config !== 'object' || typeof config.namespace !== 'string' || typeof config.name !== 'string' || typeof config.states !== 'object') {
                        log('sanity check failed, no device created', 'warn');
                        return;
                    }
                
                    this.config = config;
                    this.namespace = 'home.' + config.namespace + '.' + config.name;
                    this.name = config.name;
                
                    //create virtual device
                    this.createDevice(function () {
                        this.createStates(function () {
                            log('created virtual device ' + this.namespace)
                        }.bind(this));
                    }.bind(this));
                }
                
                VirtualDevice.prototype.createDevice = function (callback) {
                    log('creating object for device ' + this.namespace, 'debug');
                    //create device object
                    var obj;
                    if (typeof this.config.copy == 'string') {
                        obj = getObject(this.config.copy);
                    } else if (typeof this.config.copy == 'object') {
                        obj = this.config.copy;
                    } else {
                        obj = {common: {}, native: {}};
                    }
                    delete obj.common.custom;
                    if (typeof this.config.common === 'object') {
                        obj.common = Object.assign(obj.common, this.config.common);
                    }
                    if (typeof this.config.native === 'object') {
                        obj.native = Object.assign(obj.native, this.config.native);
                    }
                    extendObject('javascript.' + instance + '.' + this.namespace, {
                        type: "device",
                        common: obj.common,
                        native: obj.native
                    }, function (err) {
                        if (err) {
                            log('could not create virtual device: ' + this.namespace, 'warn');
                            return;
                        }
                        log('created object for device ' + this.namespace, 'debug');
                        if (typeof this.config.onCreate === 'function') {
                            this.config.onCreate(this, callback);
                        } else {
                            callback();
                        }
                    }.bind(this));
                };
                
                VirtualDevice.prototype.createStates = function (callback) {
                    "use strict";
                    log('creating states for device ' + this.namespace, 'debug');
                    var stateIds = Object.keys(this.config.states);
                    log('creating states ' + JSON.stringify(stateIds), 'debug');
                    var countCreated = 0;
                    for (var i = 0; i < stateIds.length; i++) {
                        let stateId = stateIds[i];
                        this.normalizeState(stateId);
                        var id = this.namespace + '.' + stateId;
                        log('creating state ' + id, 'debug');
                        var obj = this.config.states[stateId].copy ? getObject(this.config.states[stateId].copy) : {
                            common: {},
                            native: {}
                        };
                        delete obj.common.custom;
                        if (typeof this.config.states[stateId].common === 'object') {
                            obj.common = Object.assign(obj.common, this.config.states[stateId].common);
                        }
                        if (typeof this.config.states[stateId].native === 'object') {
                            obj.native = Object.assign(obj.native, this.config.states[stateId].native);
                        }
                        createState(id, obj.common, obj.native, function (err) {
                            if (err) {
                                log('skipping creation of state ' + id, 'debug');
                            } else {
                                log('created state ' + id, 'debug');
                            }
                            this.connectState(stateId);
                            countCreated++;
                            if (countCreated >= stateIds.length) {
                                log('created ' + countCreated + ' states for device ' + this.namespace, 'debug');
                                callback();
                            }
                        }.bind(this));
                    }
                };
                
                VirtualDevice.prototype.normalizeState = function (state) {
                    log('normalizing state ' + state, 'debug');
                    if (typeof this.config.states[state].read !== 'object') {
                        this.config.states[state].read = {};
                    }
                    if (typeof this.config.states[state].write !== 'object') {
                        this.config.states[state].write = {};
                    }
                
                    var readIds = Object.keys(this.config.states[state].read);
                    for (var i = 0; i < readIds.length; i++) {
                        var readId = this.config.states[state].read[readIds[i]];
                        if (typeof readId.before !== 'function') {
                            this.config.states[state].read[readIds[i]].before = function (device, value, callback) {
                                callback();
                            };
                        }
                        if (typeof readId.after !== 'function') {
                            this.config.states[state].read[readIds[i]].after = function (device, value) {
                            };
                        }
                    }
                    var writeIds = Object.keys(this.config.states[state].write);
                    for (i = 0; i < writeIds.length; i++) {
                        var writeId = this.config.states[state].write[writeIds[i]];
                        if (typeof writeId.before !== 'function') {
                            this.config.states[state].write[writeIds[i]].before = function (device, value, callback) {
                                callback();
                            };
                        }
                        if (typeof writeId.after !== 'function') {
                            this.config.states[state].write[writeIds[i]].after = function (device, value) {
                            };
                        }
                    }
                    log('normalized state ' + state, 'debug');
                };
                
                VirtualDevice.prototype.connectState = function (state) {
                    var id = this.namespace + '.' + state;
                    log('connecting state ' + id, 'debug');
                    
                    //subscribe to read ids
                    var readIds = Object.keys(this.config.states[state].read);
                    for (var i = 0; i < readIds.length; i++) {
                        if (getState(readIds[i]).notExist === true) { //check if state exists
                            log('cannot connect to not existing state: ' + readIds[i], 'warn');
                            continue;
                        }
                        var readObj = this.config.states[state].read[readIds[i]];
                        var readTrigger = readObj.trigger || {change: 'any'};
                        readTrigger.ack = true;
                        readTrigger.id = readIds[i];
                        this.subRead(readTrigger, readObj, state);
                        log('connected ' + readIds[i] + ' to ' + id, 'debug');
                    }
                
                    //subscribe to this state and write to write ids
                    var writeIds = Object.keys(this.config.states[state].write);
                    if (writeIds.length > 0) {
                        var writeTrigger = {id: 'javascript.' + instance + '.' + this.namespace + '.' + state, change: 'any', ack: false};
                        on(writeTrigger, function (obj) {
                            "use strict";
                            log('detected change of ' + state, 'debug');
                            for (var i = 0; i < writeIds.length; i++) {
                                let writeObj = this.config.states[state].write[writeIds[i]];
                                let val = this.convertValue(obj.state.val, writeObj.convert);
                                let writeId = writeIds[i];
                                log('executing function before for ' + writeId, 'debug');
                                writeObj.before(this, val, function (newVal, newDelay) {
                                    if (newVal !== undefined && newVal !== null) val = newVal;
                                    var delay = writeObj.delay;
                                    if (newDelay !== undefined && newDelay !== null) delay = newDelay;
                                    log(newVal + 'writing value ' + val + ' to ' + writeId + ' with delay ' + delay, 'debug');
                                    setStateDelayed(writeId, val, false, delay || 0, true, function () {
                                        log('executing function after for ' + writeId, 'debug');
                                        writeObj.after(this, val);
                                    }.bind(this));
                                }.bind(this));
                            }
                        }.bind(this));
                        log('connected ' + state + ' to ' + JSON.stringify(writeIds), 'debug');
                    }
                }
                
                VirtualDevice.prototype.subRead = function (trigger, readObj, state) {
                    var func = function (obj) {
                        var val = this.convertValue(obj.state.val, readObj.convert);
                
                        //@todo aggregations
                
                        log('executing function before for ' + trigger.id, 'debug');
                        readObj.before(this, val, function (newVal, newDelay) {
                            if (newVal !== undefined && newVal !== null) val = newVal;
                            if (newDelay !== undefined && newDelay !== null) readObj.delay = newDelay;
                            log('reading value ' + val + ' to ' + this.namespace + '.' + state, 'debug');
                            setStateDelayed(this.namespace + '.' + state, val, true, readObj.delay || 0, true, function () {
                                log('executing function after for ' + trigger.id, 'debug');
                                readObj.after(this, val);
                            }.bind(this));
                        }.bind(this));
                    }.bind(this);
                    // initial read on script start
                    func({state: getState(trigger.id)});
                    // create read trigger
                    on(trigger, func);
                }
                
                VirtualDevice.prototype.convertValue = function (val, func) {
                    if (typeof func !== 'function') {
                        return val;
                    }
                    return func(val);
                }
                
                B 1 Antwort Letzte Antwort
                0
                • B Offline
                  B Offline
                  biker1602
                  schrieb am zuletzt editiert von
                  #24

                  Das ist kein Blockly oder? Den Ordner cammon habe ich den main nicht da ich wahrscheinlich schon einige Räume angelegt habe und den vielleicht gelöscht aber halt alles als Blockly Scripte.
                  Mit JS und den anderen habe ich gar keine Erfahrung.

                  1 Antwort Letzte Antwort
                  0
                  • R Offline
                    R Offline
                    R1Snake
                    schrieb am zuletzt editiert von
                    #25

                    Nein das ist kein Blockly sondern Javascript.

                    839c3683-a0bd-4acb-a1d2-48ce4f0ba9bf-image.png

                    Kannst die Struktur so übernehmen.

                    Und beide scripte müssen immer laufen. Zuerst das global script starten.

                    Wenn du so unerfahren bist wie du meinst, können wir kurz telefonieren und mit Teamviewer das ganze umsetzen. Einfach ne Pn schicken

                    B 1 Antwort Letzte Antwort
                    0
                    • X Offline
                      X Offline
                      xbow42
                      schrieb am zuletzt editiert von
                      #26

                      gute Lösung:+1:

                      Kleiner Fehler in der Bezeichnung:writing_hand: :thinking_face: Rolladen-Controller umbenennen in food-Steuerung.:stuck_out_tongue_winking_eye:

                      1 Antwort Letzte Antwort
                      0
                      • R R1Snake

                        Nein das ist kein Blockly sondern Javascript.

                        839c3683-a0bd-4acb-a1d2-48ce4f0ba9bf-image.png

                        Kannst die Struktur so übernehmen.

                        Und beide scripte müssen immer laufen. Zuerst das global script starten.

                        Wenn du so unerfahren bist wie du meinst, können wir kurz telefonieren und mit Teamviewer das ganze umsetzen. Einfach ne Pn schicken

                        B Offline
                        B Offline
                        biker1602
                        schrieb am zuletzt editiert von
                        #27

                        @R1Snake hier in dem Board braucht man ja schon einen Lehrgang um eine PN zu schicken

                        -Alex- 0- 1 Antwort Letzte Antwort
                        0
                        • B biker1602

                          @R1Snake hier in dem Board braucht man ja schon einen Lehrgang um eine PN zu schicken

                          -Alex- 0- Offline
                          -Alex- 0- Offline
                          -Alex- 0
                          schrieb am zuletzt editiert von -Alex- 0
                          #28

                          @biker1602
                          hier mal mein kleiner Vorschlag dafür.. Einfach aber müsste funktionieren.

                          9bca7c57-d62b-4da2-8cce-11aa3f21ce69-image.png

                          <xml xmlns="http://www.w3.org/1999/xhtml">
                           <variables>
                             <variable type="undefined" id="Intervall">Intervall</variable>
                             <variable type="undefined" id="timeout">timeout</variable>
                           </variables>
                           <block type="comment" id="vrVK/df=;#^e3P=znc~y" x="-687" y="63">
                             <field name="COMMENT">Trigger Abenddämmerung</field>
                             <next>
                               <block type="astro" id="h,5.j/zVAK/tX]|)w1xp">
                                 <field name="TYPE">dusk</field>
                                 <field name="OFFSET">0</field>
                                 <statement name="STATEMENT">
                                   <block type="comment" id="Xs!E-G$SQzf{{6])c]l1">
                                     <field name="COMMENT">Falls Fenterkontakt geschlossen</field>
                                     <next>
                                       <block type="controls_if" id="cpU54oKDM@h.oCd?FT^e">
                                         <value name="IF0">
                                           <block type="logic_compare" id="*4HqGcZ`eYf)x.!a8Q4}">
                                             <field name="OP">EQ</field>
                                             <value name="A">
                                               <block type="get_value_var" id="3x2i$x1Ed}3G;T.pTXEU">
                                                 <field name="ATTR">val</field>
                                                 <value name="OID">
                                                   <shadow type="text" id="jCiSWj3po|QZIbSkGdrM">
                                                     <field name="TEXT">Fensterkontakt eintragen</field>
                                                   </shadow>
                                                 </value>
                                               </block>
                                             </value>
                                             <value name="B">
                                               <block type="logic_boolean" id=";LuHi.!$R~}$r+/*3{IE">
                                                 <field name="BOOL">TRUE</field>
                                               </block>
                                             </value>
                                           </block>
                                         </value>
                                         <statement name="DO0">
                                           <block type="comment" id="-|34ccE5Af{YZzcUIH0X">
                                             <field name="COMMENT">hier die ObjektID von "Rollo 2 Tür runter" eintragen</field>
                                             <next>
                                               <block type="control" id="XefW0u?Jo788(GxTAL9)">
                                                 <mutation delay_input="false"></mutation>
                                                 <field name="OID">Object ID</field>
                                                 <field name="WITH_DELAY">FALSE</field>
                                                 <value name="VALUE">
                                                   <block type="logic_boolean" id="}?2Gb_l$$S35vh]Fkjq^">
                                                     <field name="BOOL">TRUE</field>
                                                   </block>
                                                 </value>
                                               </block>
                                             </next>
                                           </block>
                                         </statement>
                                         <next>
                                           <block type="controls_if" id="rmzJr]^#M5t.Z?ekAK6*">
                                             <value name="IF0">
                                               <block type="logic_compare" id="o%+KLg.F|wtdz75!Ms56">
                                                 <field name="OP">EQ</field>
                                                 <value name="A">
                                                   <block type="get_value_var" id="]8+~Sy~5XP~;|@B_q=p~">
                                                     <field name="ATTR">val</field>
                                                     <value name="OID">
                                                       <shadow type="text" id="lO|^pql#3Wf`8j;4$#%6">
                                                         <field name="TEXT">Fensterkontakt eintragen</field>
                                                       </shadow>
                                                     </value>
                                                   </block>
                                                 </value>
                                                 <value name="B">
                                                   <block type="logic_boolean" id="Q+f%ySToKYgepco_#alD">
                                                     <field name="BOOL">FALSE</field>
                                                   </block>
                                                 </value>
                                               </block>
                                             </value>
                                             <statement name="DO0">
                                               <block type="timeouts_clearinterval" id="0g*!5a$H2OW7V:(?%um}">
                                                 <field name="NAME">Intervall</field>
                                                 <next>
                                                   <block type="timeouts_setinterval" id=".JiJ/1Z#Y%.W]BI)*d$1">
                                                     <field name="NAME">Intervall</field>
                                                     <field name="INTERVAL">3</field>
                                                     <field name="UNIT">min</field>
                                                     <statement name="STATEMENT">
                                                       <block type="controls_if" id="VwJyTF`h$Hc(|_hta3(_">
                                                         <value name="IF0">
                                                           <block type="logic_compare" id="SM:wcPkRDtzTTGm4T$pW">
                                                             <field name="OP">EQ</field>
                                                             <value name="A">
                                                               <block type="get_value_var" id="k!IE,w{S9)Syr?~S27j0">
                                                                 <field name="ATTR">val</field>
                                                                 <value name="OID">
                                                                   <shadow type="text" id="}TusHYiNXQBeQCWDB5Y6">
                                                                     <field name="TEXT">Fensterkontakt eintragen</field>
                                                                   </shadow>
                                                                 </value>
                                                               </block>
                                                             </value>
                                                             <value name="B">
                                                               <block type="logic_boolean" id="u.3|.it^G-O4hA;IFPCL">
                                                                 <field name="BOOL">TRUE</field>
                                                               </block>
                                                             </value>
                                                           </block>
                                                         </value>
                                                         <statement name="DO0">
                                                           <block type="comment" id="A+VOL$Oai4%bhn3u1q9B">
                                                             <field name="COMMENT">hier die ObjektID von "Rollo 2 Tür runter" eintragen</field>
                                                             <next>
                                                               <block type="control" id="rFb@bP/GFMq%w*3mtP.I">
                                                                 <mutation delay_input="false"></mutation>
                                                                 <field name="OID">Object ID</field>
                                                                 <field name="WITH_DELAY">FALSE</field>
                                                                 <value name="VALUE">
                                                                   <block type="logic_boolean" id=",Gkm`^-Vm@-g}gJLm3}p">
                                                                     <field name="BOOL">TRUE</field>
                                                                   </block>
                                                                 </value>
                                                                 <next>
                                                                   <block type="timeouts_clearinterval" id="CjSG28%-zCbGN+QoqmEH">
                                                                     <field name="NAME">Intervall</field>
                                                                   </block>
                                                                 </next>
                                                               </block>
                                                             </next>
                                                           </block>
                                                         </statement>
                                                       </block>
                                                     </statement>
                                                     <next>
                                                       <block type="timeouts_cleartimeout" id="%JdNY@-PcAE,}e*ntAM(">
                                                         <field name="NAME">timeout</field>
                                                         <next>
                                                           <block type="timeouts_settimeout" id="9(6[ls-+Celw`q$Q9-{a">
                                                             <field name="NAME">timeout</field>
                                                             <field name="DELAY">60</field>
                                                             <field name="UNIT">min</field>
                                                             <statement name="STATEMENT">
                                                               <block type="timeouts_clearinterval" id="zgNP:ivo42:v|~M2lIvW">
                                                                 <field name="NAME">Intervall</field>
                                                                 <next>
                                                                   <block type="comment" id="?P-QUp~~t[:}urC~LcPR">
                                                                     <field name="COMMENT">hier Meldung über Telegram oder Alexa oder sonst was, das Türe offen war und der Rolladen nicht runterfahren konnte</field>
                                                                   </block>
                                                                 </next>
                                                               </block>
                                                             </statement>
                                                           </block>
                                                         </next>
                                                       </block>
                                                     </next>
                                                   </block>
                                                 </next>
                                               </block>
                                             </statement>
                                           </block>
                                         </next>
                                       </block>
                                     </next>
                                   </block>
                                 </statement>
                               </block>
                             </next>
                           </block>
                          </xml>
                          

                          B 1 Antwort Letzte Antwort
                          0
                          • -Alex- 0- -Alex- 0

                            @biker1602
                            hier mal mein kleiner Vorschlag dafür.. Einfach aber müsste funktionieren.

                            9bca7c57-d62b-4da2-8cce-11aa3f21ce69-image.png

                            <xml xmlns="http://www.w3.org/1999/xhtml">
                             <variables>
                               <variable type="undefined" id="Intervall">Intervall</variable>
                               <variable type="undefined" id="timeout">timeout</variable>
                             </variables>
                             <block type="comment" id="vrVK/df=;#^e3P=znc~y" x="-687" y="63">
                               <field name="COMMENT">Trigger Abenddämmerung</field>
                               <next>
                                 <block type="astro" id="h,5.j/zVAK/tX]|)w1xp">
                                   <field name="TYPE">dusk</field>
                                   <field name="OFFSET">0</field>
                                   <statement name="STATEMENT">
                                     <block type="comment" id="Xs!E-G$SQzf{{6])c]l1">
                                       <field name="COMMENT">Falls Fenterkontakt geschlossen</field>
                                       <next>
                                         <block type="controls_if" id="cpU54oKDM@h.oCd?FT^e">
                                           <value name="IF0">
                                             <block type="logic_compare" id="*4HqGcZ`eYf)x.!a8Q4}">
                                               <field name="OP">EQ</field>
                                               <value name="A">
                                                 <block type="get_value_var" id="3x2i$x1Ed}3G;T.pTXEU">
                                                   <field name="ATTR">val</field>
                                                   <value name="OID">
                                                     <shadow type="text" id="jCiSWj3po|QZIbSkGdrM">
                                                       <field name="TEXT">Fensterkontakt eintragen</field>
                                                     </shadow>
                                                   </value>
                                                 </block>
                                               </value>
                                               <value name="B">
                                                 <block type="logic_boolean" id=";LuHi.!$R~}$r+/*3{IE">
                                                   <field name="BOOL">TRUE</field>
                                                 </block>
                                               </value>
                                             </block>
                                           </value>
                                           <statement name="DO0">
                                             <block type="comment" id="-|34ccE5Af{YZzcUIH0X">
                                               <field name="COMMENT">hier die ObjektID von "Rollo 2 Tür runter" eintragen</field>
                                               <next>
                                                 <block type="control" id="XefW0u?Jo788(GxTAL9)">
                                                   <mutation delay_input="false"></mutation>
                                                   <field name="OID">Object ID</field>
                                                   <field name="WITH_DELAY">FALSE</field>
                                                   <value name="VALUE">
                                                     <block type="logic_boolean" id="}?2Gb_l$$S35vh]Fkjq^">
                                                       <field name="BOOL">TRUE</field>
                                                     </block>
                                                   </value>
                                                 </block>
                                               </next>
                                             </block>
                                           </statement>
                                           <next>
                                             <block type="controls_if" id="rmzJr]^#M5t.Z?ekAK6*">
                                               <value name="IF0">
                                                 <block type="logic_compare" id="o%+KLg.F|wtdz75!Ms56">
                                                   <field name="OP">EQ</field>
                                                   <value name="A">
                                                     <block type="get_value_var" id="]8+~Sy~5XP~;|@B_q=p~">
                                                       <field name="ATTR">val</field>
                                                       <value name="OID">
                                                         <shadow type="text" id="lO|^pql#3Wf`8j;4$#%6">
                                                           <field name="TEXT">Fensterkontakt eintragen</field>
                                                         </shadow>
                                                       </value>
                                                     </block>
                                                   </value>
                                                   <value name="B">
                                                     <block type="logic_boolean" id="Q+f%ySToKYgepco_#alD">
                                                       <field name="BOOL">FALSE</field>
                                                     </block>
                                                   </value>
                                                 </block>
                                               </value>
                                               <statement name="DO0">
                                                 <block type="timeouts_clearinterval" id="0g*!5a$H2OW7V:(?%um}">
                                                   <field name="NAME">Intervall</field>
                                                   <next>
                                                     <block type="timeouts_setinterval" id=".JiJ/1Z#Y%.W]BI)*d$1">
                                                       <field name="NAME">Intervall</field>
                                                       <field name="INTERVAL">3</field>
                                                       <field name="UNIT">min</field>
                                                       <statement name="STATEMENT">
                                                         <block type="controls_if" id="VwJyTF`h$Hc(|_hta3(_">
                                                           <value name="IF0">
                                                             <block type="logic_compare" id="SM:wcPkRDtzTTGm4T$pW">
                                                               <field name="OP">EQ</field>
                                                               <value name="A">
                                                                 <block type="get_value_var" id="k!IE,w{S9)Syr?~S27j0">
                                                                   <field name="ATTR">val</field>
                                                                   <value name="OID">
                                                                     <shadow type="text" id="}TusHYiNXQBeQCWDB5Y6">
                                                                       <field name="TEXT">Fensterkontakt eintragen</field>
                                                                     </shadow>
                                                                   </value>
                                                                 </block>
                                                               </value>
                                                               <value name="B">
                                                                 <block type="logic_boolean" id="u.3|.it^G-O4hA;IFPCL">
                                                                   <field name="BOOL">TRUE</field>
                                                                 </block>
                                                               </value>
                                                             </block>
                                                           </value>
                                                           <statement name="DO0">
                                                             <block type="comment" id="A+VOL$Oai4%bhn3u1q9B">
                                                               <field name="COMMENT">hier die ObjektID von "Rollo 2 Tür runter" eintragen</field>
                                                               <next>
                                                                 <block type="control" id="rFb@bP/GFMq%w*3mtP.I">
                                                                   <mutation delay_input="false"></mutation>
                                                                   <field name="OID">Object ID</field>
                                                                   <field name="WITH_DELAY">FALSE</field>
                                                                   <value name="VALUE">
                                                                     <block type="logic_boolean" id=",Gkm`^-Vm@-g}gJLm3}p">
                                                                       <field name="BOOL">TRUE</field>
                                                                     </block>
                                                                   </value>
                                                                   <next>
                                                                     <block type="timeouts_clearinterval" id="CjSG28%-zCbGN+QoqmEH">
                                                                       <field name="NAME">Intervall</field>
                                                                     </block>
                                                                   </next>
                                                                 </block>
                                                               </next>
                                                             </block>
                                                           </statement>
                                                         </block>
                                                       </statement>
                                                       <next>
                                                         <block type="timeouts_cleartimeout" id="%JdNY@-PcAE,}e*ntAM(">
                                                           <field name="NAME">timeout</field>
                                                           <next>
                                                             <block type="timeouts_settimeout" id="9(6[ls-+Celw`q$Q9-{a">
                                                               <field name="NAME">timeout</field>
                                                               <field name="DELAY">60</field>
                                                               <field name="UNIT">min</field>
                                                               <statement name="STATEMENT">
                                                                 <block type="timeouts_clearinterval" id="zgNP:ivo42:v|~M2lIvW">
                                                                   <field name="NAME">Intervall</field>
                                                                   <next>
                                                                     <block type="comment" id="?P-QUp~~t[:}urC~LcPR">
                                                                       <field name="COMMENT">hier Meldung über Telegram oder Alexa oder sonst was, das Türe offen war und der Rolladen nicht runterfahren konnte</field>
                                                                     </block>
                                                                   </next>
                                                                 </block>
                                                               </statement>
                                                             </block>
                                                           </next>
                                                         </block>
                                                       </next>
                                                     </block>
                                                   </next>
                                                 </block>
                                               </statement>
                                             </block>
                                           </next>
                                         </block>
                                       </next>
                                     </block>
                                   </statement>
                                 </block>
                               </next>
                             </block>
                            </xml>
                            

                            B Offline
                            B Offline
                            biker1602
                            schrieb am zuletzt editiert von
                            #29

                            @Alex-0 said in Blockly um Rollo zu blockieren?:

                            @biker1602
                            hier mal mein kleiner Vorschlag dafür.. Einfach aber müsste funktionieren.

                            9bca7c57-d62b-4da2-8cce-11aa3f21ce69-image.png

                            Super aber kannst du das nicht gleich als Script so hochladen, dass ich es kopieren kann und dann die Datenpunkte nur ändern muss?

                            -Alex- 0- 1 Antwort Letzte Antwort
                            0
                            • B biker1602

                              @Alex-0 said in Blockly um Rollo zu blockieren?:

                              @biker1602
                              hier mal mein kleiner Vorschlag dafür.. Einfach aber müsste funktionieren.

                              9bca7c57-d62b-4da2-8cce-11aa3f21ce69-image.png

                              Super aber kannst du das nicht gleich als Script so hochladen, dass ich es kopieren kann und dann die Datenpunkte nur ändern muss?

                              -Alex- 0- Offline
                              -Alex- 0- Offline
                              -Alex- 0
                              schrieb am zuletzt editiert von
                              #30

                              Super aber kannst du das nicht gleich als Script so hochladen, dass ich es kopieren kann und dann die Datenpunkte nur ändern muss?

                              habe es hinzugefügt.

                              1 Antwort Letzte Antwort
                              0
                              • X Offline
                                X Offline
                                xbow42
                                schrieb am zuletzt editiert von
                                #31

                                kleine Optimierung für @Alex-0 - Script : Die Befehle des 2. Falls können in den 1. Falls-Block als sonst-Bedingung.
                                Ich kann nicht die Anfordeung für den Badlichtschalter sehen und auch nicht die Sicherheitsabfrage(Fensterkontakt) wenn der Rollladen über Alexa runtergefahren wird. Da finde ich die Lösung von @R1Snake mit dem VDP deutlich besser.

                                1 Antwort Letzte Antwort
                                0
                                • R R1Snake

                                  So hab es mal quick and dirty umgeschrieben.

                                  dieses script legst du bei common an:

                                  virtualGosundSwitch('MQTT', 'Abstellraum','Gosund6', 'mqtt.0.SmartHome.Gosund.Gosund6');
                                  
                                  function virtualGosundSwitch(room, name, devname, deviceId) {
                                      var config = {
                                          namespace: room,
                                          name: name,
                                          copy: {common: {name: devname, role: 'variable'}, native: {type: 'switch'}},
                                          states: {
                                              'state': {
                                                  common: {type: 'boolean', def: '', read: false, write: true},
                                                  write: {
                                                      [deviceId + '.cmnd.POWER']: { // Pfad von deinem Button
                                                          convert: function(val) {
                                                              if (val == true)
                                  								if (getState()) //hier den Pfad von deinem Türsensor 
                                  									return false;
                                                                  return true;
                                                              else
                                                                  return false;                              
                                                          }
                                                      }
                                                  }
                                              }           
                                          }
                                      }
                                      return new VirtualDevice(config);
                                  }
                                  

                                  und das bei main:

                                  function VirtualDevice(config) {
                                      //sanity check
                                      if (typeof config !== 'object' || typeof config.namespace !== 'string' || typeof config.name !== 'string' || typeof config.states !== 'object') {
                                          log('sanity check failed, no device created', 'warn');
                                          return;
                                      }
                                  
                                      this.config = config;
                                      this.namespace = 'home.' + config.namespace + '.' + config.name;
                                      this.name = config.name;
                                  
                                      //create virtual device
                                      this.createDevice(function () {
                                          this.createStates(function () {
                                              log('created virtual device ' + this.namespace)
                                          }.bind(this));
                                      }.bind(this));
                                  }
                                  
                                  VirtualDevice.prototype.createDevice = function (callback) {
                                      log('creating object for device ' + this.namespace, 'debug');
                                      //create device object
                                      var obj;
                                      if (typeof this.config.copy == 'string') {
                                          obj = getObject(this.config.copy);
                                      } else if (typeof this.config.copy == 'object') {
                                          obj = this.config.copy;
                                      } else {
                                          obj = {common: {}, native: {}};
                                      }
                                      delete obj.common.custom;
                                      if (typeof this.config.common === 'object') {
                                          obj.common = Object.assign(obj.common, this.config.common);
                                      }
                                      if (typeof this.config.native === 'object') {
                                          obj.native = Object.assign(obj.native, this.config.native);
                                      }
                                      extendObject('javascript.' + instance + '.' + this.namespace, {
                                          type: "device",
                                          common: obj.common,
                                          native: obj.native
                                      }, function (err) {
                                          if (err) {
                                              log('could not create virtual device: ' + this.namespace, 'warn');
                                              return;
                                          }
                                          log('created object for device ' + this.namespace, 'debug');
                                          if (typeof this.config.onCreate === 'function') {
                                              this.config.onCreate(this, callback);
                                          } else {
                                              callback();
                                          }
                                      }.bind(this));
                                  };
                                  
                                  VirtualDevice.prototype.createStates = function (callback) {
                                      "use strict";
                                      log('creating states for device ' + this.namespace, 'debug');
                                      var stateIds = Object.keys(this.config.states);
                                      log('creating states ' + JSON.stringify(stateIds), 'debug');
                                      var countCreated = 0;
                                      for (var i = 0; i < stateIds.length; i++) {
                                          let stateId = stateIds[i];
                                          this.normalizeState(stateId);
                                          var id = this.namespace + '.' + stateId;
                                          log('creating state ' + id, 'debug');
                                          var obj = this.config.states[stateId].copy ? getObject(this.config.states[stateId].copy) : {
                                              common: {},
                                              native: {}
                                          };
                                          delete obj.common.custom;
                                          if (typeof this.config.states[stateId].common === 'object') {
                                              obj.common = Object.assign(obj.common, this.config.states[stateId].common);
                                          }
                                          if (typeof this.config.states[stateId].native === 'object') {
                                              obj.native = Object.assign(obj.native, this.config.states[stateId].native);
                                          }
                                          createState(id, obj.common, obj.native, function (err) {
                                              if (err) {
                                                  log('skipping creation of state ' + id, 'debug');
                                              } else {
                                                  log('created state ' + id, 'debug');
                                              }
                                              this.connectState(stateId);
                                              countCreated++;
                                              if (countCreated >= stateIds.length) {
                                                  log('created ' + countCreated + ' states for device ' + this.namespace, 'debug');
                                                  callback();
                                              }
                                          }.bind(this));
                                      }
                                  };
                                  
                                  VirtualDevice.prototype.normalizeState = function (state) {
                                      log('normalizing state ' + state, 'debug');
                                      if (typeof this.config.states[state].read !== 'object') {
                                          this.config.states[state].read = {};
                                      }
                                      if (typeof this.config.states[state].write !== 'object') {
                                          this.config.states[state].write = {};
                                      }
                                  
                                      var readIds = Object.keys(this.config.states[state].read);
                                      for (var i = 0; i < readIds.length; i++) {
                                          var readId = this.config.states[state].read[readIds[i]];
                                          if (typeof readId.before !== 'function') {
                                              this.config.states[state].read[readIds[i]].before = function (device, value, callback) {
                                                  callback();
                                              };
                                          }
                                          if (typeof readId.after !== 'function') {
                                              this.config.states[state].read[readIds[i]].after = function (device, value) {
                                              };
                                          }
                                      }
                                      var writeIds = Object.keys(this.config.states[state].write);
                                      for (i = 0; i < writeIds.length; i++) {
                                          var writeId = this.config.states[state].write[writeIds[i]];
                                          if (typeof writeId.before !== 'function') {
                                              this.config.states[state].write[writeIds[i]].before = function (device, value, callback) {
                                                  callback();
                                              };
                                          }
                                          if (typeof writeId.after !== 'function') {
                                              this.config.states[state].write[writeIds[i]].after = function (device, value) {
                                              };
                                          }
                                      }
                                      log('normalized state ' + state, 'debug');
                                  };
                                  
                                  VirtualDevice.prototype.connectState = function (state) {
                                      var id = this.namespace + '.' + state;
                                      log('connecting state ' + id, 'debug');
                                      
                                      //subscribe to read ids
                                      var readIds = Object.keys(this.config.states[state].read);
                                      for (var i = 0; i < readIds.length; i++) {
                                          if (getState(readIds[i]).notExist === true) { //check if state exists
                                              log('cannot connect to not existing state: ' + readIds[i], 'warn');
                                              continue;
                                          }
                                          var readObj = this.config.states[state].read[readIds[i]];
                                          var readTrigger = readObj.trigger || {change: 'any'};
                                          readTrigger.ack = true;
                                          readTrigger.id = readIds[i];
                                          this.subRead(readTrigger, readObj, state);
                                          log('connected ' + readIds[i] + ' to ' + id, 'debug');
                                      }
                                  
                                      //subscribe to this state and write to write ids
                                      var writeIds = Object.keys(this.config.states[state].write);
                                      if (writeIds.length > 0) {
                                          var writeTrigger = {id: 'javascript.' + instance + '.' + this.namespace + '.' + state, change: 'any', ack: false};
                                          on(writeTrigger, function (obj) {
                                              "use strict";
                                              log('detected change of ' + state, 'debug');
                                              for (var i = 0; i < writeIds.length; i++) {
                                                  let writeObj = this.config.states[state].write[writeIds[i]];
                                                  let val = this.convertValue(obj.state.val, writeObj.convert);
                                                  let writeId = writeIds[i];
                                                  log('executing function before for ' + writeId, 'debug');
                                                  writeObj.before(this, val, function (newVal, newDelay) {
                                                      if (newVal !== undefined && newVal !== null) val = newVal;
                                                      var delay = writeObj.delay;
                                                      if (newDelay !== undefined && newDelay !== null) delay = newDelay;
                                                      log(newVal + 'writing value ' + val + ' to ' + writeId + ' with delay ' + delay, 'debug');
                                                      setStateDelayed(writeId, val, false, delay || 0, true, function () {
                                                          log('executing function after for ' + writeId, 'debug');
                                                          writeObj.after(this, val);
                                                      }.bind(this));
                                                  }.bind(this));
                                              }
                                          }.bind(this));
                                          log('connected ' + state + ' to ' + JSON.stringify(writeIds), 'debug');
                                      }
                                  }
                                  
                                  VirtualDevice.prototype.subRead = function (trigger, readObj, state) {
                                      var func = function (obj) {
                                          var val = this.convertValue(obj.state.val, readObj.convert);
                                  
                                          //@todo aggregations
                                  
                                          log('executing function before for ' + trigger.id, 'debug');
                                          readObj.before(this, val, function (newVal, newDelay) {
                                              if (newVal !== undefined && newVal !== null) val = newVal;
                                              if (newDelay !== undefined && newDelay !== null) readObj.delay = newDelay;
                                              log('reading value ' + val + ' to ' + this.namespace + '.' + state, 'debug');
                                              setStateDelayed(this.namespace + '.' + state, val, true, readObj.delay || 0, true, function () {
                                                  log('executing function after for ' + trigger.id, 'debug');
                                                  readObj.after(this, val);
                                              }.bind(this));
                                          }.bind(this));
                                      }.bind(this);
                                      // initial read on script start
                                      func({state: getState(trigger.id)});
                                      // create read trigger
                                      on(trigger, func);
                                  }
                                  
                                  VirtualDevice.prototype.convertValue = function (val, func) {
                                      if (typeof func !== 'function') {
                                          return val;
                                      }
                                      return func(val);
                                  }
                                  
                                  B Offline
                                  B Offline
                                  biker1602
                                  schrieb am zuletzt editiert von
                                  #32

                                  @R1Snake said in Blockly um Rollo zu blockieren?:

                                  So hab es mal quick and dirty umgeschrieben.

                                  dieses script legst du bei common an:

                                  virtualGosundSwitch('MQTT', 'Abstellraum','Gosund6', 'mqtt.0.SmartHome.Gosund.Gosund6');
                                  
                                  function virtualGosundSwitch(room, name, devname, deviceId) {
                                      var config = {
                                          namespace: room,
                                          name: name,
                                          copy: {common: {name: devname, role: 'variable'}, native: {type: 'switch'}},
                                          states: {
                                              'state': {
                                                  common: {type: 'boolean', def: '', read: false, write: true},
                                                  write: {
                                                      [deviceId + '.cmnd.POWER']: { // Pfad von deinem Button
                                                          convert: function(val) {
                                                              if (val == true)
                                  								if (getState()) //hier den Pfad von deinem Türsensor 
                                  									return false;
                                                                  return true;
                                                              else
                                                                  return false;                              
                                                          }
                                                      }
                                                  }
                                              }           
                                          }
                                      }
                                      return new VirtualDevice(config);
                                  }
                                  

                                  und das bei main:

                                  function VirtualDevice(config) {
                                      //sanity check
                                      if (typeof config !== 'object' || typeof config.namespace !== 'string' || typeof config.name !== 'string' || typeof config.states !== 'object') {
                                          log('sanity check failed, no device created', 'warn');
                                          return;
                                      }
                                  
                                      this.config = config;
                                      this.namespace = 'home.' + config.namespace + '.' + config.name;
                                      this.name = config.name;
                                  
                                      //create virtual device
                                      this.createDevice(function () {
                                          this.createStates(function () {
                                              log('created virtual device ' + this.namespace)
                                          }.bind(this));
                                      }.bind(this));
                                  }
                                  
                                  VirtualDevice.prototype.createDevice = function (callback) {
                                      log('creating object for device ' + this.namespace, 'debug');
                                      //create device object
                                      var obj;
                                      if (typeof this.config.copy == 'string') {
                                          obj = getObject(this.config.copy);
                                      } else if (typeof this.config.copy == 'object') {
                                          obj = this.config.copy;
                                      } else {
                                          obj = {common: {}, native: {}};
                                      }
                                      delete obj.common.custom;
                                      if (typeof this.config.common === 'object') {
                                          obj.common = Object.assign(obj.common, this.config.common);
                                      }
                                      if (typeof this.config.native === 'object') {
                                          obj.native = Object.assign(obj.native, this.config.native);
                                      }
                                      extendObject('javascript.' + instance + '.' + this.namespace, {
                                          type: "device",
                                          common: obj.common,
                                          native: obj.native
                                      }, function (err) {
                                          if (err) {
                                              log('could not create virtual device: ' + this.namespace, 'warn');
                                              return;
                                          }
                                          log('created object for device ' + this.namespace, 'debug');
                                          if (typeof this.config.onCreate === 'function') {
                                              this.config.onCreate(this, callback);
                                          } else {
                                              callback();
                                          }
                                      }.bind(this));
                                  };
                                  
                                  VirtualDevice.prototype.createStates = function (callback) {
                                      "use strict";
                                      log('creating states for device ' + this.namespace, 'debug');
                                      var stateIds = Object.keys(this.config.states);
                                      log('creating states ' + JSON.stringify(stateIds), 'debug');
                                      var countCreated = 0;
                                      for (var i = 0; i < stateIds.length; i++) {
                                          let stateId = stateIds[i];
                                          this.normalizeState(stateId);
                                          var id = this.namespace + '.' + stateId;
                                          log('creating state ' + id, 'debug');
                                          var obj = this.config.states[stateId].copy ? getObject(this.config.states[stateId].copy) : {
                                              common: {},
                                              native: {}
                                          };
                                          delete obj.common.custom;
                                          if (typeof this.config.states[stateId].common === 'object') {
                                              obj.common = Object.assign(obj.common, this.config.states[stateId].common);
                                          }
                                          if (typeof this.config.states[stateId].native === 'object') {
                                              obj.native = Object.assign(obj.native, this.config.states[stateId].native);
                                          }
                                          createState(id, obj.common, obj.native, function (err) {
                                              if (err) {
                                                  log('skipping creation of state ' + id, 'debug');
                                              } else {
                                                  log('created state ' + id, 'debug');
                                              }
                                              this.connectState(stateId);
                                              countCreated++;
                                              if (countCreated >= stateIds.length) {
                                                  log('created ' + countCreated + ' states for device ' + this.namespace, 'debug');
                                                  callback();
                                              }
                                          }.bind(this));
                                      }
                                  };
                                  
                                  VirtualDevice.prototype.normalizeState = function (state) {
                                      log('normalizing state ' + state, 'debug');
                                      if (typeof this.config.states[state].read !== 'object') {
                                          this.config.states[state].read = {};
                                      }
                                      if (typeof this.config.states[state].write !== 'object') {
                                          this.config.states[state].write = {};
                                      }
                                  
                                      var readIds = Object.keys(this.config.states[state].read);
                                      for (var i = 0; i < readIds.length; i++) {
                                          var readId = this.config.states[state].read[readIds[i]];
                                          if (typeof readId.before !== 'function') {
                                              this.config.states[state].read[readIds[i]].before = function (device, value, callback) {
                                                  callback();
                                              };
                                          }
                                          if (typeof readId.after !== 'function') {
                                              this.config.states[state].read[readIds[i]].after = function (device, value) {
                                              };
                                          }
                                      }
                                      var writeIds = Object.keys(this.config.states[state].write);
                                      for (i = 0; i < writeIds.length; i++) {
                                          var writeId = this.config.states[state].write[writeIds[i]];
                                          if (typeof writeId.before !== 'function') {
                                              this.config.states[state].write[writeIds[i]].before = function (device, value, callback) {
                                                  callback();
                                              };
                                          }
                                          if (typeof writeId.after !== 'function') {
                                              this.config.states[state].write[writeIds[i]].after = function (device, value) {
                                              };
                                          }
                                      }
                                      log('normalized state ' + state, 'debug');
                                  };
                                  
                                  VirtualDevice.prototype.connectState = function (state) {
                                      var id = this.namespace + '.' + state;
                                      log('connecting state ' + id, 'debug');
                                      
                                      //subscribe to read ids
                                      var readIds = Object.keys(this.config.states[state].read);
                                      for (var i = 0; i < readIds.length; i++) {
                                          if (getState(readIds[i]).notExist === true) { //check if state exists
                                              log('cannot connect to not existing state: ' + readIds[i], 'warn');
                                              continue;
                                          }
                                          var readObj = this.config.states[state].read[readIds[i]];
                                          var readTrigger = readObj.trigger || {change: 'any'};
                                          readTrigger.ack = true;
                                          readTrigger.id = readIds[i];
                                          this.subRead(readTrigger, readObj, state);
                                          log('connected ' + readIds[i] + ' to ' + id, 'debug');
                                      }
                                  
                                      //subscribe to this state and write to write ids
                                      var writeIds = Object.keys(this.config.states[state].write);
                                      if (writeIds.length > 0) {
                                          var writeTrigger = {id: 'javascript.' + instance + '.' + this.namespace + '.' + state, change: 'any', ack: false};
                                          on(writeTrigger, function (obj) {
                                              "use strict";
                                              log('detected change of ' + state, 'debug');
                                              for (var i = 0; i < writeIds.length; i++) {
                                                  let writeObj = this.config.states[state].write[writeIds[i]];
                                                  let val = this.convertValue(obj.state.val, writeObj.convert);
                                                  let writeId = writeIds[i];
                                                  log('executing function before for ' + writeId, 'debug');
                                                  writeObj.before(this, val, function (newVal, newDelay) {
                                                      if (newVal !== undefined && newVal !== null) val = newVal;
                                                      var delay = writeObj.delay;
                                                      if (newDelay !== undefined && newDelay !== null) delay = newDelay;
                                                      log(newVal + 'writing value ' + val + ' to ' + writeId + ' with delay ' + delay, 'debug');
                                                      setStateDelayed(writeId, val, false, delay || 0, true, function () {
                                                          log('executing function after for ' + writeId, 'debug');
                                                          writeObj.after(this, val);
                                                      }.bind(this));
                                                  }.bind(this));
                                              }
                                          }.bind(this));
                                          log('connected ' + state + ' to ' + JSON.stringify(writeIds), 'debug');
                                      }
                                  }
                                  
                                  VirtualDevice.prototype.subRead = function (trigger, readObj, state) {
                                      var func = function (obj) {
                                          var val = this.convertValue(obj.state.val, readObj.convert);
                                  
                                          //@todo aggregations
                                  
                                          log('executing function before for ' + trigger.id, 'debug');
                                          readObj.before(this, val, function (newVal, newDelay) {
                                              if (newVal !== undefined && newVal !== null) val = newVal;
                                              if (newDelay !== undefined && newDelay !== null) readObj.delay = newDelay;
                                              log('reading value ' + val + ' to ' + this.namespace + '.' + state, 'debug');
                                              setStateDelayed(this.namespace + '.' + state, val, true, readObj.delay || 0, true, function () {
                                                  log('executing function after for ' + trigger.id, 'debug');
                                                  readObj.after(this, val);
                                              }.bind(this));
                                          }.bind(this));
                                      }.bind(this);
                                      // initial read on script start
                                      func({state: getState(trigger.id)});
                                      // create read trigger
                                      on(trigger, func);
                                  }
                                  
                                  VirtualDevice.prototype.convertValue = function (val, func) {
                                      if (typeof func !== 'function') {
                                          return val;
                                      }
                                      return func(val);
                                  }
                                  

                                  Es wäre einfach geil wenn mir jemand sagen könnte wie man JS von hier kopieren und in scripte einfügen kann.
                                  Ich habe jetzt eine Stunde gebastelt das Ding zu kopieren und irgendwie einzufügen

                                  X 1 Antwort Letzte Antwort
                                  0
                                  • B biker1602

                                    @R1Snake said in Blockly um Rollo zu blockieren?:

                                    So hab es mal quick and dirty umgeschrieben.

                                    dieses script legst du bei common an:

                                    virtualGosundSwitch('MQTT', 'Abstellraum','Gosund6', 'mqtt.0.SmartHome.Gosund.Gosund6');
                                    
                                    function virtualGosundSwitch(room, name, devname, deviceId) {
                                        var config = {
                                            namespace: room,
                                            name: name,
                                            copy: {common: {name: devname, role: 'variable'}, native: {type: 'switch'}},
                                            states: {
                                                'state': {
                                                    common: {type: 'boolean', def: '', read: false, write: true},
                                                    write: {
                                                        [deviceId + '.cmnd.POWER']: { // Pfad von deinem Button
                                                            convert: function(val) {
                                                                if (val == true)
                                    								if (getState()) //hier den Pfad von deinem Türsensor 
                                    									return false;
                                                                    return true;
                                                                else
                                                                    return false;                              
                                                            }
                                                        }
                                                    }
                                                }           
                                            }
                                        }
                                        return new VirtualDevice(config);
                                    }
                                    

                                    und das bei main:

                                    function VirtualDevice(config) {
                                        //sanity check
                                        if (typeof config !== 'object' || typeof config.namespace !== 'string' || typeof config.name !== 'string' || typeof config.states !== 'object') {
                                            log('sanity check failed, no device created', 'warn');
                                            return;
                                        }
                                    
                                        this.config = config;
                                        this.namespace = 'home.' + config.namespace + '.' + config.name;
                                        this.name = config.name;
                                    
                                        //create virtual device
                                        this.createDevice(function () {
                                            this.createStates(function () {
                                                log('created virtual device ' + this.namespace)
                                            }.bind(this));
                                        }.bind(this));
                                    }
                                    
                                    VirtualDevice.prototype.createDevice = function (callback) {
                                        log('creating object for device ' + this.namespace, 'debug');
                                        //create device object
                                        var obj;
                                        if (typeof this.config.copy == 'string') {
                                            obj = getObject(this.config.copy);
                                        } else if (typeof this.config.copy == 'object') {
                                            obj = this.config.copy;
                                        } else {
                                            obj = {common: {}, native: {}};
                                        }
                                        delete obj.common.custom;
                                        if (typeof this.config.common === 'object') {
                                            obj.common = Object.assign(obj.common, this.config.common);
                                        }
                                        if (typeof this.config.native === 'object') {
                                            obj.native = Object.assign(obj.native, this.config.native);
                                        }
                                        extendObject('javascript.' + instance + '.' + this.namespace, {
                                            type: "device",
                                            common: obj.common,
                                            native: obj.native
                                        }, function (err) {
                                            if (err) {
                                                log('could not create virtual device: ' + this.namespace, 'warn');
                                                return;
                                            }
                                            log('created object for device ' + this.namespace, 'debug');
                                            if (typeof this.config.onCreate === 'function') {
                                                this.config.onCreate(this, callback);
                                            } else {
                                                callback();
                                            }
                                        }.bind(this));
                                    };
                                    
                                    VirtualDevice.prototype.createStates = function (callback) {
                                        "use strict";
                                        log('creating states for device ' + this.namespace, 'debug');
                                        var stateIds = Object.keys(this.config.states);
                                        log('creating states ' + JSON.stringify(stateIds), 'debug');
                                        var countCreated = 0;
                                        for (var i = 0; i < stateIds.length; i++) {
                                            let stateId = stateIds[i];
                                            this.normalizeState(stateId);
                                            var id = this.namespace + '.' + stateId;
                                            log('creating state ' + id, 'debug');
                                            var obj = this.config.states[stateId].copy ? getObject(this.config.states[stateId].copy) : {
                                                common: {},
                                                native: {}
                                            };
                                            delete obj.common.custom;
                                            if (typeof this.config.states[stateId].common === 'object') {
                                                obj.common = Object.assign(obj.common, this.config.states[stateId].common);
                                            }
                                            if (typeof this.config.states[stateId].native === 'object') {
                                                obj.native = Object.assign(obj.native, this.config.states[stateId].native);
                                            }
                                            createState(id, obj.common, obj.native, function (err) {
                                                if (err) {
                                                    log('skipping creation of state ' + id, 'debug');
                                                } else {
                                                    log('created state ' + id, 'debug');
                                                }
                                                this.connectState(stateId);
                                                countCreated++;
                                                if (countCreated >= stateIds.length) {
                                                    log('created ' + countCreated + ' states for device ' + this.namespace, 'debug');
                                                    callback();
                                                }
                                            }.bind(this));
                                        }
                                    };
                                    
                                    VirtualDevice.prototype.normalizeState = function (state) {
                                        log('normalizing state ' + state, 'debug');
                                        if (typeof this.config.states[state].read !== 'object') {
                                            this.config.states[state].read = {};
                                        }
                                        if (typeof this.config.states[state].write !== 'object') {
                                            this.config.states[state].write = {};
                                        }
                                    
                                        var readIds = Object.keys(this.config.states[state].read);
                                        for (var i = 0; i < readIds.length; i++) {
                                            var readId = this.config.states[state].read[readIds[i]];
                                            if (typeof readId.before !== 'function') {
                                                this.config.states[state].read[readIds[i]].before = function (device, value, callback) {
                                                    callback();
                                                };
                                            }
                                            if (typeof readId.after !== 'function') {
                                                this.config.states[state].read[readIds[i]].after = function (device, value) {
                                                };
                                            }
                                        }
                                        var writeIds = Object.keys(this.config.states[state].write);
                                        for (i = 0; i < writeIds.length; i++) {
                                            var writeId = this.config.states[state].write[writeIds[i]];
                                            if (typeof writeId.before !== 'function') {
                                                this.config.states[state].write[writeIds[i]].before = function (device, value, callback) {
                                                    callback();
                                                };
                                            }
                                            if (typeof writeId.after !== 'function') {
                                                this.config.states[state].write[writeIds[i]].after = function (device, value) {
                                                };
                                            }
                                        }
                                        log('normalized state ' + state, 'debug');
                                    };
                                    
                                    VirtualDevice.prototype.connectState = function (state) {
                                        var id = this.namespace + '.' + state;
                                        log('connecting state ' + id, 'debug');
                                        
                                        //subscribe to read ids
                                        var readIds = Object.keys(this.config.states[state].read);
                                        for (var i = 0; i < readIds.length; i++) {
                                            if (getState(readIds[i]).notExist === true) { //check if state exists
                                                log('cannot connect to not existing state: ' + readIds[i], 'warn');
                                                continue;
                                            }
                                            var readObj = this.config.states[state].read[readIds[i]];
                                            var readTrigger = readObj.trigger || {change: 'any'};
                                            readTrigger.ack = true;
                                            readTrigger.id = readIds[i];
                                            this.subRead(readTrigger, readObj, state);
                                            log('connected ' + readIds[i] + ' to ' + id, 'debug');
                                        }
                                    
                                        //subscribe to this state and write to write ids
                                        var writeIds = Object.keys(this.config.states[state].write);
                                        if (writeIds.length > 0) {
                                            var writeTrigger = {id: 'javascript.' + instance + '.' + this.namespace + '.' + state, change: 'any', ack: false};
                                            on(writeTrigger, function (obj) {
                                                "use strict";
                                                log('detected change of ' + state, 'debug');
                                                for (var i = 0; i < writeIds.length; i++) {
                                                    let writeObj = this.config.states[state].write[writeIds[i]];
                                                    let val = this.convertValue(obj.state.val, writeObj.convert);
                                                    let writeId = writeIds[i];
                                                    log('executing function before for ' + writeId, 'debug');
                                                    writeObj.before(this, val, function (newVal, newDelay) {
                                                        if (newVal !== undefined && newVal !== null) val = newVal;
                                                        var delay = writeObj.delay;
                                                        if (newDelay !== undefined && newDelay !== null) delay = newDelay;
                                                        log(newVal + 'writing value ' + val + ' to ' + writeId + ' with delay ' + delay, 'debug');
                                                        setStateDelayed(writeId, val, false, delay || 0, true, function () {
                                                            log('executing function after for ' + writeId, 'debug');
                                                            writeObj.after(this, val);
                                                        }.bind(this));
                                                    }.bind(this));
                                                }
                                            }.bind(this));
                                            log('connected ' + state + ' to ' + JSON.stringify(writeIds), 'debug');
                                        }
                                    }
                                    
                                    VirtualDevice.prototype.subRead = function (trigger, readObj, state) {
                                        var func = function (obj) {
                                            var val = this.convertValue(obj.state.val, readObj.convert);
                                    
                                            //@todo aggregations
                                    
                                            log('executing function before for ' + trigger.id, 'debug');
                                            readObj.before(this, val, function (newVal, newDelay) {
                                                if (newVal !== undefined && newVal !== null) val = newVal;
                                                if (newDelay !== undefined && newDelay !== null) readObj.delay = newDelay;
                                                log('reading value ' + val + ' to ' + this.namespace + '.' + state, 'debug');
                                                setStateDelayed(this.namespace + '.' + state, val, true, readObj.delay || 0, true, function () {
                                                    log('executing function after for ' + trigger.id, 'debug');
                                                    readObj.after(this, val);
                                                }.bind(this));
                                            }.bind(this));
                                        }.bind(this);
                                        // initial read on script start
                                        func({state: getState(trigger.id)});
                                        // create read trigger
                                        on(trigger, func);
                                    }
                                    
                                    VirtualDevice.prototype.convertValue = function (val, func) {
                                        if (typeof func !== 'function') {
                                            return val;
                                        }
                                        return func(val);
                                    }
                                    

                                    Es wäre einfach geil wenn mir jemand sagen könnte wie man JS von hier kopieren und in scripte einfügen kann.
                                    Ich habe jetzt eine Stunde gebastelt das Ding zu kopieren und irgendwie einzufügen

                                    X Offline
                                    X Offline
                                    xbow42
                                    schrieb am zuletzt editiert von xbow42
                                    #33

                                    @biker1602 sagte in Blockly um Rollo zu blockieren?:

                                    • im Block hier [select all] anklicken Strg+C drücken.
                                    • in ioBroker Scripte ein neues JS-Script anlegen im richtigen Ordner.
                                    • dann im Fenster ober rechts auf den Button [Code importieren] o.ä. klicken (kann ich leider gerade kein Screenshot von machen)
                                    • im PopUp Strg-V drücken
                                    • PopUp-Fenster unten auf [Speichern] klicken
                                      fertig!
                                    B 1 Antwort Letzte Antwort
                                    0
                                    • X xbow42

                                      @biker1602 sagte in Blockly um Rollo zu blockieren?:

                                      • im Block hier [select all] anklicken Strg+C drücken.
                                      • in ioBroker Scripte ein neues JS-Script anlegen im richtigen Ordner.
                                      • dann im Fenster ober rechts auf den Button [Code importieren] o.ä. klicken (kann ich leider gerade kein Screenshot von machen)
                                      • im PopUp Strg-V drücken
                                      • PopUp-Fenster unten auf [Speichern] klicken
                                        fertig!
                                      B Offline
                                      B Offline
                                      biker1602
                                      schrieb am zuletzt editiert von
                                      #34

                                      @xbow42 ehrlich wer so etwas bearbeiten kann Hut ab. Da wüsste, ich gar nicht wo ich anfangen sollte etwas zu ändern.
                                      Das mit dem einfügen hat geklappt aber das war es dann auch. Das ist mir einfach zu hoch.

                                      1 Antwort Letzte Antwort
                                      0
                                      • R Offline
                                        R Offline
                                        R1Snake
                                        schrieb am zuletzt editiert von
                                        #35

                                        Angebot steht mit Teamviewer.

                                        Damit komme ich auf deinen Rechner und kann dir beim umschreiben helfen.

                                        Passend dazu wäre ein telefonat.

                                        B 1 Antwort Letzte Antwort
                                        0
                                        • R R1Snake

                                          Angebot steht mit Teamviewer.

                                          Damit komme ich auf deinen Rechner und kann dir beim umschreiben helfen.

                                          Passend dazu wäre ein telefonat.

                                          B Offline
                                          B Offline
                                          biker1602
                                          schrieb am zuletzt editiert von
                                          #36

                                          @R1Snake Können wir gerne Morgen machen machen wenn es passt

                                          1 Antwort Letzte Antwort
                                          0
                                          Antworten
                                          • In einem neuen Thema antworten
                                          Anmelden zum Antworten
                                          • Älteste zuerst
                                          • Neuste zuerst
                                          • Meiste Stimmen


                                          Support us

                                          ioBroker
                                          Community Adapters
                                          Donate

                                          654

                                          Online

                                          32.7k

                                          Benutzer

                                          82.4k

                                          Themen

                                          1.3m

                                          Beiträge
                                          Community
                                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                                          ioBroker Community 2014-2025
                                          logo
                                          • Anmelden

                                          • Du hast noch kein Konto? Registrieren

                                          • Anmelden oder registrieren, um zu suchen
                                          • Erster Beitrag
                                            Letzter Beitrag
                                          0
                                          • Home
                                          • Aktuell
                                          • Tags
                                          • Ungelesen 0
                                          • Kategorien
                                          • Unreplied
                                          • Beliebt
                                          • GitHub
                                          • Docu
                                          • Hilfe