{
    "title": "Switch Configuration",
    "description": "Toggle switches that show an on/off state and change it on click: a switch calls a device action, stores its position in a table (targetColumn), or sets a URL parameter that other widgets filter on (parameterKey). Several switches fit in one tile, drawn small, normal or big.",
    "aiSelection": {
        "dataShape": "One value per switch, read as ON or OFF through stateMap. A click fires the switch's device action (actionApp, actionTopic), or with targetColumn writes a row: true or false plus extraColumns such as a record id, with value bound to the same column. A switch with parameterKey needs no data: while ON the URL parameter holds parameterValue (default 'true'), while OFF it is removed.",
        "useWhen": [
            "A binary device state an operator should see and change — a pump, a light, a valve, an enable flag.",
            "An on/off setting stored per record, such as a feature turned on for one model: targetColumn, with the record id in extraColumns.",
            "An on/off view filter such as 'only alarms': parameterKey and parameterValue, and each widget to narrow gets a filterAnd condition with useFilter: true and the parameterKey as value. While OFF they show everything."
        ],
        "notFor": [
            "Choosing among several filter values, or a filter whose OFF state is another value — use widget-filter-dropdown.",
            "A status users must not change, or more than two states — use widget-signal.",
            "Text, numbers or choices that are entered and stored, or several settings saved together — use widget-form.",
            "The history of the switching — use widget-statehistory.",
            "A tank, valve or pump drawn as itself and animated — use widget-scada."
        ]
    },
    "type": "object",
    "properties": {
        "title": {
            "title": "Title",
            "description": "The main heading displayed above the switch controls. Use to describe the control group (e.g., 'Light Controls', 'Pump Switches').",
            "type": "string",
            "order": 1
        },
        "subTitle": {
            "title": "Subtitle",
            "description": "Secondary text displayed below the title. Use for additional context like location, device group, or instructions.",
            "type": "string",
            "order": 2
        },
        "size": {
            "title": "Size",
            "description": "How large the switches and their labels are drawn. 'small' fits dense control panels, 'normal' is the default, and 'big' suits touch screens and wall displays.",
            "type": "string",
            "enum": ["small", "normal", "big"],
            "enumLabels": {
                "small": "Small",
                "normal": "Normal",
                "big": "Big"
            },
            "default": "normal",
            "dataDrivenDisabled": true,
            "order": 3
        },
        "dataseries": {
            "title": "Switches",
            "description": "Array of switch configurations. Each entry creates a toggle switch with its own state mapping and optional device action binding, or with a URL parameter it sets.",
            "type": "array",
            "order": 4,
            "items": {
                "type": "object",
                "properties": {
                    "label": {
                        "title": "Label",
                        "description": "Display text identifying this switch. Should clearly describe what the switch controls (e.g., 'Main Power', 'Pump 1', 'Night Mode').",
                        "type": "string",
                        "order": 1
                    },
                    "description": {
                        "title": "Hint Text",
                        "description": "Helper text displayed below the switch label to guide the operator. Use for what the switch does, when it is safe to flip it, or how long the action takes.",
                        "type": "string",
                        "order": 2
                    },
                    "stateMap": {
                        "title": "State Map",
                        "description": "Defines how data values are interpreted as switch states. Configure which values represent ON and OFF. A value matching neither shows the switch OFF. Not needed when URL Parameter Key is set.",
                        "type": "object",
                        "required": true,
                        "order": 3,
                        "properties": {
                            "on": {
                                "title": "ON Values",
                                "description": "Values that indicate the ON state. Can be: a single value ('1', 'true', 'ON'), comma-separated list ('1,true,ON'), or numeric expression ('<4' means values below 4 are ON, '>33' means values above 33 are ON). If a value matches both ON and OFF, ON takes precedence.",
                                "type": "string",
                                "required": true
                            },
                            "off": {
                                "title": "OFF Values",
                                "description": "Values that indicate the OFF state. Can be: a single value ('0', 'false', 'OFF'), comma-separated list ('0,false,OFF'), or numeric expression ('<4' means values below 4 are OFF, '>33' means values above 33 are OFF). A value matching neither ON nor OFF also shows the switch OFF.",
                                "type": "string",
                                "required": true
                            }
                        }
                    },
                    "value": {
                        "title": "Switch State",
                        "type": "string",
                        "description": "The current state value from the backend, used to display the correct switch position. Strongly recommended to bind this to the actual device state column to keep the visual state synchronized with the physical device state: after a click the switch waits up to 10 seconds for this value to confirm the new position, then returns to the position it reports. Without a value the switch keeps the position the operator last set. Not needed when URL Parameter Key is set.",
                        "required": false,
                        "order": 4
                    },
                    "actionDevice": {
                        "title": "Action Device Target",
                        "description": "The device that receives commands when the switch is clicked. In data-driven mode, bind to a 'Device ID' column to dynamically target different devices per row.",
                        "type": "actionDevice",
                        "order": 5
                    },
                    "actionApp": {
                        "title": "Action App",
                        "description": "The application/service on the target device that handles the switch command. Select from available apps installed on the device.",
                        "dataDrivenDisabled": true,
                        "type": "actionApp",
                        "order": 6
                    },
                    "actionTopic": {
                        "title": "Action App Topic",
                        "description": "The specific command/topic sent to the app when the switch is clicked. Arguments sent are: True for turning ON, False for turning OFF. Refer to the app's documentation for available topics.",
                        "type": "string",
                        "order": 7
                    },
                    "parameterKey": {
                        "title": "URL Parameter Key",
                        "description": "Turns this switch into a view control: the NAME of the URL parameter it sets (e.g. 'onlyAlarms'). While the switch is ON the parameter holds the URL Parameter Value; while it is OFF the parameter is removed. The switch's position then follows the URL, so it survives a reload and a shared link, and it fires no device action — State Map, Switch State and the action settings are ignored. Every widget that should follow this switch needs a filterAnd condition with \"useFilter\": true and exactly this name as the bare \"value\" — e.g. {\"column\": \"status\", \"operator\": \"=\", \"value\": \"onlyAlarms\", \"useFilter\": true, \"dataType\": \"string\"}. While the switch is OFF the frontend drops that condition and the widget shows unfiltered data.",
                        "type": "string",
                        "dataDrivenDisabled": true,
                        "order": 8
                    },
                    "parameterValue": {
                        "title": "URL Parameter Value",
                        "description": "The value written into the URL parameter while the switch is ON. Defaults to 'true'. A widget following this switch compares it against its own filtered column, so it must match the values stored in that column exactly (same spelling and case), e.g. 'ALARM'. Only used when URL Parameter Key is set.",
                        "type": "string",
                        "dataDrivenDisabled": true,
                        "order": 9
                    },
                    "targetColumn": {
                        "title": "Write to Column",
                        "description": "Stores the switch's position in a table: every click writes a row, with true in this column for ON and false for OFF (1 and 0 in a numeric column), plus the Extra Columns, as a form does. Bind Switch State to the latest value of the same column, filtered to the same record, and set State Map to on 'true', off 'false', so the switch shows what is stored. A device action still fires when Action App Topic is set. Ignored when URL Parameter Key is set.",
                        "type": "targetColumn",
                        "dataDrivenDisabled": true,
                        "order": 10
                    },
                    "extraColumns": {
                        "title": "Extra Columns",
                        "description": "More columns of the row Write to Column writes, each with a fixed or bound value, such as the id of the record the switch belongs to. While one of them has no value (its binding has delivered none yet), the switch is disabled, so it never writes a row without its key.",
                        "type": "array",
                        "dataDrivenDisabled": true,
                        "order": 11,
                        "items": {
                            "type": "object",
                            "properties": {
                                "targetColumn": {
                                    "title": "Column",
                                    "description": "The column this value goes into, normally in the same table as Write to Column.",
                                    "type": "targetColumn",
                                    "dataDrivenDisabled": true,
                                    "order": 1
                                },
                                "value": {
                                    "title": "Value",
                                    "description": "What every click writes into Column: a constant, or bound to a column, such as the id of the record shown on this page. Converted to the column's type (number, true/false).",
                                    "type": "string",
                                    "order": 2
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
