BusDiagram GitHub Download

Examples

#Extension: delayed switching

Two scripts register a delayedSwitch/v1 behavior and a ledStrip view without changing the library. Key 1 sends 1: L1 switches on after 2 seconds and L2, shown as an LED strip, after 1 second. Key 2 sends 0 to switch them off immediately and cancel pending switch-on events.

<bus-diagram>
<script type="application/json">
{
  "formatVersion": 2,
  "title": "Extension · delayed switch",
  "description": "The delayedSwitch/v1 behavior is loaded by an extension script. Key 1 sends 1 and the lamp turns on after 2 seconds; Key 2 sends 0 and cancels a pending turn-on. L2 uses the alternative ledStrip view with the same Boolean state.",
  "lines": [{ "address": "1.1", "name": "Example line" }],
  "groupAddresses": [
    { "address": "1/1/1", "name": "Delayed lighting", "dpt": "1.001" },
    { "address": "1/4/1", "name": "L1 status feedback", "dpt": "1.001" }
  ],
  "devices": [
    {
      "id": "pushButton",
      "name": "Push button",
      "address": "1.1.1",
      "kind": "pushButton",
      "behavior": "pushButton/v1",
      "objects": [
        {
          "id": "key1",
          "name": "Key 1 on",
          "ga": "1/1/1",
          "dpt": "1.001",
          "port": "input",
          "flags": { "W": true, "T": true }
        },
        {
          "id": "key2",
          "name": "Key 2 off",
          "ga": "1/1/1",
          "dpt": "1.001",
          "port": "input",
          "flags": { "W": true, "T": true }
        },
        {
          "id": "status",
          "name": "L1 status",
          "ga": "1/4/1",
          "dpt": "1.001",
          "port": "display",
          "flags": { "W": true, "T": false }
        }
      ],
      "buttons": [
        {
          "id": "key1",
          "label": "Key 1",
          "press": { "object": "key1", "value": 1 },
          "led": "status"
        },
        { "id": "key2", "label": "Key 2", "press": { "object": "key2", "value": 0 } }
      ]
    },
    {
      "id": "switchActuator",
      "name": "Delayed switch",
      "address": "1.1.2",
      "kind": "switchActuator",
      "behavior": "delayedSwitch/v1",
      "objects": [
        {
          "id": "c1",
          "name": "Channel 1",
          "ga": "1/1/1",
          "dpt": "1.001",
          "port": "switch",
          "channel": "s1",
          "flags": { "W": true, "T": false }
        },
        {
          "id": "e1",
          "name": "Status 1",
          "ga": "1/4/1",
          "dpt": "1.001",
          "port": "status",
          "channel": "s1",
          "flags": { "W": false, "T": true }
        },
        {
          "id": "c2",
          "name": "Channel 2",
          "ga": "1/1/1",
          "dpt": "1.001",
          "port": "switch",
          "channel": "s2",
          "flags": { "W": true, "T": false }
        }
      ],
      "channels": [
        {
          "id": "s1",
          "label": "L1",
          "parameters": { "delayMs": 2000 },
          "equipment": { "type": "lamp" }
        },
        {
          "id": "s2",
          "label": "L2",
          "parameters": { "delayMs": 1000 },
          "equipment": { "type": "lamp", "view": "ledStrip" }
        }
      ]
    }
  ],
  "options": { "speed": 1, "filterTables": false }
}
</script>
</bus-diagram>

#Load the scripts

<script src="bus-diagram.js"></script>
<script src="extensions/delayed-switch.js"></script>
<script src="extensions/led-lamp-view.js"></script>

#Source

The TypeScript source at site/samples/extensions/delayed-switch.ts is compiled into a classic script by npm run build. See the extension guide for the behavior API.