『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 4312|回复: 3

[教程系列] [抛砖引玉]利用魔方打造客厅万能遥控器

[复制链接]

15

主题

331

帖子

2390

积分

金牌会员

Rank: 6Rank: 6

积分
2390
金钱
2059
HASS币
10
发表于 2019-5-2 17:28:26 | 显示全部楼层 |阅读模式
根据论坛各位大大的nodered教程,照葫芦画瓢做了一个魔方的遥控流程,利用双击切换模式,利用左转右转实现调光调色调温等功能,刚开始学习,完全照葫芦画瓢,觉得mode获取流转的节点可以优化,希望大大们指教。

另目前只是利用{   "entity_id": "light.living_room",   "brightness": "200" }这个命令指定数值调光,请教nodered如何实现类似滑动条的调光调色调温,平滑调光。


捕获3.PNG

[
    {
        "id": "4b348da2.77a314",
        "type": "tab",
        "label": "流程4",
        "disabled": false,
        "info": ""
    },
    {
        "id": "2247ab14.5fb634",
        "type": "server-events",
        "z": "4b348da2.77a314",
        "name": "获取所有事件",
        "server": "909c521e.52735",
        "x": 153.3333282470703,
        "y": 398.33331298828125,
        "wires": [
            [
                "769c172c.1e3a58"
            ]
        ]
    },
    {
        "id": "769c172c.1e3a58",
        "type": "switch",
        "z": "4b348da2.77a314",
        "name": "获取客厅无线开关事件",
        "property": "payload.entity_id",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "binary_sensor.switch_158d0001223ea8",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "binary_sensor.switch_158d0001b9425f",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "binary_sensor.cube_158d000278ead4",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 367.3333282470703,
        "y": 397.33331298828125,
        "wires": [
            [],
            [],
            [
                "2462e000.cddc2"
            ]
        ]
    },
    {
        "id": "2462e000.cddc2",
        "type": "switch",
        "z": "4b348da2.77a314",
        "name": "魔方",
        "property": "payload.event.action_type",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "flip90",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "flip180",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "shake_air",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "rotate",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "tap_twice",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "move",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 6,
        "x": 596.3332958221436,
        "y": 419.6666564941406,
        "wires": [
            [],
            [],
            [],
            [
                "ebef2114.4035b"
            ],
            [
                "50f9e36.1f7751c"
            ],
            []
        ]
    },
    {
        "id": "f9d5f8c9.7519d8",
        "type": "api-call-service",
        "z": "4b348da2.77a314",
        "name": "提高亮度",
        "server": "909c521e.52735",
        "service_domain": "light",
        "service": "turn_on",
        "data": "{   "entity_id": "light.living_room",   "brightness": "200" }",
        "mergecontext": "",
        "x": 1198.3333282470703,
        "y": 262.33331298828125,
        "wires": [
            []
        ]
    },
    {
        "id": "e6482a78.187f18",
        "type": "api-call-service",
        "z": "4b348da2.77a314",
        "name": "降低亮度",
        "server": "909c521e.52735",
        "service_domain": "light",
        "service": "turn_on",
        "data": "{   "entity_id": "light.living_room",   "brightness": "30" }",
        "mergecontext": "",
        "x": 1195.3333282470703,
        "y": 300.33331298828125,
        "wires": [
            []
        ]
    },
    {
        "id": "50f9e36.1f7751c",
        "type": "function",
        "z": "4b348da2.77a314",
        "name": "获取mode变量状态",
        "func": "if(flow.get('mode')==='brightness'){\n    return [msg,null];\n}\nelse{\n    return [null,msg];}\n",
        "outputs": 2,
        "noerr": 0,
        "x": 822.3333282470703,
        "y": 561.3333129882812,
        "wires": [
            [
                "937f2ee0.de56d",
                "f23ed97.ed4bb28"
            ],
            [
                "3a7b7a6a.d2b286"
            ]
        ]
    },
    {
        "id": "937f2ee0.de56d",
        "type": "function",
        "z": "4b348da2.77a314",
        "name": "设置mode变量状态为color_temp",
        "func": "flow.set('mode','color_temp');\nreturn null;",
        "outputs": 1,
        "noerr": 0,
        "x": 1132.3333282470703,
        "y": 536.3333129882812,
        "wires": [
            []
        ]
    },
    {
        "id": "9c02c415.487ce8",
        "type": "function",
        "z": "4b348da2.77a314",
        "name": "获取mode变量状态为temperature",
        "func": "flow.set('mode','temperature');\nreturn null;",
        "outputs": 1,
        "noerr": 0,
        "x": 1440.3333282470703,
        "y": 612.3333129882812,
        "wires": [
            []
        ]
    },
    {
        "id": "3a7b7a6a.d2b286",
        "type": "function",
        "z": "4b348da2.77a314",
        "name": "获取mode变量状态",
        "func": "if(flow.get('mode')==='color_temp'){\n    return [msg,null];\n}\nelse{\n    return [null,msg];}\n",
        "outputs": 2,
        "noerr": 0,
        "x": 1131.3333282470703,
        "y": 634.3333129882812,
        "wires": [
            [
                "9c02c415.487ce8",
                "7e5a6eba.20a27"
            ],
            [
                "5b8279fc.9ba6e8",
                "f03ef696.ddcd58"
            ]
        ]
    },
    {
        "id": "5b8279fc.9ba6e8",
        "type": "function",
        "z": "4b348da2.77a314",
        "name": "获取mode变量状态为temperature",
        "func": "flow.set('mode','brightness');\nreturn null;",
        "outputs": 1,
        "noerr": 0,
        "x": 1444.3333282470703,
        "y": 760.3333129882812,
        "wires": [
            []
        ]
    },
    {
        "id": "ebef2114.4035b",
        "type": "function",
        "z": "4b348da2.77a314",
        "name": "获取mode变量状态",
        "func": "if(flow.get('mode')==='brightness'){\n    return [msg,null];\n}\nelse{\n    return [null,msg];}\n",
        "outputs": 2,
        "noerr": 0,
        "x": 794.3332824707031,
        "y": 383.66663360595703,
        "wires": [
            [
                "d2f489e3.695278"
            ],
            [
                "c8859af2.08ae88"
            ]
        ]
    },
    {
        "id": "c8859af2.08ae88",
        "type": "function",
        "z": "4b348da2.77a314",
        "name": "获取mode变量状态",
        "func": "if(flow.get('mode')==='color_temp'){\n    return [msg,null];\n}\nelse{\n    return [null,msg];}\n",
        "outputs": 2,
        "noerr": 0,
        "x": 827.3333053588867,
        "y": 453.6666450500488,
        "wires": [
            [
                "377854a6.b9ac0c"
            ],
            [
                "811a5eb0.ad23b"
            ]
        ]
    },
    {
        "id": "d2f489e3.695278",
        "type": "switch",
        "z": "4b348da2.77a314",
        "name": "获取魔方事件",
        "property": "payload.event.action_value",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": " 0",
                "vt": "str"
            },
            {
                "t": "lt",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1005.9999771118164,
        "y": 355.66665744781494,
        "wires": [
            [
                "f9d5f8c9.7519d8"
            ],
            [
                "e6482a78.187f18"
            ]
        ]
    },
    {
        "id": "9924f107.12b94",
        "type": "api-call-service",
        "z": "4b348da2.77a314",
        "name": "调暖",
        "server": "909c521e.52735",
        "service_domain": "light",
        "service": "turn_on",
        "data": "{   "entity_id": "light.living_room",   "color_temp": "370" }",
        "mergecontext": "",
        "x": 1182.3333282470703,
        "y": 380.33331298828125,
        "wires": [
            []
        ]
    },
    {
        "id": "fca4056e.ec0c78",
        "type": "api-call-service",
        "z": "4b348da2.77a314",
        "name": "调冷",
        "server": "909c521e.52735",
        "service_domain": "light",
        "service": "turn_on",
        "data": "{   "entity_id": "light.living_room",   "color_temp": "153" }",
        "mergecontext": "",
        "x": 1180.3333282470703,
        "y": 423.33331298828125,
        "wires": [
            []
        ]
    },
    {
        "id": "377854a6.b9ac0c",
        "type": "switch",
        "z": "4b348da2.77a314",
        "name": "获取魔方事件",
        "property": "payload.event.action_value",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": " 0",
                "vt": "str"
            },
            {
                "t": "lt",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1021.3333282470703,
        "y": 429.33331298828125,
        "wires": [
            [
                "9924f107.12b94"
            ],
            [
                "fca4056e.ec0c78"
            ]
        ]
    },
    {
        "id": "b5af3efd.30666",
        "type": "api-call-service",
        "z": "4b348da2.77a314",
        "name": "提高温度",
        "server": "909c521e.52735",
        "service_domain": "climate",
        "service": "set_temperature",
        "data": "{   "entity_id": "climate.air_conditioner",   "temperature": "26" }",
        "mergecontext": "",
        "x": 1269.3333282470703,
        "y": 463.33331298828125,
        "wires": [
            []
        ]
    },
    {
        "id": "6ca213dd.7dcf6c",
        "type": "api-call-service",
        "z": "4b348da2.77a314",
        "name": "降低温度",
        "server": "909c521e.52735",
        "service_domain": "climate",
        "service": "set_temperature",
        "data": "{   "entity_id": "climate.air_conditioner",   "temperature": "20" }",
        "mergecontext": "",
        "x": 1263.3333282470703,
        "y": 500.33331298828125,
        "wires": [
            []
        ]
    },
    {
        "id": "811a5eb0.ad23b",
        "type": "switch",
        "z": "4b348da2.77a314",
        "name": "获取魔方事件",
        "property": "payload.event.action_value",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": " 0",
                "vt": "str"
            },
            {
                "t": "lt",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1032.3333282470703,
        "y": 479.33331298828125,
        "wires": [
            [
                "b5af3efd.30666"
            ],
            [
                "6ca213dd.7dcf6c"
            ]
        ]
    },
    {
        "id": "3a43f3b0.bd4c7c",
        "type": "api-call-service",
        "z": "4b348da2.77a314",
        "name": "若琪播报",
        "server": "909c521e.52735",
        "service_domain": "rokid_tts",
        "service": "speak",
        "data": "",
        "mergecontext": "",
        "x": 1525.3333282470703,
        "y": 832.3333129882812,
        "wires": [
            []
        ]
    },
    {
        "id": "f03ef696.ddcd58",
        "type": "function",
        "z": "4b348da2.77a314",
        "name": "TTS内容",
        "func": "var message = `切换至调光`;\nmsg.payload = {};\nmsg.payload.data = {"message":message};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 1357.9998321533203,
        "y": 848.8334350585938,
        "wires": [
            [
                "c41efe1d.031d4",
                "3a43f3b0.bd4c7c"
            ]
        ]
    },
    {
        "id": "c41efe1d.031d4",
        "type": "debug",
        "z": "4b348da2.77a314",
        "name": "调式信息",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 1526.9998321533203,
        "y": 873.8334350585938,
        "wires": []
    },
    {
        "id": "e68bffa5.714e1",
        "type": "api-call-service",
        "z": "4b348da2.77a314",
        "name": "若琪播报",
        "server": "909c521e.52735",
        "service_domain": "rokid_tts",
        "service": "speak",
        "data": "",
        "mergecontext": "",
        "x": 1656.3334007263184,
        "y": 644.3333377838135,
        "wires": [
            []
        ]
    },
    {
        "id": "7e5a6eba.20a27",
        "type": "function",
        "z": "4b348da2.77a314",
        "name": "TTS内容",
        "func": "var message = `切换至调温`;\nmsg.payload = {};\nmsg.payload.data = {"message":message};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 1358.9998321533203,
        "y": 651.8334350585938,
        "wires": [
            [
                "e0bd92e.a5fca7",
                "e68bffa5.714e1"
            ]
        ]
    },
    {
        "id": "e0bd92e.a5fca7",
        "type": "debug",
        "z": "4b348da2.77a314",
        "name": "调式信息",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 1652.333236694336,
        "y": 684.8334407806396,
        "wires": []
    },
    {
        "id": "ca566174.45873",
        "type": "api-call-service",
        "z": "4b348da2.77a314",
        "name": "若琪播报",
        "server": "909c521e.52735",
        "service_domain": "rokid_tts",
        "service": "speak",
        "data": "",
        "mergecontext": "",
        "x": 1362.3333282470703,
        "y": 538.3333129882812,
        "wires": [
            []
        ]
    },
    {
        "id": "f23ed97.ed4bb28",
        "type": "function",
        "z": "4b348da2.77a314",
        "name": "TTS内容",
        "func": "var message = `切换至调色`;\nmsg.payload = {};\nmsg.payload.data = {"message":message};\nreturn msg;\n\n",
        "outputs": 1,
        "noerr": 0,
        "x": 1109.9998321533203,
        "y": 583.8334350585938,
        "wires": [
            [
                "c45f1c02.91859",
                "ca566174.45873"
            ]
        ]
    },
    {
        "id": "c45f1c02.91859",
        "type": "debug",
        "z": "4b348da2.77a314",
        "name": "调式信息",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 1317.9998321533203,
        "y": 578.8334350585938,
        "wires": []
    },
    {
        "id": "909c521e.52735",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "url": "http://192.1.1.111:8123",
        "pass": "123456"
    }
]

评分

参与人数 1金钱 +20 收起 理由
+ 20 感谢楼主分享!

查看全部评分

回复

使用道具 举报

7

主题

363

帖子

1308

积分

金牌会员

Rank: 6Rank: 6

积分
1308
金钱
945
HASS币
0
发表于 2019-5-3 11:29:49 | 显示全部楼层
魔方我觉得真的不好用啊  可能是我记忆不好  经常忘了
回复

使用道具 举报

3

主题

220

帖子

2072

积分

金牌会员

Rank: 6Rank: 6

积分
2072
金钱
1852
HASS币
0
发表于 2019-5-18 00:59:23 | 显示全部楼层
楼主,魔方旋转不能触发以上各个操作,只有双敲魔方TTS可以触发,咋破?
回复

使用道具 举报

11

主题

258

帖子

961

积分

高级会员

Rank: 4

积分
961
金钱
703
HASS币
0
发表于 2019-6-14 07:01:02 | 显示全部楼层
本帖最后由 hisoo 于 2019-6-14 07:02 编辑

赞赞,我想用这个来手动开空调 同时反馈空调的状态
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-13 02:20 , Processed in 0.095497 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表