真是煞费苦心!极米投影仪接入终极解决方案 | 您所在的位置:网站首页 › 极米投影仪xhome › 真是煞费苦心!极米投影仪接入终极解决方案 |
本帖最后由 hyperlau 于 2022-6-16 10:04 编辑 大家都知道极米投影仪遥控器是蓝牙的,本身有非官方api但只能关机没法开机,所以想完美的接入系统还是有一些困难多亏了论坛的几位大佬之前做出的诸多努力,才有了如下终极解决方案: 一.极米投影仪软硬件简述 系统:android 遥控器类型:蓝牙(意味着没办法用其他遥控设备控制) API:首先感谢以下几位大佬: https://bbs.hassbian.com/forum.php?mod=viewthread&tid=4998&highlight=%E6%9E%81%E7%B1%B3 https://bbs.hassbian.com/forum.php?mod=viewthread&tid=4998&page=2&authorid=17564感谢这位大佬的flow和lovelace https://bbs.hassbian.com/thread-7105-1-1.html 第三方集成:感谢这位兄台做了我想做但做不出来的东西! https://bbs.hassbian.com/thread-16308-1-1.html 上电自动开机:之前是没有的,前几个月官方系统更新推出了这个功能,让联动开机得以实现(借助智能插座)(如果你的上电开机功能异常,请在设置里关闭上电开机,完全退出设置后重新进入打开上电开机功能就可以正常使用了,应该是系统bug) 二、要实现的效果 1.能在hass和homekit里!!稳定的!!开机、关机 2.能正确的显示开关机状态(至少出门后能用手机看到投影仪是不是还开着)
三、思路
关机,如果简单的实现的话就直接给智能插座断电就好了,但我估计简单粗暴一定没有好结果(没测试过,哪位舍得自己的机器可以做个1000次上电断电的测试 **那正常的开关机流程就是关机后看机器是不是真的关了,如果真的关了就断电,开机的时候通电就好了**
那怎么才能判断投影仪是不是关机了?
可以ping投影仪。**关机后ping不通** 就可以断电了当然如果你的智能插座功率数据读取是实时的,用功率判断是最准确的,但奈何小米的智能插座功率数据延迟很大(几分钟),实在是没什么用户
正确的显示状态:按照上面的逻辑,可以做个sensor,ping不通就断电,状态置为关机,能ping通状态就置为开机,
但有个问题,上电开机后有40秒是ping不通的,而且投影用wifi网络,日常ping会跳,万一跳的高了被断电。。。
所以干脆简单一点,**不做日常状态的判断,只在开关机的时候设置状态**
四、实际效果
hass上按开机按钮后会给智能插座上电,这中间会有1分钟延时,1分钟内会忽略所有的操作(避免操作进入队列,主要是homekit的操作队列机制不明朗),彻底开机后(网络通了)开关状态会变为“开”
关机时会通过api进行关机操作,然后会开始ping,ping不通后延迟3秒彻底关机后再断电
[email protected] (447.59 KB, 下载次数: 0) 下载附件 2022-6-16 09:28 上传 hass端: 找到了一个不错的media_player模板,可以模拟media player设备,控制更加方便
[email protected] (119.1 KB, 下载次数: 0) 下载附件 2022-6-16 09:34 上传 五、上代码 需要准备: 1.hass 集成:mqtt nodered ** Media player template(记得重启hass) 前端:button-card(下面的遥控器部分用的button-card,上面是mushroom) 2.nodered 添加节点 node-red-node-ping node-red-contrib-home-assistant-websocket node-red-contrib-mqtt-bridge 3.mqtt 确保nodered hass mqtt通讯正常
nodered添加如下flow:
记得把ip地址换成投影仪的ip flow会映射到hass里三个实体: xgimi.power_off_button xgimi.power_on_button xgimi.state hass configuration.yaml添加如下代码: media_player: - platform: media_player_template media_players: receiver: friendly_name: Xgimi Z6X device_class: receiver value_template: > {% if is_state("sensor.xgimi_state", "on") -%} on {%- else -%} off {%- endif %} turn_on: service: button.press data: {} target: entity_id: button.xgimi_power_on_button turn_off: service: button.press data: {} target: entity_id: button.xgimi_power_off_button volume_up: service: mqtt.publish data: { payload: vol+ ,topic: homeassistant/remote/XGIMI} volume_down: service: mqtt.publish data: { payload: vol- ,topic: homeassistant/remote/XGIMI} mute: service: mqtt.publish data: { payload: mute ,topic: homeassistant/remote/XGIMI}自己按照下面的图片格式化一下
[email protected] (215.63 KB, 下载次数: 0) 下载附件 2022-6-16 09:52 上传 喜欢用homekit的可以把设备映射到homekit里
lovelace添加: cards: - cards: - type: custom:button-card icon: mdi:remote layout: icon_name name: 遥控器 show_state: true color: rgb(31, 129, 240) size: 150% styles: name: - font-size: 14px - font-weight: bold - justify-self: start - type: custom:button-card color_type: blank-card - color: rgb(31, 129, 240) entity: null icon: mdi:menu-up show_name: false style: - height: 50px tap_action: action: call-service service: mqtt.publish service_data: payload: up topic: homeassistant/remote/XGIMI type: custom:button-card - type: custom:button-card color_type: blank-card - color: rgb(31, 129, 240) entity: null icon: mdi:home style: - height: 50px tap_action: action: call-service service: mqtt.publish service_data: payload: home topic: homeassistant/remote/XGIMI type: custom:button-card type: horizontal-stack - cards: - color: rgb(31, 129, 240) entity: null icon: mdi:application-settings style: - height: 50px tap_action: action: call-service service: mqtt.publish service_data: payload: set_up topic: homeassistant/remote/XGIMI type: custom:button-card - color: rgb(31, 129, 240) entity: null icon: mdi:menu-left show_name: false style: - height: 50px tap_action: action: call-service service: mqtt.publish service_data: payload: left topic: homeassistant/remote/XGIMI type: custom:button-card - color_type: card color: rgb(31, 129, 240) entity: null name: OK aspect_ratio: 2 tap_action: action: call-service service: mqtt.publish service_data: payload: pause&play topic: homeassistant/remote/XGIMI type: custom:button-card - color: rgb(31, 129, 240) entity: null icon: mdi:menu-right show_name: false style: - height: 50px tap_action: action: call-service service: mqtt.publish service_data: payload: right topic: homeassistant/remote/XGIMI type: custom:button-card - color: rgb(31, 129, 240) entity: null icon: mdi:menu style: - height: 50px tap_action: action: call-service service: mqtt.publish service_data: payload: menu topic: homeassistant/remote/XGIMI type: custom:button-card type: horizontal-stack - cards: - color: rgb(31, 129, 240) entity: null icon: mdi:keyboard-backspace style: - height: 50px tap_action: action: call-service service: mqtt.publish service_data: payload: back topic: homeassistant/remote/XGIMI type: custom:button-card - type: custom:button-card color_type: card color: rgb(31, 129, 240) icon: mdi:volume-plus style: - height: 30px tap_action: action: call-service service: mqtt.publish service_data: payload: vol+ topic: homeassistant/remote/XGIMI - color: rgb(31, 129, 240) entity: null icon: mdi:menu-down show_name: false style: - height: 50px tap_action: action: call-service service: mqtt.publish service_data: payload: down topic: homeassistant/remote/XGIMI type: custom:button-card - type: custom:button-card color_type: card color: rgb(31, 129, 240) icon: mdi:volume-minus style: - height: 30px tap_action: action: call-service service: mqtt.publish service_data: payload: vol- topic: homeassistant/remote/XGIMI - color: rgb(31, 129, 240) entity: null icon: mdi:volume-mute style: - height: 50px tap_action: action: call-service service: mqtt.publish service_data: payload: mute topic: homeassistant/remote/XGIMI type: custom:button-card type: horizontal-stack type: vertical-stack搞定!
|
CopyRight 2018-2019 实验室设备网 版权所有 |