[
{
"id": "70b4edf253c5b70e",
"type": "tab",
"label": "涂鸦旋钮控制灯光亮度",
"disabled": false,
"info": "",
"env": []
},
{
"id": "feba44aaf9ad7705",
"type": "mqtt in",
"z": "70b4edf253c5b70e",
"name": "",
"topic": "zigbee2mqtt/涂鸦旋钮",
"qos": "2",
"datatype": "auto-detect",
"broker": "284c9f1b3fe33e7c",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 120,
"y": 100,
"wires": [
[
"b852174b07d4ddf2",
"55808425cbdfdd20"
]
]
},
{
"id": "09a8034cc29da6d7",
"type": "comment",
"z": "70b4edf253c5b70e",
"name": "获取旋钮状态",
"info": "",
"x": 90,
"y": 40,
"wires": []
},
{
"id": "098945fe574bbc4c",
"type": "mqtt in",
"z": "70b4edf253c5b70e",
"name": "",
"topic": "homeassistant/light/test_light/state",
"qos": "2",
"datatype": "auto-detect",
"broker": "284c9f1b3fe33e7c",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 160,
"y": 160,
"wires": [
[
"d27a2915b48d9863",
"0b020d43c4fc35ee"
]
]
},
{
"id": "0b020d43c4fc35ee",
"type": "function",
"z": "70b4edf253c5b70e",
"name": "function 1",
"func": "global.set('t', t = { payload: msg.payload.brightness} );\nmsg.payload = t;\nreturn t;",
"outputs": 1,
"noerr": 2,
"initialize": "",
"finalize": "",
"libs": [],
"x": 500,
"y": 160,
"wires": [
[]
]
},
{
"id": "55808425cbdfdd20",
"type": "function",
"z": "70b4edf253c5b70e",
"name": "获取旋钮",
"func": "var msg1 = { payload: global.get('t', msg1) };//获得灯原始的状态\nvar action = { payload: msg.payload.action };//获得旋钮功能\nvar step = { payload: msg.payload.action_step_size };//获得旋钮旋转步距\nvar state = ""\nvar brightness=0\nif (action.payload === "brightness_step_up"){\n // brightness=\n brightness=msg1.payload.payload+step.payload;\n state="ON"\n if (brightness >= 255){\n brightness=255\n }\n}\nelse if (action.payload === "brightness_step_down"){\n brightness = msg1.payload.payload - step.payload;\n if (brightness <= 0) {\n brightness = 0\n state = "OFF"\n }\n}\nelse{\n return null\n}\nmsg = { "payload": { "state":state , "brightness": brightness }}\n// msg={"payload":brightness}\nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 500,
"y": 80,
"wires": [
[
"3078977d7708161e",
"31afc27b8f0f1f3f"
]
]
},
{
"id": "3078977d7708161e",
"type": "debug",
"z": "70b4edf253c5b70e",
"name": "debug 5",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 720,
"y": 40,
"wires": []
},
{
"id": "b852174b07d4ddf2",
"type": "debug",
"z": "70b4edf253c5b70e",
"name": "debug 9",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 500,
"y": 40,
"wires": []
},
{
"id": "31afc27b8f0f1f3f",
"type": "mqtt out",
"z": "70b4edf253c5b70e",
"name": "",
"topic": "homeassistant/light/test_light/state",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "284c9f1b3fe33e7c",
"x": 800,
"y": 80,
"wires": []
},
{
"id": "d27a2915b48d9863",
"type": "debug",
"z": "70b4edf253c5b70e",
"name": "debug 10",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 500,
"y": 200,
"wires": []
},
{
"id": "258781eb87cf0e7e",
"type": "mqtt out",
"z": "70b4edf253c5b70e",
"name": "",
"topic": "homeassistant/light/test_light/config",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "284c9f1b3fe33e7c",
"x": 460,
"y": 240,
"wires": []
},
{
"id": "ac28aada87595c35",
"type": "inject",
"z": "70b4edf253c5b70e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{"~":"homeassistant/light/test_light","name":"test_light","unique_id":"test_light","cmd_t":"~/set","stat_t":"~/state","schema":"json","brightness":true}",
"payloadType": "json",
"x": 90,
"y": 260,
"wires": [
[
"258781eb87cf0e7e"
]
]
},
{
"id": "284c9f1b3fe33e7c",
"type": "mqtt-broker",
"name": "老王的MQTT服务器",
"broker": "10.12.1.185",
"port": "1883",
"clientid": "node-red",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]