Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. Blockly um Rollo zu blockieren?

    NEWS

    • Wir empfehlen: Node.js 22.x

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker goes Matter ... Matter Adapter in Stable

    Blockly um Rollo zu blockieren?

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

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

      Sekunde ich such dir mal ein Script raus

      1 Reply Last reply Reply Quote 0
      • R
        R1Snake last edited by

        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 Reply Last reply Reply Quote 0
        • B
          biker1602 last edited by

          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 Reply Last reply Reply Quote 0
          • R
            R1Snake last edited by

            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 Reply Last reply Reply Quote 0
            • X
              xbow42 last edited by

              gute Lösung👍

              Kleiner Fehler in der Bezeichnung✍ 🤔 Rolladen-Controller umbenennen in food-Steuerung.😜

              1 Reply Last reply Reply Quote 0
              • B
                biker1602 @R1Snake last edited by

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

                -Alex- 0 1 Reply Last reply Reply Quote 0
                • -Alex- 0
                  -Alex- 0 @biker1602 last edited by -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 1 Reply Last reply Reply Quote 0
                  • B
                    biker1602 @-Alex- 0 last edited by

                    @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 Reply Last reply Reply Quote 0
                    • -Alex- 0
                      -Alex- 0 @biker1602 last edited by

                      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 Reply Last reply Reply Quote 0
                      • X
                        xbow42 last edited by

                        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 Reply Last reply Reply Quote 0
                        • B
                          biker1602 @R1Snake last edited by

                          @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 Reply Last reply Reply Quote 0
                          • X
                            xbow42 @biker1602 last edited by 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 1 Reply Last reply Reply Quote 0
                            • B
                              biker1602 @xbow42 last edited by

                              @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 Reply Last reply Reply Quote 0
                              • R
                                R1Snake last edited by

                                Angebot steht mit Teamviewer.

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

                                Passend dazu wäre ein telefonat.

                                B 1 Reply Last reply Reply Quote 0
                                • B
                                  biker1602 @R1Snake last edited by

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

                                  1 Reply Last reply Reply Quote 0
                                  • S
                                    Stephiobroker last edited by

                                    Halllo,
                                    habt Ihr es auch hinbekommen Zwischenpositionen anzufahren?

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

                                    Support us

                                    ioBroker
                                    Community Adapters
                                    Donate

                                    923
                                    Online

                                    32.0k
                                    Users

                                    80.5k
                                    Topics

                                    1.3m
                                    Posts

                                    blockly
                                    6
                                    37
                                    2670
                                    Loading More Posts
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    Community
                                    Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                    The ioBroker Community 2014-2023
                                    logo