HVAC temperature control - Amazon IoT Events
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

HVAC temperature control

Background story

This example implements a temperature control model (a thermostat) with these features:

  • One detector model you define that can monitor and control multiple areas. (A detector instance will be created for each area.)

  • Each detector instance receives temperature data from multiple sensors placed in each control area.

  • You can change the desired temperature (the set point) for each area at any time.

  • You can define the operational parameters for each area and change these parameters at any time.

  • You can add sensors to or delete sensors from an area at any time.

  • You can enable a minimum run for time heating and cooling units to protect them from damage.

  • The detectors will reject, and report, anomalous sensor readings.

  • You can define emergency temperature set points. If any one sensor reports a temperature above or below the set points you have defined, heating or cooling units will be engaged immediately, and the detector will report that temperature spike.

This example demonstrates the following functional capabilities:

  • Create event detector models.

  • Create inputs.

  • Ingest inputs into a detector model.

  • Evaluate trigger conditions.

  • Refer to state variables in conditions and set the values of variables depending on conditions.

  • Refer to timers in conditions and set timers depending on conditions.

  • Take actions that send Amazon SNS and MQTT messages.

Input definitions

A "seedTemperatureInput" is used to create a detector instance for an area and define its operational parameters.

CLI command used:

aws iotevents create-input --cli-input-json file://seedInput.json

File: seedInput.json

{ "inputName": "seedTemperatureInput", "inputDescription": "Temperature seed values.", "inputDefinition": { "attributes": [ { "jsonPath": "areaId" }, { "jsonPath": "desiredTemperature" }, { "jsonPath": "allowedError" }, { "jsonPath": "rangeHigh" }, { "jsonPath": "rangeLow" }, { "jsonPath": "anomalousHigh" }, { "jsonPath": "anomalousLow" }, { "jsonPath": "sensorCount" }, { "jsonPath": "noDelay" } ] } }

Response:

{ "inputConfiguration": { "status": "ACTIVE", "inputArn": "arn:aws:iotevents:us-west-2:123456789012:input/seedTemperatureInput", "lastUpdateTime": 1557519620.736, "creationTime": 1557519620.736, "inputName": "seedTemperatureInput", "inputDescription": "Temperature seed values." } }

A "temperatureInput" should be sent by each sensor in each area, as necessary.

CLI command used:

aws iotevents create-input --cli-input-json file://temperatureInput.json

File: temperatureInput.json

{ "inputName": "temperatureInput", "inputDescription": "Temperature sensor unit data.", "inputDefinition": { "attributes": [ { "jsonPath": "sensorId" }, { "jsonPath": "areaId" }, { "jsonPath": "sensorData.temperature" } ] } }

Response:

{ "inputConfiguration": { "status": "ACTIVE", "inputArn": "arn:aws:iotevents:us-west-2:123456789012:input/temperatureInput", "lastUpdateTime": 1557519707.399, "creationTime": 1557519707.399, "inputName": "temperatureInput", "inputDescription": "Temperature sensor unit data." } }

Detector model definition

The "areaDetectorModel" defines how each detector instance works. Each "state machine" instance will ingest temperature sensor readings, then change state and send control messages depending on these readings.

CLI command used:

aws iotevents create-detector-model --cli-input-json file://areaDetectorModel.json

File: areaDetectorModel.json

{ "detectorModelName": "areaDetectorModel", "detectorModelDefinition": { "states": [ { "stateName": "start", "onEnter": { "events": [ { "eventName": "prepare", "condition": "true", "actions": [ { "setVariable": { "variableName": "sensorId", "value": "0" } }, { "setVariable": { "variableName": "reportedTemperature", "value": "0.1" } }, { "setVariable": { "variableName": "resetMe", "value": "false" } } ] } ] }, "onInput": { "transitionEvents": [ { "eventName": "initialize", "condition": "$input.seedTemperatureInput.sensorCount > 0", "actions": [ { "setVariable": { "variableName": "rangeHigh", "value": "$input.seedTemperatureInput.rangeHigh" } }, { "setVariable": { "variableName": "rangeLow", "value": "$input.seedTemperatureInput.rangeLow" } }, { "setVariable": { "variableName": "desiredTemperature", "value": "$input.seedTemperatureInput.desiredTemperature" } }, { "setVariable": { "variableName": "averageTemperature", "value": "$input.seedTemperatureInput.desiredTemperature" } }, { "setVariable": { "variableName": "allowedError", "value": "$input.seedTemperatureInput.allowedError" } }, { "setVariable": { "variableName": "anomalousHigh", "value": "$input.seedTemperatureInput.anomalousHigh" } }, { "setVariable": { "variableName": "anomalousLow", "value": "$input.seedTemperatureInput.anomalousLow" } }, { "setVariable": { "variableName": "sensorCount", "value": "$input.seedTemperatureInput.sensorCount" } }, { "setVariable": { "variableName": "noDelay", "value": "$input.seedTemperatureInput.noDelay == true" } } ], "nextState": "idle" }, { "eventName": "reset", "condition": "($variable.resetMe == true) && ($input.temperatureInput.sensorData.temperature < $variable.anomalousHigh && $input.temperatureInput.sensorData.temperature > $variable.anomalousLow)", "actions": [ { "setVariable": { "variableName": "averageTemperature", "value": "((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount)" } } ], "nextState": "idle" } ] }, "onExit": { "events": [ { "eventName": "resetHeatCool", "condition": "true", "actions": [ { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOff" } }, { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOff" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Heating/Off" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Cooling/Off" } } ] } ] } }, { "stateName": "idle", "onInput": { "events": [ { "eventName": "whatWasInput", "condition": "true", "actions": [ { "setVariable": { "variableName": "sensorId", "value": "$input.temperatureInput.sensorId" } }, { "setVariable": { "variableName": "reportedTemperature", "value": "$input.temperatureInput.sensorData.temperature" } } ] }, { "eventName": "changeDesired", "condition": "$input.seedTemperatureInput.desiredTemperature != $variable.desiredTemperature", "actions": [ { "setVariable": { "variableName": "desiredTemperature", "value": "$input.seedTemperatureInput.desiredTemperature" } } ] }, { "eventName": "calculateAverage", "condition": "$input.temperatureInput.sensorData.temperature < $variable.anomalousHigh && $input.temperatureInput.sensorData.temperature > $variable.anomalousLow", "actions": [ { "setVariable": { "variableName": "averageTemperature", "value": "((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount)" } } ] } ], "transitionEvents": [ { "eventName": "anomalousInputArrived", "condition": "$input.temperatureInput.sensorData.temperature >= $variable.anomalousHigh || $input.temperatureInput.sensorData.temperature <= $variable.anomalousLow", "actions": [ { "iotTopicPublish": { "mqttTopic": "temperatureSensor/anomaly" } } ], "nextState": "idle" }, { "eventName": "highTemperatureSpike", "condition": "$input.temperatureInput.sensorData.temperature > $variable.rangeHigh", "actions": [ { "iotTopicPublish": { "mqttTopic": "temperatureSensor/spike" } }, { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOn" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Cooling/On" } }, { "setVariable": { "variableName": "enteringNewState", "value": "true" } } ], "nextState": "cooling" }, { "eventName": "lowTemperatureSpike", "condition": "$input.temperatureInput.sensorData.temperature < $variable.rangeLow", "actions": [ { "iotTopicPublish": { "mqttTopic": "temperatureSensor/spike" } }, { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOn" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Heating/On" } }, { "setVariable": { "variableName": "enteringNewState", "value": "true" } } ], "nextState": "heating" }, { "eventName": "highTemperatureThreshold", "condition": "(((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount) > ($variable.desiredTemperature + $variable.allowedError))", "actions": [ { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOn" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Cooling/On" } }, { "setVariable": { "variableName": "enteringNewState", "value": "true" } } ], "nextState": "cooling" }, { "eventName": "lowTemperatureThreshold", "condition": "(((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount) < ($variable.desiredTemperature - $variable.allowedError))", "actions": [ { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOn" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Heating/On" } }, { "setVariable": { "variableName": "enteringNewState", "value": "true" } } ], "nextState": "heating" } ] } }, { "stateName": "cooling", "onEnter": { "events": [ { "eventName": "delay", "condition": "!$variable.noDelay && $variable.enteringNewState", "actions": [ { "setTimer": { "timerName": "coolingTimer", "seconds": 180 } }, { "setVariable": { "variableName": "goodToGo", "value": "false" } } ] }, { "eventName": "dontDelay", "condition": "$variable.noDelay == true", "actions": [ { "setVariable": { "variableName": "goodToGo", "value": "true" } } ] }, { "eventName": "beenHere", "condition": "true", "actions": [ { "setVariable": { "variableName": "enteringNewState", "value": "false" } } ] } ] }, "onInput": { "events": [ { "eventName": "whatWasInput", "condition": "true", "actions": [ { "setVariable": { "variableName": "sensorId", "value": "$input.temperatureInput.sensorId" } }, { "setVariable": { "variableName": "reportedTemperature", "value": "$input.temperatureInput.sensorData.temperature" } } ] }, { "eventName": "changeDesired", "condition": "$input.seedTemperatureInput.desiredTemperature != $variable.desiredTemperature", "actions": [ { "setVariable": { "variableName": "desiredTemperature", "value": "$input.seedTemperatureInput.desiredTemperature" } } ] }, { "eventName": "calculateAverage", "condition": "$input.temperatureInput.sensorData.temperature < $variable.anomalousHigh && $input.temperatureInput.sensorData.temperature > $variable.anomalousLow", "actions": [ { "setVariable": { "variableName": "averageTemperature", "value": "((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount)" } } ] }, { "eventName": "areWeThereYet", "condition": "(timeout(\"coolingTimer\"))", "actions": [ { "setVariable": { "variableName": "goodToGo", "value": "true" } } ] } ], "transitionEvents": [ { "eventName": "anomalousInputArrived", "condition": "$input.temperatureInput.sensorData.temperature >= $variable.anomalousHigh || $input.temperatureInput.sensorData.temperature <= $variable.anomalousLow", "actions": [ { "iotTopicPublish": { "mqttTopic": "temperatureSensor/anomaly" } } ], "nextState": "cooling" }, { "eventName": "highTemperatureSpike", "condition": "$input.temperatureInput.sensorData.temperature > $variable.rangeHigh", "actions": [ { "iotTopicPublish": { "mqttTopic": "temperatureSensor/spike" } } ], "nextState": "cooling" }, { "eventName": "lowTemperatureSpike", "condition": "$input.temperatureInput.sensorData.temperature < $variable.rangeLow", "actions": [ { "iotTopicPublish": { "mqttTopic": "temperatureSensor/spike" } }, { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOff" } }, { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOn" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Cooling/Off" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Heating/On" } }, { "setVariable": { "variableName": "enteringNewState", "value": "true" } } ], "nextState": "heating" }, { "eventName": "desiredTemperature", "condition": "(((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount) <= ($variable.desiredTemperature - $variable.allowedError)) && $variable.goodToGo == true", "actions": [ { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOff" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Cooling/Off" } } ], "nextState": "idle" } ] } }, { "stateName": "heating", "onEnter": { "events": [ { "eventName": "delay", "condition": "!$variable.noDelay && $variable.enteringNewState", "actions": [ { "setTimer": { "timerName": "heatingTimer", "seconds": 120 } }, { "setVariable": { "variableName": "goodToGo", "value": "false" } } ] }, { "eventName": "dontDelay", "condition": "$variable.noDelay == true", "actions": [ { "setVariable": { "variableName": "goodToGo", "value": "true" } } ] }, { "eventName": "beenHere", "condition": "true", "actions": [ { "setVariable": { "variableName": "enteringNewState", "value": "false" } } ] } ] }, "onInput": { "events": [ { "eventName": "whatWasInput", "condition": "true", "actions": [ { "setVariable": { "variableName": "sensorId", "value": "$input.temperatureInput.sensorId" } }, { "setVariable": { "variableName": "reportedTemperature", "value": "$input.temperatureInput.sensorData.temperature" } } ] }, { "eventName": "changeDesired", "condition": "$input.seedTemperatureInput.desiredTemperature != $variable.desiredTemperature", "actions": [ { "setVariable": { "variableName": "desiredTemperature", "value": "$input.seedTemperatureInput.desiredTemperature" } } ] }, { "eventName": "calculateAverage", "condition": "$input.temperatureInput.sensorData.temperature < $variable.anomalousHigh && $input.temperatureInput.sensorData.temperature > $variable.anomalousLow", "actions": [ { "setVariable": { "variableName": "averageTemperature", "value": "((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount)" } } ] }, { "eventName": "areWeThereYet", "condition": "(timeout(\"heatingTimer\"))", "actions": [ { "setVariable": { "variableName": "goodToGo", "value": "true" } } ] } ], "transitionEvents": [ { "eventName": "anomalousInputArrived", "condition": "$input.temperatureInput.sensorData.temperature >= $variable.anomalousHigh || $input.temperatureInput.sensorData.temperature <= $variable.anomalousLow", "actions": [ { "iotTopicPublish": { "mqttTopic": "temperatureSensor/anomaly" } } ], "nextState": "heating" }, { "eventName": "highTemperatureSpike", "condition": "$input.temperatureInput.sensorData.temperature > $variable.rangeHigh", "actions": [ { "iotTopicPublish": { "mqttTopic": "temperatureSensor/spike" } }, { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOff" } }, { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOn" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Heating/Off" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Cooling/On" } }, { "setVariable": { "variableName": "enteringNewState", "value": "true" } } ], "nextState": "cooling" }, { "eventName": "lowTemperatureSpike", "condition": "$input.temperatureInput.sensorData.temperature < $variable.rangeLow", "actions": [ { "iotTopicPublish": { "mqttTopic": "temperatureSensor/spike" } } ], "nextState": "heating" }, { "eventName": "desiredTemperature", "condition": "(((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount) >= ($variable.desiredTemperature + $variable.allowedError)) && $variable.goodToGo == true", "actions": [ { "sns": { "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOff" } }, { "iotTopicPublish": { "mqttTopic": "hvac/Heating/Off" } } ], "nextState": "idle" } ] } } ], "initialStateName": "start" }, "key": "areaId", "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole" }

Response:

{ "detectorModelConfiguration": { "status": "ACTIVATING", "lastUpdateTime": 1557523491.168, "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole", "creationTime": 1557523491.168, "detectorModelArn": "arn:aws:iotevents:us-west-2:123456789012:detectorModel/areaDetectorModel", "key": "areaId", "detectorModelName": "areaDetectorModel", "detectorModelVersion": "1" } }

BatchPutMessage examples

In this example, "BatchPutMessage" is used to create a detector instance for an area and define the initial operating parameters.

CLI command used:

aws iotevents-data batch-put-message --cli-input-json file://seedExample.json --cli-binary-format raw-in-base64-out

File: seedExample.json

{ "messages": [ { "messageId": "00001", "inputName": "seedTemperatureInput", "payload": "{\"areaId\": \"Area51\", \"desiredTemperature\": 20.0, \"allowedError\": 0.7, \"rangeHigh\": 30.0, \"rangeLow\": 15.0, \"anomalousHigh\": 60.0, \"anomalousLow\": 0.0, \"sensorCount\": 10, \"noDelay\": false}" } ] }

Response:

{ "BatchPutMessageErrorEntries": [] }

In this example, "BatchPutMessage" is used to report temperature sensor readings for a single sensor in an area.

CLI command used:

aws iotevents-data batch-put-message --cli-input-json file://temperatureExample.json --cli-binary-format raw-in-base64-out

File: temperatureExample.json

{ "messages": [ { "messageId": "00005", "inputName": "temperatureInput", "payload": "{\"sensorId\": \"05\", \"areaId\": \"Area51\", \"sensorData\": {\"temperature\": 23.12} }" } ] }

Response:

{ "BatchPutMessageErrorEntries": [] }

In this example, "BatchPutMessage" is used to change the desired temperature for an area.

CLI command used:

aws iotevents-data batch-put-message --cli-input-json file://seedSetDesiredTemp.json --cli-binary-format raw-in-base64-out

File: seedSetDesiredTemp.json

{ "messages": [ { "messageId": "00001", "inputName": "seedTemperatureInput", "payload": "{\"areaId\": \"Area51\", \"desiredTemperature\": 23.0}" } ] }

Response:

{ "BatchPutMessageErrorEntries": [] }

Examples of Amazon SNS messages generated by the Area51 detector instance:

Heating system off command> { "eventTime":1557520274729, "payload":{ "actionExecutionId":"f3159081-bac3-38a4-96f7-74af0940d0a4", "detector":{ "detectorModelName":"areaDetectorModel", "keyValue":"Area51", "detectorModelVersion":"1" }, "eventTriggerDetails":{ "inputName":"seedTemperatureInput", "messageId":"00001", "triggerType":"Message" }, "state":{ "stateName":"start", "variables":{ "sensorCount":10, "rangeHigh":30.0, "resetMe":false, "enteringNewState":true, "averageTemperature":20.0, "rangeLow":15.0, "noDelay":false, "allowedError":0.7, "desiredTemperature":20.0, "anomalousHigh":60.0, "reportedTemperature":0.1, "anomalousLow":0.0, "sensorId":0 }, "timers":{} } }, "eventName":"resetHeatCool" }
Cooling system off command> { "eventTime":1557520274729, "payload":{ "actionExecutionId":"98f6a1b5-8f40-3cdb-9256-93afd4d66192", "detector":{ "detectorModelName":"areaDetectorModel", "keyValue":"Area51", "detectorModelVersion":"1" }, "eventTriggerDetails":{ "inputName":"seedTemperatureInput", "messageId":"00001", "triggerType":"Message" }, "state":{ "stateName":"start", "variables":{ "sensorCount":10, "rangeHigh":30.0, "resetMe":false, "enteringNewState":true, "averageTemperature":20.0, "rangeLow":15.0, "noDelay":false, "allowedError":0.7, "desiredTemperature":20.0, "anomalousHigh":60.0, "reportedTemperature":0.1, "anomalousLow":0.0, "sensorId":0 }, "timers":{} } }, "eventName":"resetHeatCool" }

In this example, we use the "DescribeDetector" API to get information about the current state of a detector instance.

aws iotevents-data describe-detector --detector-model-name areaDetectorModel --key-value Area51

Response:

{ "detector": { "lastUpdateTime": 1557521572.216, "creationTime": 1557520274.405, "state": { "variables": [ { "name": "resetMe", "value": "false" }, { "name": "rangeLow", "value": "15.0" }, { "name": "noDelay", "value": "false" }, { "name": "desiredTemperature", "value": "20.0" }, { "name": "anomalousLow", "value": "0.0" }, { "name": "sensorId", "value": "\"01\"" }, { "name": "sensorCount", "value": "10" }, { "name": "rangeHigh", "value": "30.0" }, { "name": "enteringNewState", "value": "false" }, { "name": "averageTemperature", "value": "19.572" }, { "name": "allowedError", "value": "0.7" }, { "name": "anomalousHigh", "value": "60.0" }, { "name": "reportedTemperature", "value": "15.72" }, { "name": "goodToGo", "value": "false" } ], "stateName": "idle", "timers": [ { "timestamp": 1557520454.0, "name": "idleTimer" } ] }, "keyValue": "Area51", "detectorModelName": "areaDetectorModel", "detectorModelVersion": "1" } }

BatchUpdateDetector example

In this example, "BatchUpdateDetector" is used to change operational parameters for a working detector instance.

CLI command used:

aws iotevents-data batch-update-detector --cli-input-json file://areaDM.BUD.json

File: areaDM.BUD.json

{ "detectors": [ { "messageId": "0001", "detectorModelName": "areaDetectorModel", "keyValue": "Area51", "state": { "stateName": "start", "variables": [ { "name": "desiredTemperature", "value": "22" }, { "name": "averageTemperature", "value": "22" }, { "name": "allowedError", "value": "1.0" }, { "name": "rangeHigh", "value": "30.0" }, { "name": "rangeLow", "value": "15.0" }, { "name": "anomalousHigh", "value": "60.0" }, { "name": "anomalousLow", "value": "0.0" }, { "name": "sensorCount", "value": "12" }, { "name": "noDelay", "value": "true" }, { "name": "goodToGo", "value": "true" }, { "name": "sensorId", "value": "0" }, { "name": "reportedTemperature", "value": "0.1" }, { "name": "resetMe", "value": "true" } ], "timers": [ ] } } ] }

Response:

{ An error occurred (InvalidRequestException) when calling the BatchUpdateDetector operation: Number of variables in the detector exceeds the limit 10 }

Amazon IoT Core rules engine examples

The following rules republish Amazon IoT Events MQTT messages as shadow update request messages. We assume that Amazon IoT Core things are defined for a heating unit and a cooling unit for each area that is controlled by the detector model.

In this example, we have defined things named "Area51HeatingUnit" and "Area51CoolingUnit".

CLI command used:

aws iot create-topic-rule --cli-input-json file://ADMShadowCoolOffRule.json

File: ADMShadowCoolOffRule.json

{ "ruleName": "ADMShadowCoolOff", "topicRulePayload": { "sql": "SELECT topic(3) as state.desired.command FROM 'hvac/Cooling/Off'", "description": "areaDetectorModel mqtt topic publish to cooling unit shadow request", "ruleDisabled": false, "awsIotSqlVersion": "2016-03-23", "actions": [ { "republish": { "topic": "$$aws/things/${payload.detector.keyValue}CoolingUnit/shadow/update", "roleArn": "arn:aws:iam::123456789012:role/service-role/ADMShadowRole" } } ] } }

Response: [empty]

CLI command used:

aws iot create-topic-rule --cli-input-json file://ADMShadowCoolOnRule.json

File: ADMShadowCoolOnRule.json

{ "ruleName": "ADMShadowCoolOn", "topicRulePayload": { "sql": "SELECT topic(3) as state.desired.command FROM 'hvac/Cooling/On'", "description": "areaDetectorModel mqtt topic publish to cooling unit shadow request", "ruleDisabled": false, "awsIotSqlVersion": "2016-03-23", "actions": [ { "republish": { "topic": "$$aws/things/${payload.detector.keyValue}CoolingUnit/shadow/update", "roleArn": "arn:aws:iam::123456789012:role/service-role/ADMShadowRole" } } ] } }

Response: [empty]

CLI command used:

aws iot create-topic-rule --cli-input-json file://ADMShadowHeatOffRule.json

File: ADMShadowHeatOffRule.json

{ "ruleName": "ADMShadowHeatOff", "topicRulePayload": { "sql": "SELECT topic(3) as state.desired.command FROM 'hvac/Heating/Off'", "description": "areaDetectorModel mqtt topic publish to heating unit shadow request", "ruleDisabled": false, "awsIotSqlVersion": "2016-03-23", "actions": [ { "republish": { "topic": "$$aws/things/${payload.detector.keyValue}HeatingUnit/shadow/update", "roleArn": "arn:aws:iam::123456789012:role/service-role/ADMShadowRole" } } ] } }

Response: [empty]

CLI command used:

aws iot create-topic-rule --cli-input-json file://ADMShadowHeatOnRule.json

File: ADMShadowHeatOnRule.json

{ "ruleName": "ADMShadowHeatOn", "topicRulePayload": { "sql": "SELECT topic(3) as state.desired.command FROM 'hvac/Heating/On'", "description": "areaDetectorModel mqtt topic publish to heating unit shadow request", "ruleDisabled": false, "awsIotSqlVersion": "2016-03-23", "actions": [ { "republish": { "topic": "$$aws/things/${payload.detector.keyValue}HeatingUnit/shadow/update", "roleArn": "arn:aws:iam::123456789012:role/service-role/ADMShadowRole" } } ] } }

Response: [empty]