本帖最后由 adxr 于 2021-10-21 10:48 编辑
家里一直用的是爱快路由器,老婆又要求对家里的电脑,电视网络做控制,这样只好在爱快开了MAC访问控制
但自己晚上也要常用到电脑及看电视,经常要打开路由器页面来启用和停用MAC访问控制是很不方便的。这个老婆也不会操作,那只好自己做一下爱快与HASS的对接了
先上效果:可以实现控制MAC访问控制的启用和停用、实时上下行情况、可查指定MAC设备是否在线等等
对接的架构:
用PHP与爱快WEB对接,PHP返回信息给Node-RED进行处理,用MQTT对接HASS
——————PHP———————PHP———————————PHP—————————————PHP————————————PHP—————————
PHP源代码:
login.php 为登录
第7行请改为自己的爱快路由器地址及端口
第15行"e01b957f0b45a4bac991101f63a57e70"为浏览器开发工具抓的加密后的爱快密码
acl_mac.php 为MAC访问控制
第7行请改为自己的爱快路由器地址及端口
call_show.php 为查询接口
第5行请改为自己的爱快路由器地址及端口
——————Node-RED———————Node-RED———————————Node-RED—————————————Node-RED————————————Node-RED—————————
Node-RED连接图:
Node-RED中所有URL:http://10.10.0.4/API/ikuai/ 中改为你的PHP地址
请求终端信息中URL:http://10.10.0.4/API/ikuai/call_show.php?param={ "func_name": "monitor_lanip", "action": "show", "param": { "TYPE": "data,total", "ORDER_BY": "ip_addr_int", "orderType": "IP", "limit": "0,20", "ORDER": "", "FINDS": "ip_addr,mac,comment,username", "KEYWORDS": "18:bc:5a:a3:76:04" } }
其中http://10.10.0.4/API/ikuai/call_show.php改为你的PHP地址,18:bc:5a:a3:76:04改为你要查的终端MAC
其中,查终端是否在线,返回total:1时是在线,返回total:0时是不在线,后面怎么用,大家发挥吧。
Node-RED 代码:
——————HASS———————HASS———————————HASS—————————————HASS————————————HASS—————————
下面是HASS中的MQTT代码:
sensor:
- platform: mqtt
name: "IKuai CPU"
state_topic: "ikuai/int"
value_template: "{{ value_json.cpu}}"
json_attributes_topic: "ikuai/int"
unit_of_measurement: "%"
icon: mdi:cpu-64-bit
- platform: mqtt
name: "IKuai RAM"
state_topic: "ikuai/int"
value_template: "{{ value_json.memory}}"
json_attributes_topic: "ikuai/int"
unit_of_measurement: "%"
icon: mdi:memory
- platform: mqtt
name: "IKuai CPU温度"
state_topic: "ikuai/int"
value_template: "{{ value_json.cputemp}}"
json_attributes_topic: "ikuai/int"
unit_of_measurement: "℃"
icon: mdi:thermometer
- platform: mqtt
name: "IKuai 在线用户"
state_topic: "ikuai/int"
value_template: "{{ value_json.online_user}}"
json_attributes_topic: "ikuai/int"
unit_of_measurement: "line"
icon: mdi:account-multiple
- platform: mqtt
name: "IKuai 连接数"
state_topic: "ikuai/int"
value_template: "{{ value_json.connect_num}}"
json_attributes_topic: "ikuai/int"
unit_of_measurement: "p/s"
icon: mdi:human-greeting-proximity
- platform: mqtt
name: "IKuai 上行速率"
state_topic: "ikuai/int"
value_template: "{{ ( value_json.upload | float / 100000 ) | round(3)}}"
json_attributes_topic: "ikuai/int"
unit_of_measurement: "Mbps"
icon: mdi:wifi-arrow-up
- platform: mqtt
name: "IKuai 下行速率"
state_topic: "ikuai/int"
value_template: "{{ ( value_json.total_down | float / 100000 ) | round(3)}}"
json_attributes_topic: "ikuai/int"
unit_of_measurement: "Mbps"
icon: mdi:wifi-arrow-down
switch:
- platform: mqtt
name: "房电脑限网"
state_topic: "stat/FPC/mac"
command_topic: "cmnd/FPC/mac"
qos: 1
icon: mdi:lan-disconnect
- platform: mqtt
name: "小厅电脑限网"
state_topic: "stat/XTPC/mac"
command_topic: "cmnd/XTPC/mac"
qos: 1
icon: mdi:lan-disconnect
- platform: mqtt
name: "小米电视限网"
state_topic: "stat/Mtv/mac"
command_topic: "cmnd/Mtv/mac"
qos: 1
icon: mdi:lan-disconnect
|