Ankündigung

Einklappen
Keine Ankündigung bisher.

X1 Logic Node: Scripting - One block. Endless possibilities.

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    X1 X1 Logic Node: Scripting - One block. Endless possibilities.

    Introducing the SCRIPTING Logic Node for Gira X1 and L1

    With the SCRIPTING Logic Node you can combine calculations, text processing and custom logic into a single powerful block, replacing multiple formula, formatter and parser modules at once.

    Build compact logic flows, reduce wiring complexity and create advanced automations with just a few lines of code. From smart data handling to dynamic text generation and complex conditions: everything runs inside one fast, flexible node.

    Finally, real JavaScript scripting inside your logic project!​
    This logic node crushes the Formelberechnung​, Textformatierer, JSON-Parser and many other logic nodes with it's easy, flexible and lightweight use.

    One block. Endless possibilities.

    All examples and a code editor can be found here: https://www.roelbroersma.nl/scripting (see there for the very handy code editor which makes your scripts 1-liners)

    The logic node has an Auto Update Check (during validation in the GPA) and during operation on the X1/L1 so you will get notified of updates!
    Tip: Ask AI for a script (see below!)

    Download: https://www.roelbroersma.nl/media/do...0.1.000024.zip


    X1_Logic_Node_Scripting.png

    How it works:


    Sending any value to the Trigger port (bool/number/text, even false or zero) will execute the script.

    Output ports will only change when set in the script. If the script doesn’t set the output port, it will not change, so

    PHP-Code:
    if (IN1=5OUT1=1;​ 
    will only set the Output port when Input1=5. If you always want to set the value, use

    PHP-Code:
    if (IN1=5OUT1=1;else OUT1=0;​ 
    Trigger the block when it received something at INPUT1? Do it like this:
    (don't worry about timing issues, it will first fill the inputs and then trigger the block)
    image.png


    Some examples:


    NUMBERS
    PHP-Code:
    OUT1 IN1 1.19;                        // Multiply with Mwst.

    OUT1 IN1 IN2 IN3 + (IN4+2)           // Set Output sum.

    OUT1 IN1 IN2OUT2 IN1 IN2;      // Set multiple outputs in one time

    OUT1 = (IN1 255) * 100;                        // Devide and use ( and )

    OUT1 Math.round(IN1 100) / 100;        // Math.round will always round on whole number, to have two decimals, device by 100.

    OUT1 Math.min(Math.max(IN10), 100);    // Limit the Input between 0 and 100

    OUT1 Math.abs(IN1);                    // Inverse: -5 -> 5

    OUT1 = -IN1;                            // Also 5 -> -5

    OUT1 Math.pow(IN12);                // (power of 2): IN1²

    OUT1 Math.sqrt(IN1);                    // (taking the root): √IN1​ 


    String manipulation (text)
    PHP-Code:
    OUT1 "Hello there!";       // Set a simple text to Output1

    OUT1 "Value is: " IN1;             // Set combined text+value. Example: "Value is: 10"

    OUT1 "My " IN1 " has " IN2 " homes"// Concatenate Strings. Example: "My Son has 2 homes"

    OUT1 IN1.toString().substring(05);       // Take the first 5 characters (start at character 0)

    OUT1 IN1.toString().substring(05);       // Trim spaces

    if (IN1.length 10OUT1 IN1.substring(010) + "..."// Shorten text to 10 characters + "..."
    else OUT1 IN1;

    OUT1 IN1.toString().substring(05);         // Take the first 5 characters (start at character 0)

    OUT1 IN1.replace(/,/g,".");       // Replace all commas by dots.

    OUT1 IN1.slice(-3);                   // Remove last 3 characters 

    LOGIC
    PHP-Code:
    if (IN1=1OUT1=1                // Use If to set output ONLY if IN1=1, otherwise do NOT set the output.

    var temp IN1;                     // Declare a variable and use it or
    OUT1 tempt;

    i=1;
    OUT1 this["IN"+1]                // Computed variabe: OUT1=IN1

    if (IN1 >= 50OUT1 1;        // Use if else
    else OUT1 0;

    if (
    IN1==1OUT1 1;            // Use if, elseif, else
    else if (IN2==1OUT1 2;
    else if (
    IN3==1OUT1 3;
    else 
    OUT1 0;

    if (
    OUT1==&& IN2==0OUT2 123;     // Read the value of OUT1

    switch(IN1) {                       // Switch Logic (easier than if/elseif/else)
      
    case 0OUT1 "OFF"; break;
      case 
    1OUT1 "AUTO"; break;
      case 
    2OUT1 "MANUAL"; break;
      default: 
    OUT1 "UNKNOWN";
    }

    for (var 
    1<= 5i++) {        // A FOR Loop
      
    if (this["IN" i] == true) {        // The computed variable IN1...IN5
        
    OUT1 i;
        break;
      }
    }
    ​ 

    JSON
    Let's take the following sample JSON to explain:
    PHP-Code:
    {
      
    "device": {
        
    "name""LivingRoomController",
        
    "status""online",
        
    "metrics": {
          
    "temperature"21.6,
          
    "humidity"48,
          
    "power"312.4
        
    },
        
    "modes": [
          { 
    "id"1"name""Auto""active"true },
          { 
    "id"2"name""Eco""active"false },
          { 
    "id"3"name""Boost""active"false }
        ]
      }
    }
    ​​ 
    PHP-Code:
    ​var obj JSON.parse(IN1); // Read Input1 as JSON

    OUT1 obj.device.name// "LivingRoomController"

    OUT2 obj.device.metrics.temperature// 21.6

    OUT3 obj.device.modes[0].name// "Auto"

    OUT4 obj.device.modes[2].active// false

    OUT5 obj.device.modes.length// 3

    OUT6 obj.device.status " / " obj.device.metrics.power "W"


    You can even ask AI (ChatGPT, CoPilot or DeepSeek):

    "Hello, can you generate JavaScript code for the Gira X1 Scripting Logic Module (see examples at https://www.roelbroersma.nl/scripting)?
    I have 2 inputs and 1 output.
    • IN1 = weather information as text
    • IN2 = expected afternoon temperature (number)
    Requirements:
    • Output format: Temp: XX°C - DESCRIPTION
    • DESCRIPTION must be truncated to 20 characters and end with .. if longer
    • Use only plain JavaScript compatible with Jint
    • Assign the result to OUT1"


    CHANGE LOG

    v0.1.000024 (02-feb-2026)
    • Fix: Update Notification in GPA (didn't work!).
    • Fix: You couldn't Trigger the block when not all inputs are set, fixed by pre-filling with 0 (zero).
    • Fix: A lot of small fixes ans possible NullPointerExceptions.
    • Future: Implemented great Debug logging (enable Debug to see what's happening).
    • Future: Debugging shows script execution time. (a hard limit is set at 200ms).

    ​v0.1.000018 (01-feb-2026)
    • Initial version
    • Tested on Gira GPA v6.0. X1: v3.0.52 and L1: v2.5.149, but may work on lower versions.




    Zuletzt geändert von Roeller; Gestern, 16:36.

    #2
    First comment reserved for future use

    Kommentar


      #3
      Second comment reserved for future use

      Kommentar


        #4
        Mega logic block. That simplifies things considerably!

        Kommentar


          #5
          Zitat von Roeller Beitrag anzeigen
          This logic node crushes the Formelberechnung​, Textformatierer, JSON-Parser and many other logic nodes with it's easy, flexible and lightweight use.
          OK, as the author of what you obviously perceive as your major "competition", let me say the following:
          1. Congrats for pushing the limits of what the X1/L1 can do with this really cool beast. If I had to choose but one of the third-party nodes it would probably be this one over even any of my own because of its endless flexibility.
          2. Its power and complexity may not always be needed. If all you need is a few calculations that can make nice use of built-in functions of Expression Calculator ("Formelberechnung"), it will be much simpler to use. For example, try to calculate a heating curve with JavaScript. You will end up with much more complexity than just using the ready-made function in Expression Calculator.
          3. Same goes for the others you mention, in cases where the combination of features simply isn't needed.
          Bottom line: You don't put me out of "business" (yet), but the bar has just raised. Next challenges:
          • Have all the builtins of Expression Calculator also available in "Scripting".
          • Open-Source "Scripting" to assure users it cannot simply go away or change its licensing.

          Kommentar


            #6
            Hi,

            very promising.

            Feature request: Add option to trigger on IN# value reception (specific or any).

            But: the in-operation update checker. A closed source scripting logic block communicating with online servers - not too attractive. I propose to remove this feature, along with making the logic node open source.

            See you
            Zuletzt geändert von maximilianeum; Gestern, 10:17.

            Kommentar


              #7
              Zitat von hyman Beitrag anzeigen

              OK, as the author of what you obviously perceive as your major "competition", let me say the following:
              When I say crushing, it’s of course meant in a playful way, we’re not competitors, but friends on the same platform. And friends help friends by pushing the ecosystem forward together.​

              It would be great to see Gira occasionally release official logic building blocks as well, with a small dedicated team of enthusiastic developers focused purely on creating and improving these tools. In the meantime… it’s up to us.

              Agreed: scripting is not a replacement for all native blocks, but a flexible addition.

              I’ve been building tools and logic for both the HomeServer and the X1/L1 platform for over 15 years now, so this comes from long-term involvement and passion for the ecosystem. I’ve never charged money for any of this work and don’t plan to do so for current projects either. Regarding an “official license” (MIT, Apache, Creative Commons, etc.): I honestly hadn’t thought about that yet, good point!

              The update check is something I try to build into all blocks because there currently is no native Gira mechanism for this. Hopefully this will be integrated into GPA someday (and I hope via their own infrastructure). You don’t want to manually browse logic node websites and forum threads every few months just to check for updates.
              It currently does two things:
              1. Check the version during project validation (in GPA) and raises an error when an outdated version is detected.
              2. Check the version about once a week and give and sets the “Update available” output to 1. You can connect the update to a mail or notification block so you know there is an update. That's automation

              Teaser: Currently I’m working on another building block which I’ll try to release this week, for DUCO ventilation systems. These systems offer both API and Modbus, but the module I’m building makes integration extremely simple: it automatically discovers the unit via mDNS and does not require API authentication because it uses Modbus on the underlying layer. You can connect a DUCO system within minutes! A huge difference compared to manual API parsing or Modbus address mapping. When the IP of the Duco box changes,.. no problem.. it gets the new IP address.
              And yes: thas module will also be (and stay!) free.


              Kommentar


                #8
                Zitat von maximilianeum Beitrag anzeigen
                Hi,

                very promising.

                Feature request: Add option to trigger on IN# value reception (specific or any).
                See you
                I first had the same idea, but this can be easily done with 1 line, see this example:

                image.png


                Kommentar


                  #9
                  Great work! An obvious question. Are you thinking about developing a similar node for the Homeserver?

                  Kommentar


                    #10
                    Update:

                    v0.1.000024 (02-feb-2026)
                    • Fix: Update Notification in GPA (didn't work!).
                    • Fix: You couldn't Trigger the block when not all inputs are set, fixed by pre-filling with 0 (zero).
                    • Fix: A lot of small fixes ans possible NullPointerExceptions.
                    • Future: Implemented great Debug logging (enable Debug to see what's happening).
                    • Future: Debugging shows script execution time. (a hard limit is set at 200ms).

                    I noticed that I accidentally uploaded version v0.1.000006 (a pre-release version, with the name v0.1.000018 in the link) which was cached by Cloudflare...
                    The update-notification is not even working in that version, so you won't see there is an update. (murphy's law )

                    Kommentar

                    Lädt...
                    X