Custom Protocol Templates ========================= Custom Protocol TX entries (Protocol -> Custom Protocol -> TX (For THEN)) support runtime template variables when HEX mode is unchecked. When an IFTTT rule triggers a TX entry, KCSv3 replaces each {{...}} placeholder with the latest live value used by the Web Monitor before transmitting the message or HTTP request. Template rendering runs in memory at send time. It does not change the saved NVS configuration and does not trigger extra hardware polling. Supported Routes and Fields --------------------------- - Applies to all non-HEX routes: TCP Client, UDP Client, RS485, RS232, HTTP GET, and HTTP POST. - Expanded fields: - Message is expanded for TCP Client, UDP Client, RS485, RS232, and HTTP POST (request body). - Url is expanded for HTTP GET and HTTP POST. - HEX mode (ishex = 1): Template expansion is disabled so binary frames and URLs are transmitted verbatim. - Multi-route triggers: When a single TX entry enables multiple routes, Message and Url are rendered once per trigger so all enabled routes receive the same snapshot. Placeholder Syntax ------------------ {{..}} - : Channel category (sensor, adc, input, output, or dac), lowercase. - : 1-based Monitor channel number (1, 2, 3, ...). Channel 0 and leading zeros such as 01 are invalid. - : Field name for that channel type, lowercase. - Optional ASCII spaces or tabs immediately inside the double braces are ignored (for example, {{ sensor.1.temperature }}). - An unclosed {{ with no matching }} is transmitted literally. Available Variables ------------------- 1. {{sensor..temperature}} - Channel Source: Monitor Sensor - Output Format: 1 decimal (25.4) - Notes: Uses the sensor's configured unit (°C or °F). Returns null for unconfigured sensors, read errors (-100), or Standard Modbus sensors. 2. {{sensor..humidity}} - Channel Source: Monitor Sensor - Output Format: 1 decimal (60.2) - Notes: Supported by humidity sensors (DHT11, DHT22, SHT31, KC-TS, KC-Modbus). Returns null for temperature-only, Standard Modbus, unconfigured, or unread sensors. 3. {{sensor..value}} - Channel Source: Monitor Sensor - Output Format: 2 decimals (12.34) - Notes: For Standard Modbus Sensor channels. Returns null for other sensor types, unconfigured channels, or read errors. 4. {{adc..raw}} - Channel Source: Monitor ADC - Output Format: Integer (2048) - Notes: Latest raw ADC reading. 5. {{adc..value}} - Channel Source: Monitor ADC - Output Format: Integer or 2 decimals (5.00) - Notes: Matches Web Monitor: returns raw integer when min = 0 and max = 0; otherwise returns the scaled custom value with 2 decimal places. 6. {{input..state}} - Channel Source: Monitor Input - Output Format: 0 or 1 - Notes: Latest digital input state (includes local, expanded, and remote inputs registered in Monitor). 7. {{output..state}} - Channel Source: Monitor Output - Output Format: 0 or 1 - Notes: Latest digital output / relay state. 8. {{dac..value}} - Channel Source: Monitor DAC - Output Format: Integer (0-255) - Notes: Latest live DAC output level. 9. {{dac..percent}} - Channel Source: Monitor DAC - Output Format: Integer (0-100) - Notes: Rounded percentage matching Web Monitor (round(value / 255 * 100)). Missing, Invalid, and Unknown Values ------------------------------------ Every matched {{...}} placeholder resolves to the literal token null when: - The channel does not exist on the device (for example, {{dac.1.value}} on a board without DAC channels or {{sensor.99.temperature}}). - A sensor channel is unconfigured, not yet ready, or reporting an invalid reading (<= -99.9, including -100). - The field does not apply to that sensor type (for example, {{sensor.1.humidity}} on a DS18B20, or {{sensor.1.temperature}} on a Standard Modbus sensor). - The placeholder syntax, type, channel number, or field name is invalid (for example, {{sensor.0.temperature}} or {{sensor.1.unknown}}). - The underlying floating-point value is non-finite (NaN or Inf). Emitting null keeps JSON payloads syntactically valid even when a sensor is temporarily disconnected. Size Limits and Error Handling ------------------------------ - Saved template limits: - Message: up to 255 bytes (256 bytes including NUL). - Url: up to 511 bytes (512 bytes including NUL). - Rendered output limits: - Rendered Message: up to 511 bytes (512 bytes including NUL). - Rendered Url: up to 1023 bytes (1024 bytes including NUL). - If expansion exceeds the rendered buffer limit, KCSv3 logs an error and aborts that transmission instead of sending truncated data. Examples -------- 1. HTTP POST JSON Telemetry Push temperature, humidity, ADC value, and relay state to a webhook server. - Route: HTTP POST - HEX: unchecked - Url: http://192.168.1.100:8080/api/telemetry - Message: {"temp":{{sensor.1.temperature}},"hum":{{sensor.1.humidity}},"adc":{{adc.1.value}},"relay1":{{output.1.state}}} - Sent request body (when Sensor 1 is 25.4 °C, 61.0 %, ADC 1 is scaled to 4.85, Output 1 is ON): {"temp":25.4,"hum":61.0,"adc":4.85,"relay1":1} - Sent request body (when Sensor 1 is disconnected): {"temp":null,"hum":null,"adc":4.85,"relay1":1} Note: HTTP POST sets Content-Type: application/json. 2. HTTP GET Query Parameters Send sensor and analog readings via query parameters without a request body. - Route: HTTP GET - HEX: unchecked - Message: (leave empty) - Url: http://192.168.1.100:8080/update?t={{sensor.1.temperature}}&h={{sensor.1.humidity}}&adc={{adc.1.raw}}&in1={{input.1.state}} - Requested URL: http://192.168.1.100:8080/update?t=25.4&h=61.0&adc=2048&in1=0 3. Standard Modbus Sensor and DAC Status Read a Standard Modbus Sensor on channel 1 together with DAC channel 1. - Route: HTTP POST - HEX: unchecked - Url: http://192.168.1.100:8080/api/status?ch=1&dac={{dac.1.percent}} - Message: {"modbus":{{sensor.1.value}},"dac_raw":{{dac.1.value}},"dac_pct":{{dac.1.percent}}} - Sent request: - URL: http://192.168.1.100:8080/api/status?ch=1&dac=50 - Body: {"modbus":12.34,"dac_raw":128,"dac_pct":50} 4. TCP / UDP / RS485 / RS232 Text Report Transmit a plain-text status line over TCP Client, UDP Client, RS485, or RS232. - Route: TCP Client (or UDP Client, RS485, RS232) - HEX: unchecked - Message: T={{sensor.1.temperature}},H={{sensor.1.humidity}},ADC={{adc.1.raw}},IN1={{input.1.state}},OUT1={{output.1.state}} - Sent payload: T=25.4,H=61.0,ADC=2048,IN1=1,OUT1=0 5. Periodic Reporting with IFTTT To push sensor values on a fixed schedule: 1. Create a Custom Protocol TX entry (for example, Protocol 1) using one of the HTTP or TCP templates above and click Save above settings. 2. Open IFTTT and create a new rule: - IF: select Interval and set the desired period in seconds (for example, 60). - THEN: select Custom Protocol and choose Protocol 1. 3. Enable and save the rule. Each interval tick renders the latest live Monitor values and sends the configured request.