Skip to content

Conditional output

cflurin edited this page Jul 27, 2018 · 9 revisions

This example shows the use of the general purpose method onTransition

dsm10c

Configuration

{
    "currentState": "onestate",
    "states": {
        "onestate": {
            "indoor": "onestate",
            "outdoor": "onestate"
        }
    },
    "data": {
        "indoor":  20,
        "outdoor": 20
    },
    "methods": {
        "indoor": "sm.data.indoor=msg.payload",
        "outdoor": "sm.data.outdoor=msg.payload",
        "onTransition" : [
            "if (sm.data.indoor > sm.data.outdoor) {",
                "msg.payload = 'indoor > outdoor';",
            "} else if (sm.data.indoor < sm.data.outdoor) {",
                "msg.payload = 'indoor < outdoor';",
            "} else {",
                "msg.payload = 'indoor = outdoor';",
            "}"
        ]
    }
}

Flow

[{"id":"e0e2d204.f6dd6","type":"dsm","z":"57ef434a.058a6c","name":"If","sm_config":"{\n    \"currentState\": \"onestate\",\n    \"states\": {\n        \"onestate\": {\n            \"indoor\": \"onestate\",\n            \"outdoor\": \"onestate\"\n        }\n    },\n    \"data\": {\n        \"indoor\":  20,\n        \"outdoor\": 20\n    },\n    \"methods\": {\n        \"indoor\": \"sm.data.indoor=msg.payload\",\n        \"outdoor\": \"sm.data.outdoor=msg.payload\",\n        \"onTransition\" : [\n            \"if (sm.data.indoor > sm.data.outdoor) {\",\n                \"msg.payload = 'indoor > outdoor';\",\n            \"} else if (sm.data.indoor < sm.data.outdoor) {\",\n                \"msg.payload = 'indoor < outdoor';\",\n            \"} else {\",\n                \"msg.payload = 'indoor = outdoor';\",\n            \"}\"\n        ],\n        \"onTransition1\" :\"if (sm.data.indoor > sm.data.outdoor) {msg.payload = 'indoor > outdoor';} else if (sm.data.indoor < sm.data.outdoor) {msg.payload = 'indoor < outdoor';} else {msg.payload = 'indoor = outdoor';}\"\n    }\n}\n","x":290,"y":4560,"wires":[["4bf01ac5.4635d4"]]},{"id":"28e4441c.5361bc","type":"inject","z":"57ef434a.058a6c","name":"","topic":"indoor","payload":"22","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":4480,"wires":[["e0e2d204.f6dd6"]]},{"id":"f52cdd49.5763c","type":"inject","z":"57ef434a.058a6c","name":"","topic":"outdoor","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":4620,"wires":[["e0e2d204.f6dd6"]]},{"id":"f258d56f.351048","type":"inject","z":"57ef434a.058a6c","name":"","topic":"outdoor","payload":"25","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":4580,"wires":[["e0e2d204.f6dd6"]]},{"id":"3db4ab7f.522f84","type":"inject","z":"57ef434a.058a6c","name":"","topic":"indoor","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":4520,"wires":[["e0e2d204.f6dd6"]]},{"id":"4bf01ac5.4635d4","type":"debug","z":"57ef434a.058a6c","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","x":470,"y":4560,"wires":[]}]
Clone this wiki locally