Crestron Components Lib - Showcase App

Join Numbers as Signal Names

Emulator Scenario (click to expand)
{
  "cues": [
    {
      "type": "s",
      "event": "22",
      "trigger": "&change",
      "actions": [
        {
          "state": "22",
          "type": "s",
          "logic": "link"
        }
      ]
    },
    {
      "type": "b",
      "event": "update_script_signals_1",
      "trigger": true,
      "actions": [
        {
          "state": "23",
          "type": "n",
          "logic": "set",
          "value": 5
        },
        {
          "state": "24",
          "type": "s",
          "logic": "set",
          "value": "New York"
        }
      ]
    },
    {
      "type": "b",
      "event": "update_script_signals_2",
      "trigger": true,
      "actions": [
        {
          "state": "23",
          "type": "n",
          "logic": "set",
          "value": 10
        },
        {
          "state": "24",
          "type": "s",
          "logic": "set",
          "value": "London"
        }
      ]
    }
  ],
  "onStart": [
    {
      "state": "22",
      "type": "s",
      "value": "String value received from join number state name: 22 (default/onStart value)"
    },
    {
      "state": "23",
      "type": "n",
      "value": 1
    },
    {
      "state": "24",
      "type": "s",
      "value": "Paris"
    }
  ]
}

Press the Load button to load the scenario.

Press the Run button to run the scenario. You only need to do this if the scenario (the json) has an onStart key.

The Emulator Scenario JSON contains an array of cues and an optional array onStart A cue is defined by: type:string, signal:string, trigger:boolean|string|number, actions:array. An action is defined by: type:string, signal:string, logic:string ... plus other fields ( depending on type)

type for cue or for action can be the string:

  • b or boolean - for a boolean signal
  • n or number or numeric - for a number signal
  • s or string - for a string signal
  • o or object - for an object signal

signal for cue or for action is a string representing the name of the signal:

trigger can be either a fixed value of the same type as the signal, or the string "&change". If it is a fixed value then, when the emulator detects that the signal has changed to the value given in trigger then it also executes the actions for that signal. If the value is the string "&change", regardless of signal type, then the actions are executed on any change in the value of the signal.

logic can be:

  • link - passes the value received on the incoming join through to the outgoing join. Using this between incompatible join types will attempt to cast the value. In the event of a cast failure the value will be set to false, 0 or "" (empty string)
  • set - assigns a specific value to the join. This requires a 5th key of 'value' and the specific value to assign. ie. {"signal":"light_level", "type":"n", "logic": "set","value":5}. If the 5th key is omitted, the default value will be sent (false, 0, "" or {})
  • toggle - (boolean Only) reads the current state and changes it to the opposite state
  • pulse - (boolean Only) value goes high and then low.
  • increment - (Numeric Only) reads the current value of the analog and adds an offset. This logic accepts an optional 5th key of 'offset which determines how many to incrementby. ie. {"signal":"volume_level","type":"n", "logic":"increment","offset":5}. If this 5th key is omitted, the default offset of 1 will be applied.
  • decrement - (Numeric Only) reads the current value of the analog and subtracts an offset. This logic accepts an optional 5th key of 'offset which determines how many to decrement by. ie. {"signal":"volume_level","type":"n", "logic":"decrement","offset":5}. If this 5th key is omitted, the default offset of 1 will be applied.

RCB logic can be accomplished by defining an action containing an object signal of RCB type:
{ "rcb":{ "value": numeric_value, "time": duration_in_ms } }
Scenario example:


    {
      "cues": [
        {
          "type": "boolean",
          "signal": "trigger",
          "trigger": true,
          "actions": [
            {
              "signal": "action1",
              "type": "boolean",
              "logic": "toggle"
            },
            {
                "signal": "rcb_signal",
                "type": "object",
                "logic": "set",
                "value": {
                    "rcb":{
                        "value": 101,
                        "time": 1500
                    }
                }
            }
          ]
        }
      ],
      "onStart": [
      ]
    }
    

CrComLib subscribeSignal, unsubscribeSignal, publishSignal, getSignal, subscribeSignalScript, unsubscribeSignalScript with join number as signal name example

subscribeState, unsubscribeState

Target element (div#target) content will be updated using a subscription with a join number state name. The subscription is is made using subscribeState utility function (CrComLib.subscribeState('s','22', (value) => {...}).

* By default state name is `22`, but it can be changed from JS panel code.

Waiting for state value...

publishEvent

Use bellow field to publish it's value using event name `22`.

(CrComLib.publishEvent('s','22', textarea.value)) * Above target div content will be updated (make sure target div subscription is on)

getState

Get last 22 state value (CrComLib.getState())

Last state value:

subscribeStateScript, unsubscribeStateScript

The red bordered element contains the value of the subscribeStateScript function for the following template string "\" City: {{s.24}}; Number: {{ n.23}}; Number*3: \"+{{ n.23 }}*3 " {#You will need to change both 23 and 24 in order for the value to change from the default one.#}

<div class="content">
    <h3>subscribeState, unsubscribeState</h3>
    <p>Target element (div#target) content will be updated using a subscription with a join number state name.
    The subscription is is made using subscribeState utility function
    (CrComLib.subscribeState('s','22', (value) => {...}).</p>

    <p>
        <span class="info">* By default state name is `22`, but it can be changed from JS panel code.</span>
    </p>

    <div id="target">
        Waiting for state value...
    </div>
</div>

<div class="content">
    <h3>publishEvent</h3>
    <p>
        Use bellow field to publish it's value using event name `22`.
    </p>

    <p>
        <input id="inputValueForPublishBtn" type="textarea" placeholder="Enter event string value">
        <button id="btn_publish" class="button is-info" type="button">Publish</button>
        (CrComLib.publishEvent('s','22', textarea.value))
        <span class="info">* Above target div content will be updated (make sure target div subscription is on)</span>
    </p>
    <p>
        <button id="btn_unsub_sig" class="button is-info" type="button">Unsubscribe state 22</button>
    </p>
</div>

<div class="content">
    <h3>getState</h3>
    <p>Get last 22 state value (CrComLib.getState())</p>
    <p>
        <button id="btn_get_signal" class="button is-info" type="button">Get 22 state value</button>
    </p>
    <p>Last state value: <span id="sig_value"></span></p>
</div>


<div class="content">
    <h3>subscribeStateScript, unsubscribeStateScript</h3>
    <p>
        The red bordered element contains the value of the subscribeStateScript function for the following template string
        <code>"\" City: {{s.24}}; Number: {{ n.23}}; Number*3: \"+{{ n.23 }}*3 "</code>
        {#You will need to change both <b>23</b> and <b>24</b> in order for the value to change from the default one.#}
    </p>
    <p>
        <ch5-button type="info" label="Update 23: 'New York' and 24: '5'"
                        sendEventOnClick="update_script_signals_1"></ch5-button>
        <ch5-button type="info" label="Update 23: 'London' and 24: '10'"
                                sendEventOnClick="update_script_signals_2"></ch5-button>
    </p>
    <div id="updated-element" style="border:1px solid blue"></div>

    <p style="margin-top: 24px;">
        <button id="btn_unsub_script" class="button is-info" type="button">Unsubscribe state script</button>
    </p>
</div>