Crestron Components Lib - Showcase App

ch5-template receive state, send event

Emulator Scenario (click to expand) (click to collapse)
{
  "cues": [
       {
      "type": "boolean",
      "event": "toggle_second_pair_of_template",
      "trigger": true,
      "actions": [
        {
          "state": "show_second_pair_of_template",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "directv.prevtrack_clicked",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button",
          "type": "s",
          "logic": "set",
          "value": "prev track clicked"
        },
        {
          "state": "receive.prevtrack_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "directv.play_clicked",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button",
          "type": "s",
          "logic": "set",
          "value": "play clicked"
        },
        {
          "state": "receive.play_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "directv.nexttrack_clicked",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button",
          "type": "s",
          "logic": "set",
          "value": "next button clicked"
        },
        {
          "state": "receive.nexttrack_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "directv.record_clicked",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button",
          "type": "s",
          "logic": "set",
          "value": "record button clicked"
        },
        {
          "state": "receive.record_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "directv.stop_clicked",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button",
          "type": "s",
          "logic": "set",
          "value": "stop button clicked"
        },
        {
          "state": "receive.stop_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "directv.pause_clicked",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button",
          "type": "s",
          "logic": "set",
          "value": "pause button clicked"
        },
        {
          "state": "receive.pause_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    }
  ],
  "onStart":[
    {
      "state": "selected_button",
      "type": "s",
      "value": "no button clicked"
    },
     {
      "type": "b",
      "state": "show_second_pair_of_template",
      "value": true
    },
    {
      "type": "b",
      "state": "show_button",
      "value": false
    }
  ]
}
Emulator actions

Press the Load button to load the scenario. This will also reload all of the existing examples on the page.

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

Events and states

The Emulator Scenario JSON contains an array of cues and an optional array onStart.

→ A cue is defined by: type:string, event:string, trigger:boolean|string|number, actions:array
→ An action is defined by: type:string, state:string, logic:string ... plus other fields ( depending on type)

The value of the state or event for a cue or for an action is a string which represents the name of that state or action.

Type field

The type for cue or for action can be the string:

  • b or boolean - for a boolean state or event
  • n or number or numeric - for a number state or event
  • s or string - for a string state or event
  • o or object - for an object state or event
Trigger field

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

Logic Field

The 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. {"state":"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 times to increment by. ie. {"event":"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 times to decrement by. ie. {"event":"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 state or event of RCB type. A 5th key is expected as the amount of time in milliseconds to reach the level. {"signal":"light_level", "type":"n", "logic": "rcb","value":65535, "time":2000}
    { "rcb":{ "value": numeric_value, "time": duration_in_ms } }
Scenario example:

    {
      "cues": [
        {
          "type": "boolean",
          "event": "trigger",
          "trigger": true,
          "actions": [
            {
              "state": "action1",
              "type": "boolean",
              "logic": "toggle"
            },
            {
                "state": "rcb_signal",
                "type": "object",
                "logic": "set",
                "value": {
                    "rcb":{
                        "value": 101,
                        "time": 1500
                    }
                }
            }
          ]
        }
      ],
      "onStart": [
      ]
    }
    
send and receive signals for components used with ch5-template(s)

All the buttons below are generated via ch5-template. When a button from the second row is clicked the corresponding button from the row above will be toggled.

The first ch5-template will receive an attribute "templateId" which represents the id of the template it needs to generate, in this case the id will be: "transportbuttons". The second attribute is the context: "TRANSBTNS:receive".

  • The first substring before the colon represents the original name of the signal while the second one represents the replacement name.
  • Therefore if a component has a receiveStateSelected="TRANSBTNS.prevtrack_selected" attribute, its value will become receiveStateSelected="receive.prevtrack_selected"
[Testing ch5-template]

The template can be reused again by providing another ch5-template, in this case the context is identical so the same signals will be used.


Ch5-template supports all ch5-common attributes. In this example you can toggle the visibility of the second pair of ch5-templates via the receiveStateShow signal by clicking the button below.

    <p>
        All the buttons below are generated via ch5-template.
        When a button from the second row is clicked the corresponding button from the row above will be toggled.
    </p>

    <p>The first ch5-template will receive an attribute <i>"templateId"</i> which represents the id of the template it
        needs to
        generate, in this case the id will be: <i>"transportbuttons"</i>. The second attribute is the context:
        "TRANSBTNS:receive". </p>
    <ul>
        <li>
            The
            first substring before the colon represents the original name of the signal while the second one
            represents the replacement name.
        </li>
        <li>Therefore if a component has a receiveStateSelected="<i><b>TRANSBTNS</b>.prevtrack_selected"</i> attribute,
            its value will
            become receiveStateSelected="<i><b>receive</b>.prevtrack_selected"</i>
        </li>
    </ul>

    <template id="transportbuttons">
        <div class="TRANSBTNS">
            <ch5-button customClass="trnsbtns__prev"
                        id="TRANSBTNS.prevtrack"
                        shape="rounded-rectangle"
                        iconClass="material-icons fast_rewind"
                        sendEventOnClick="TRANSBTNS.prevtrack_clicked"
                        receiveStateSelected="TRANSBTNS.prevtrack_selected">
            </ch5-button>
            <ch5-button customClass="trnsbtns__play"
                        id="TRANSBTNS.play"
                        shape="rounded-rectangle"
                        iconClass="material-icons play_arrow"
                        sendEventOnClick="TRANSBTNS.play_clicked"
                        receiveStateSelected="TRANSBTNS.play_selected">
            </ch5-button>
            <ch5-button customClass="trnsbtns__next"
                        id="TRANSBTNS.nexttrack"
                        shape="rounded-rectangle"
                        iconClass="material-icons fast_forward"
                        sendEventOnClick="TRANSBTNS.nexttrack_clicked"
                        receiveStateSelected="TRANSBTNS.nexttrack_selected">
            </ch5-button>
            <ch5-button customClass="trnsbtns__record"
                        id="TRANSBTNS.record"
                        shape="rounded-rectangle"
                        iconClass="material-icons fiber_manual_record"
                        sendEventOnClick="TRANSBTNS.record_clicked"
                        receiveStateSelected="TRANSBTNS.record_selected">
            </ch5-button>
            <ch5-button customClass="trnsbtns__stop"
                        id="TRANSBTNS.stop"
                        shape="rounded-rectangle"
                        iconClass="material-icons stop"
                        sendEventOnClick="TRANSBTNS.stop_clicked">
            </ch5-button>
            <ch5-button customClass="trnsbtns__pause"
                        id="TRANSBTNS.pause"
                        shape="rounded-rectangle"
                        iconClass="material-icons pause"
                        sendEventOnClick="TRANSBTNS.pause_clicked"
                        receiveStateSelected="TRANSBTNS.pause_selected">
            </ch5-button>
        </div>
    </template>
    <template id="transportbuttons_nextline">
        <div class="TRANSBTNS">
            <ch5-button shape="rounded-rectangle" type="text"
                        iconClass="material-icons fast_rewind"
                        receiveStateSelected="TRANSBTNS.prevtrack_selected">
            </ch5-button>
            <ch5-button shape="rounded-rectangle" type="text"
                        iconClass="material-icons play_arrow"
                        receiveStateSelected="TRANSBTNS.play_selected">
            </ch5-button>
            <ch5-button shape="rounded-rectangle" type="text"
                        iconClass="material-icons fast_forward"
                        receiveStateSelected="TRANSBTNS.nexttrack_selected">
            </ch5-button>
            <ch5-button shape="rounded-rectangle" type="text"
                        iconClass="material-icons fiber_manual_record"
                        receiveStateSelected="TRANSBTNS.record_selected">
            </ch5-button>
            <ch5-button shape="rounded-rectangle" type="text"
                        iconClass="material-icons stop"
                        receiveStateSelected="TRANSBTNS.stop_selected">
            </ch5-button>
            <ch5-button shape="rounded-rectangle" type="text"
                        iconClass="material-icons pause"
                        receiveStateSelected="TRANSBTNS.pause_selected">
            </ch5-button>
        </div>
    </template>


    <ch5-template id="receive"
                  templateid="transportbuttons_nextline"
                  context="TRANSBTNS:receive"></ch5-template>

    <ch5-template id="directv"
                  receiveStateShow="show_second_pair_of_template"
                  templateid="transportbuttons"
                  context="TRANSBTNS:directv"></ch5-template>

    <div id="textcontent" class="b-red"
         data-ch5-textcontent="selected_button">
        [Testing ch5-template]
    </div>

    <p>
        The template can be reused again by providing another ch5-template, in this case the context is identical so the
        same signals will be used.
    </p>

    <ch5-template id="directv"
                  receiveStateShow="show_second_pair_of_template"
                  templateid="transportbuttons"
                  context="TRANSBTNS:directv"></ch5-template>
    <br>
    <p>Ch5-template supports all ch5-common attributes. In this example you can toggle the visibility of the second pair
        of
        ch5-templates via the <i>receiveStateShow</i> signal by clicking the button below.</p>
    <ch5-button label="Toggle the visibility of the second pair of ch5-templates"
                sendEventOnClick="toggle_second_pair_of_template"></ch5-button>