|
本帖最后由 zro22 于 2019-9-2 15:53 编辑
雷士,至拓,东联,WiFi灯或者通过一个wifi小网关可以控制的灯
我买的那个app长这样
小网关长这样
app和网关怎么用我就不说了,重点说一下怎么控制
相关的帖子
https://bbs.hassbian.com/forum.p ... =%E9%9B%B7%E5%A3%AB
https://bbs.hassbian.com/forum.p ... =%E9%9B%B7%E5%A3%AB
有些灯自带了wifi,可以直接用app控制,有些没有wifi,经过小网关后可以实现app控制。
我采用的是小网关。
首先查到小网关的IP,然后在局域网用抓包工具,看看小网关是否在不停的发包
用tcpdump的话命令是
tcpdump host 192.168.10.218 -A
可以看到这样的广播包
15:15:36.981877 IP ESP_xxxx.xxxx > 255.255.255.255.findhostd: UDP, length 561
E..M=...../x..
.....m.'..9..{"uuid":"6602-xxx-xxx-2","fw":1928,"mode":5,
"light":{
"l0":{"cw":255,"ww":50,"rgb":0},"l1":{"cw":0,"ww":0,"rgb":0},"l2":{"cw":255,"ww":50,"rgb":0},"l3":{"cw":0,"ww":0,"rgb":0},
"l4":{"cw":0,"ww":0,"rgb":0},"l5":{"cw":0,"ww":0,"rgb":0},"l6":{"cw":0,"ww":0,"rgb":0},"l7":{"cw":0,"ww":0,"rgb":0},
"l8":{"cw":0,"ww":0,"rgb":0},"l9":{"cw":0,"ww":0,"rgb":0},"l10":{"cw":0,"ww":0,"rgb":0},"l11":{"cw":0,"ww":0,"rgb":0},
"l12":{"cw":0,"ww":0,"rgb":0},"l13":{"cw":0,"ww":0,"rgb":0},"l14":{"cw":0,"ww":0,"rgb":0},"l15":{"cw":0,"ww":0,"rgb":0}
}
}
记住uuid后面的数字。
然后在电脑上使用mqtt.fx 登陆如下服务器
[size=14.3999996185303px]雷士云的mqtt
地址:[size=14.3999996185303px]www.xlinyun.com
[size=14.3999996185303px]账号:DL_APP
[size=14.3999996185303px]密码:dl_123456
订阅如下topic
[size=14.3999996185303px]6602-xxx-xxx-2/out
[size=14.3999996185303px]6602-xxx-xxx-2/userin
[size=14.3999996185303px]上面的uuid换成自己的。然后在灯的app上控制一下,看看mqtt订阅能否收到消息,能收到消息的话继续往下走,收不到的话之前的步骤再检查下。
[size=14.3999996185303px]
[size=14.3999996185303px]下面说一下接入HA的具体方式。
1,控制方式采用http post给小网关下命令
2,状态采用读取雷士云mqtt服务器来更新
首先在ha的confiure文件增加如下命令,ip更换为自己的网关IP
# gtop_led 代表第几个灯,gtop_command 4设定亮度,gtop_command 1开灯,0关灯
rest_command:
gtop_request:
url: http://192.168.10.218/config?command=light
method: POST
payload: '{"mode":15,"time":0,"rgb":{"red":{{ gtop_led }},"green":{{ gtop_command }},"blue":0,"cwhite":{{ gtop_liangdu }},"wwhite":{{ gtop_sewen }}},"response":1}'
content_type: 'text/plain; charset=utf-8'
添加完之后 重启HA
然后再服务里面测试一下能控制灯不
选择 rest_command.gtop_request 服务,数据
{
"gtop_led": "0",
"gtop_command": "4",
"gtop_liangdu":"255",
"gtop_sewen": "50"
}
然后 发送,看看灯亮了没有,对应小网关的第一个灯
接下来配置状态反馈,首先配置自己的mqtt服务器的mosquitto.conf 搜索到 [size=14.3999996185303px]connection[size=14.3999996185303px]
按照如下配置 ,topic那里修改成自己的uuid
connection zhita
address www.xlinyun.com:1883
topic 6602-xxx-xxx-2/out both 0 "" ""
remote_username DL_APP
remote_password dl_123456
然后重启自己的mqtt服务器,然后用mqtt.fx订阅上面这个topic,用手机app控制灯看一下能否收到消息,收不到的话上面没配置对,需要重新检查。
至此,周边的配置都全了,在ha里面控制和接收我用的mqtt
在configure文件里面
首先增加两个input_number
input_number:
brightness0:
name: 亮度0
initial: 0
min: 0
max: 255
step: 1
color0:
name: 色温0
initial: 50
min: 0
max: 100
step: 1
然后在light下添加一个mqtt实体,注意uuid那里修改成自己的
- platform: mqtt
name: "gtop_led0"
state_topic: "6602-xxx-xxx-2/out"
value_template: >
{% if (value_json.light.l0.cw == 0) %}
{{ 0 }}
{% else %}
{{ 1 }}
{% endif %}
command_topic: "/gtop/led0/switch"
brightness_command_topic: "/gtop/led0/brightness"
brightness_state_topic: "6602-xxx-xxx-2/out"
brightness_value_template: "{{ value_json.light.l0.cw }}"
white_value_command_topic: "/gtop/led0/color"
white_value_state_topic: "6602-xxx-xxx-2/out"
white_value_template: "{{ value_json.light.l0.ww }}"
white_value_scale: 100
payload_on: 1
payload_off: 0
然后在自动化配置里面加如下的自动化,因为我不太会写mqtt触发自动化的时候怎么取得另外一个topic的数据,所以用input_number转换了一次。
如果谁知道mqtt怎么直接触发自动化后读取数据,会更简单一点。
- alias: input number send REQUTEST command 0
initial_state: true
hide_entity: false
trigger:
- platform: state
entity_id: input_number.brightness0
- platform: state
entity_id: input_number.color0
action:
service: rest_command.gtop_request
data_template:
gtop_led: 0
#'{{ states.sensor.mqtt_test.state | int }}'
gtop_command: 4
gtop_liangdu: '{{ states.input_number.brightness0.state | int }}'
gtop_sewen: '{{ states.input_number.color0.state | int }}'
- alias: mqtt set input number brightness 0
initial_state: true
hide_entity: false
trigger:
- platform: mqtt
topic: '/gtop/led0/brightness'
action:
service: input_number.set_value
data_template:
entity_id: input_number.brightness0
value: "{{ trigger.payload }}"
- alias: mqtt set input number color 0
initial_state: true
hide_entity: false
trigger:
- platform: mqtt
topic: '/gtop/led0/color'
action:
service: input_number.set_value
data_template:
entity_id: input_number.color0
value: "{{ trigger.payload }}"
- alias: mqtt switch send on off REQUTEST command 0
initial_state: true
hide_entity: false
trigger:
- platform: mqtt
topic: '/gtop/led0/switch'
action:
service: rest_command.gtop_request
data_template:
gtop_led: 0
gtop_command: "{{ trigger.payload }}"
至此全部完成了,HA里面的控制APP可以看到,app里面的控制 HA可以看到。
|
评分
-
参与人数 1 | 金钱 +20 |
HASS币 +20 |
收起
理由
|
囧
| + 20 |
+ 20 |
厉害了word楼主! |
查看全部评分
|