Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Magic cube NODE-RED config
[
{
"id": "77b5dd61.4f3574",
"type": "tab",
"label": "Magic Cube Controller",
"disabled": false,
"info": ""
},
{
"id": "50a6a391.4b1f9c",
"type": "mqtt in",
"z": "77b5dd61.4f3574",
"name": "Magic Cube Side",
"topic": "zigbee2mqtt/0x00158d00027850bc",
"qos": "0",
"broker": "41ca50e5.b8978",
"x": 340,
"y": 200,
"wires": [
[
"dea1bc07.5e97d"
]
]
},
{
"id": "7ad9bd68.4f2754",
"type": "switch",
"z": "77b5dd61.4f3574",
"name": "Action",
"property": "payload.action",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "slide",
"vt": "str"
},
{
"t": "eq",
"v": "tap",
"vt": "str"
},
{
"t": "eq",
"v": "flip180",
"vt": "str"
},
{
"t": "eq",
"v": "flip90",
"vt": "str"
},
{
"t": "eq",
"v": "shake",
"vt": "str"
},
{
"t": "eq",
"v": "rotate_left",
"vt": "str"
},
{
"t": "eq",
"v": "rotate_right",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 7,
"x": 640,
"y": 200,
"wires": [
[
"786cd7dc.d4d748"
],
[
"786cd7dc.d4d748"
],
[
"786cd7dc.d4d748"
],
[
"b8ca8804.582878"
],
[
"bc8c9164.40db"
],
[
"7f0b1db7.f69cd4"
],
[
"7f0b1db7.f69cd4"
]
]
},
{
"id": "786cd7dc.d4d748",
"type": "change",
"z": "77b5dd61.4f3574",
"name": "Cube side",
"rules": [
{
"t": "set",
"p": "cube_side",
"pt": "flow",
"to": "payload.side",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 800,
"y": 120,
"wires": [
[]
]
},
{
"id": "b8ca8804.582878",
"type": "change",
"z": "77b5dd61.4f3574",
"name": "Cube side",
"rules": [
{
"t": "set",
"p": "cube_side",
"pt": "flow",
"to": "payload.to_side",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 800,
"y": 160,
"wires": [
[]
]
},
{
"id": "bc8c9164.40db",
"type": "change",
"z": "77b5dd61.4f3574",
"name": "Cube side",
"rules": [
{
"t": "set",
"p": "cube_side",
"pt": "flow",
"to": "-1",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 800,
"y": 200,
"wires": [
[]
]
},
{
"id": "701e7b94.3dff34",
"type": "switch",
"z": "77b5dd61.4f3574",
"name": "Rotate action",
"property": "cube_side",
"propertyType": "flow",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "num"
},
{
"t": "eq",
"v": "1",
"vt": "str"
},
{
"t": "eq",
"v": "2",
"vt": "str"
},
{
"t": "eq",
"v": "3",
"vt": "str"
},
{
"t": "eq",
"v": "4",
"vt": "str"
},
{
"t": "eq",
"v": "5",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 6,
"x": 990,
"y": 240,
"wires": [
[
"e0b7f28a.22a56"
],
[
"e0b7f28a.22a56"
],
[
"e0b7f28a.22a56"
],
[
"e0b7f28a.22a56"
],
[
"e0b7f28a.22a56"
],
[
"e0b7f28a.22a56"
]
]
},
{
"id": "dea1bc07.5e97d",
"type": "json",
"z": "77b5dd61.4f3574",
"name": "",
"property": "payload",
"action": "obj",
"pretty": false,
"x": 510,
"y": 200,
"wires": [
[
"7ad9bd68.4f2754"
]
]
},
{
"id": "e0b7f28a.22a56",
"type": "api-current-state",
"z": "77b5dd61.4f3574",
"name": "Ceiling yeelight",
"server": "45aa0aee.37a7e4",
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"override_payload": false,
"override_data": true,
"entity_id": "light.ceiling_yeelight",
"state_type": "str",
"outputs": 1,
"x": 1260,
"y": 160,
"wires": [
[
"af239f79.fcdce"
]
]
},
{
"id": "7f0b1db7.f69cd4",
"type": "change",
"z": "77b5dd61.4f3574",
"name": "Cube rotate",
"rules": [
{
"t": "set",
"p": "cube_direction",
"pt": "msg",
"to": "msg.payload.action",
"tot": "jsonata"
},
{
"t": "set",
"p": "cube_angle",
"pt": "msg",
"to": "msg.payload.angle",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 810,
"y": 240,
"wires": [
[
"701e7b94.3dff34"
]
]
},
{
"id": "af239f79.fcdce",
"type": "function",
"z": "77b5dd61.4f3574",
"name": "New brightness",
"func": "if(msg.data.state == \"on\"){\n brightness = msg.data.attributes.brightness;\n if(msg.cube_direction == \"rotate_right\"){\n new_brightness = brightness + 50;\n } else{\n new_brightness = brightness - 50;\n }\n}else {\n if(msg.cube_direction == \"rotate_right\"){\n new_brightness = 1;\n } else{\n new_brightness = 0;\n }\n}\nif(new_brightness > 0){\n msg.light_action = \"on\";\n msg.light_brightness = new_brightness;\n} else {\n msg.light_action = \"off\";\n}\n\ndelete msg[\"payload\"];\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1460,
"y": 160,
"wires": [
[
"4bec80e4.77d7a"
]
]
},
{
"id": "4bec80e4.77d7a",
"type": "switch",
"z": "77b5dd61.4f3574",
"name": "On/Off",
"property": "light_action",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "on",
"vt": "str"
},
{
"t": "eq",
"v": "off",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 1630,
"y": 160,
"wires": [
[
"6affe9bd.dd2938"
],
[
"cae7ec7b.f59a7"
]
]
},
{
"id": "b877915d.3752b",
"type": "api-call-service",
"z": "77b5dd61.4f3574",
"name": "On + brightness",
"server": "45aa0aee.37a7e4",
"service_domain": "light",
"service": "turn_on",
"data": "{\"entity_id\":\"light.ceiling_yeelight\"}",
"render_data": false,
"mergecontext": "",
"output_location": "payload",
"output_location_type": "msg",
"x": 2000,
"y": 120,
"wires": [
[]
]
},
{
"id": "cae7ec7b.f59a7",
"type": "api-call-service",
"z": "77b5dd61.4f3574",
"name": "Off",
"server": "45aa0aee.37a7e4",
"service_domain": "light",
"service": "turn_off",
"data": "{\"entity_id\":\"light.ceiling_yeelight\"}",
"render_data": false,
"mergecontext": "",
"output_location": "payload",
"output_location_type": "msg",
"x": 2030,
"y": 180,
"wires": [
[]
]
},
{
"id": "6affe9bd.dd2938",
"type": "function",
"z": "77b5dd61.4f3574",
"name": "Construct data",
"func": "msg.payload = {};\nmsg.payload.data = {\"brightness\": msg.light_brightness}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1800,
"y": 120,
"wires": [
[
"b877915d.3752b"
]
]
},
{
"id": "41ca50e5.b8978",
"type": "mqtt-broker",
"z": "",
"name": "Hassio Mosquitto",
"broker": "localhost",
"port": "1883",
"clientid": "hassio-node-red",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "45aa0aee.37a7e4",
"type": "server",
"z": "",
"name": "Home Assistant",
"legacy": false,
"hassio": true,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment