|
本帖最后由 zxlch 于 2021-11-14 22:17 编辑
家里的小米电视坏了,之前写的一个控制方式本来要删除的,可是想想之前也是自己辛辛苦苦做出来的,就发上来给大家共享一下。
之前写过一个索尼全系列家用设备TCP控制的:索尼家电TCP控制(使用NODERED实现),控制码及控制流程 - 『HomeAssistant』综合讨论区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz! (hassbian.com)
废话不多说,直接上代码:
Nodered上的代码
[
{
"id": "ff3b62cf.74686",
"type": "inject",
"z": "85c4a17a.2912d",
"name": "",
"props": [
{
"p": "payload",
"v": "enter",
"vt": "str"
},
{
"p": "topic",
"v": "",
"vt": "string"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "enter",
"payloadType": "str",
"x": 230,
"y": 120,
"wires": [
[
"3f0e44a6.179bcc"
]
]
},
{
"id": "3f0e44a6.179bcc",
"type": "function",
"z": "85c4a17a.2912d",
"name": "format",
"func": "var a = new Buffer([71,69,84,32,47,99,111,110,116,114,111,108,108,101,114,63,97,99,116,105,111,110,61,107,101,121,101,118,101,110,116,38,107,101,121,99,111,100,101,61]);\n\nvar c = new Buffer([32,72,84,84,80,47,49,46,49,13,10,104,111,115,116,58,32,49,57,50,46,49,54,56,46,50,49,54,46,51,48,58,54,48,57,53,13,10,67,111,110,110,101,99,116,105,111,110,58,32,99,108,111,115,101,13,10,13,10]);\n\nvar b = msg.payload;\n\nmsg.payload = a + b + c;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 470,
"y": 80,
"wires": [
[
"2a6bd5d5.92bb7a"
]
]
},
{
"id": "2a6bd5d5.92bb7a",
"type": "tcp request",
"z": "85c4a17a.2912d",
"server": "192.168.88.99",
"port": "6095",
"out": "time",
"splitc": "0",
"name": "TCP(MITV4)",
"x": 670,
"y": 80,
"wires": [
[]
]
},
{
"id": "c80755ba.fd9588",
"type": "mqtt in",
"z": "85c4a17a.2912d",
"name": "",
"topic": "control/mitv4/send",
"qos": "2",
"datatype": "auto",
"broker": "b095aef8.978e9",
"x": 190,
"y": 80,
"wires": [
[
"3f0e44a6.179bcc"
]
]
},
{
"id": "b095aef8.978e9",
"type": "mqtt-broker",
"name": "",
"broker": "127.0.0.1",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": false,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
}
]
需要更改的两个位置:
"server": "192.168.88.99",
"port": "6095",
应该来说,port是不需要更改的,只更改server的IP地址即可。
接下来是HA的代码:
XiaoMi TV4:
cards:
- cards:
- color: rgb(113, 113, 198)
color_type: card
icon: mdi:power
name: 电源
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: power
topic: control/mitv4/send
type: custom:button-card
- default: 'off'
entity: binary_sensor.mi_tv4
states:
'off':
color: rgb(255, 0, 0)
color_type: label-card
name: XiaoMi TV4
styles:
card:
- height: 80px
type: custom:button-card
'on':
color: rgb(255, 255, 255)
color_type: label-card
name: XiaoMi TV4
styles:
card:
- height: 80px
type: custom:button-card
type: custom:state-switch
- color: rgb(255, 255, 255)
color_type: card
icon: mdi:home
name: 主页
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: home
topic: control/mitv4/send
type: custom:button-card
type: horizontal-stack
- cards:
- styles:
card:
- filter: opacity(0%)
type: custom:button-card
- color: rgb(119, 136, 153)
color_type: card
icon: mdi:arrow-up-bold
name: 上
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: up
topic: control/mitv4/send
type: custom:button-card
- styles:
card:
- filter: opacity(0%)
type: custom:button-card
type: horizontal-stack
- cards:
- color: rgb(119, 136, 153)
color_type: card
icon: mdi:arrow-left-bold
name: 左
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: left
topic: control/mitv4/send
type: custom:button-card
- color: rgb(119, 136, 153)
color_type: card
icon: mdi:power-off
name: 确认
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: enter
topic: control/mitv4/send
type: custom:button-card
- color: rgb(119, 136, 153)
color_type: card
icon: mdi:arrow-right-bold
name: 右
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: right
topic: control/mitv4/send
type: custom:button-card
type: horizontal-stack
- cards:
- color: rgb(255, 255, 255)
color_type: card
icon: mdi:keyboard-backspace
name: 返回
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: back
topic: control/mitv4/send
type: custom:button-card
- color: rgb(119, 136, 153)
color_type: card
icon: mdi:arrow-down-bold
name: 下
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: down
topic: control/mitv4/send
type: custom:button-card
- color: rgb(255, 255, 255)
color_type: card
icon: mdi:menu
name: 菜单
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: menu
topic: control/mitv4/send
type: custom:button-card
type: horizontal-stack
- cards:
- color: rgb(255, 255, 255)
color_type: card
icon: mdi:volume-minus
name: 音量减
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: volumedown
topic: control/mitv4/send
type: custom:button-card
- color: rgb(255, 255, 255)
color_type: card
icon: mdi:volume-plus
name: 音量增
styles:
card:
- height: 80px
tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: volumeup
topic: control/mitv4/send
type: custom:button-card
type: horizontal-stack
type: vertical-stack
注意,HA的代码不能直接用,要修改一下,我太懒了,希望有人改好了发上来我复制过来。
具体样式如下:
如果设备在线,电源旁边的设备名称会变成白色的底,不在线就是红色的低。
|
评分
-
参与人数 1 | 金钱 +20 |
HASS币 +10 |
收起
理由
|
囧
| + 20 |
+ 10 |
感谢楼主分享! |
查看全部评分
|