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

 找回密码
 立即注册
查看: 4296|回复: 20

[技术探讨] TUYA旋钮控制亮度

[复制链接]

11

主题

134

帖子

1148

积分

金牌会员

Rank: 6Rank: 6

积分
1148
金钱
1014
HASS币
0
发表于 2022-12-11 18:02:29 | 显示全部楼层 |阅读模式
IMG_20221211_173713.jpg 屏幕截图 2022-12-11 174039.png 屏幕截图 2022-12-11 174201.png 现在设置后用起来很蠢,无论我旋转多少角度他增加亮度或者减少亮度的值是固定的。怎样能让亮度和旋转角度结合一下呢。或者有没有其他这样的旋钮能做到这种效果
回复

使用道具 举报

27

主题

2143

帖子

8930

积分

论坛元老

Rank: 8Rank: 8

积分
8930
金钱
6782
HASS币
30

论坛元老

发表于 2022-12-11 20:16:30 | 显示全部楼层
貌似这种成品它内部锁死了0~100或者0~255的亮度值,它最大值和最小值是固定的,比较无解。

你试试这种思路,读取旋钮每次输出的亮度值,跟前一个值做对比,如果是大于前一个值或者等于255或者100这种峰值,就作为增加亮度的触发条件,反之亦然,
回复

使用道具 举报

11

主题

134

帖子

1148

积分

金牌会员

Rank: 6Rank: 6

积分
1148
金钱
1014
HASS币
0
 楼主| 发表于 2022-12-11 20:43:50 | 显示全部楼层
本帖最后由 moz111 于 2022-12-11 20:45 编辑
情非殇 发表于 2022-12-11 20:16
貌似这种成品它内部锁死了0~100或者0~255的亮度值,它最大值和最小值是固定的,比较无解。

你试试这种思路 ...

并没有输出亮度。输出的只是左右旋转。是通过自动化右转增加亮度。旋转后松手才触发。是有这样的半成品么?推荐下
回复

使用道具 举报

27

主题

2143

帖子

8930

积分

论坛元老

Rank: 8Rank: 8

积分
8930
金钱
6782
HASS币
30

论坛元老

发表于 2022-12-12 08:21:59 | 显示全部楼层
moz111 发表于 2022-12-11 20:43
并没有输出亮度。输出的只是左右旋转。是通过自动化右转增加亮度。旋转后松手才触发。是有这样的半成品么 ...

旋转后松手才触发,不太对吧,旋转一点和旋转一圈难道是一样的输出么,那还叫什么旋钮,不就是按键开关么
回复

使用道具 举报

10

主题

1332

帖子

4252

积分

论坛元老

Rank: 8Rank: 8

积分
4252
金钱
2920
HASS币
0
发表于 2022-12-12 08:55:11 | 显示全部楼层
用node-red转换一下就好了。
回复

使用道具 举报

11

主题

134

帖子

1148

积分

金牌会员

Rank: 6Rank: 6

积分
1148
金钱
1014
HASS币
0
 楼主| 发表于 2022-12-13 15:47:04 | 显示全部楼层
情非殇 发表于 2022-12-12 08:21
旋转后松手才触发,不太对吧,旋转一点和旋转一圈难道是一样的输出么,那还叫什么旋钮,不就是按键开关么 ...

的确是松手后才能触发。明天涂鸦网关到看。 看看用涂鸦控制是什么样把
回复

使用道具 举报

11

主题

134

帖子

1148

积分

金牌会员

Rank: 6Rank: 6

积分
1148
金钱
1014
HASS币
0
 楼主| 发表于 2022-12-13 15:48:08 | 显示全部楼层
隔壁的王叔叔 发表于 2022-12-12 08:55
用node-red转换一下就好了。

怎样用node-red呢。有没有能参考的帖子。node-red不太会用
回复

使用道具 举报

10

主题

1332

帖子

4252

积分

论坛元老

Rank: 8Rank: 8

积分
4252
金钱
2920
HASS币
0
发表于 2022-12-13 22:45:06 | 显示全部楼层
这是我写的
[
    {
        "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": ""
    }
]
回复

使用道具 举报

0

主题

21

帖子

157

积分

注册会员

Rank: 2

积分
157
金钱
136
HASS币
0
发表于 2022-12-16 13:08:32 | 显示全部楼层
能大概说下怎么接入的吗,我一直接入不了
回复

使用道具 举报

11

主题

134

帖子

1148

积分

金牌会员

Rank: 6Rank: 6

积分
1148
金钱
1014
HASS币
0
 楼主| 发表于 2022-12-19 22:50:57 | 显示全部楼层

一直没来得及操作。 大佬我这个导入后怎么不对呢。 不是导入节点么
屏幕截图 2022-12-19 224952.png
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-24 14:36 , Processed in 0.283688 second(s), 35 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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