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

 找回密码
 立即注册
查看: 8603|回复: 13

[修仙教程] 真是煞费苦心!极米投影仪接入终极解决方案

[复制链接]

10

主题

63

帖子

403

积分

中级会员

Rank: 3Rank: 3

积分
403
金钱
340
HASS币
0
发表于 2022-6-16 10:04:22 | 显示全部楼层 |阅读模式
本帖最后由 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次上电断电的测试
开机上面说了官方已经支持上电开机,所以需要备个hass能控制的智能插座

**那正常的开关机流程就是关机后看机器是不是真的关了,如果真的关了就断电,开机的时候通电就好了**

那怎么才能判断投影仪是不是关机了?
可以ping投影仪。**关机后ping不通** 就可以断电了当然如果你的智能插座功率数据读取是实时的,用功率判断是最准确的,但奈何小米的智能插座功率数据延迟很大(几分钟),实在是没什么用户

正确的显示状态:按照上面的逻辑,可以做个sensor,ping不通就断电,状态置为关机,能ping通状态就置为开机,
但有个问题,上电开机后有40秒是ping不通的,而且投影用wifi网络,日常ping会跳,万一跳的高了被断电。。。

所以干脆简单一点,**不做日常状态的判断,只在开关机的时候设置状态**

四、实际效果
hass上按开机按钮后会给智能插座上电,这中间会有1分钟延时,1分钟内会忽略所有的操作(避免操作进入队列,主要是homekit的操作队列机制不明朗),彻底开机后(网络通了)开关状态会变为“开”
关机时会通过api进行关机操作,然后会开始ping,ping不通后延迟3秒彻底关机后再断电

WX20220616-092824@2x.png
hass端:
找到了一个不错的media_player模板,可以模拟media player设备,控制更加方便

WX20220616-093029@2x.png

五、上代码
需要准备:
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:
flows.json.zip (10.82 KB, 下载次数: 80)

记得把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}


自己按照下面的图片格式化一下

WX20220616-095138@2x.png

喜欢用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


搞定!





回复

使用道具 举报

55

主题

621

帖子

3804

积分

论坛元老

Rank: 8Rank: 8

积分
3804
金钱
3178
HASS币
20
发表于 2022-6-16 13:39:41 | 显示全部楼层
是的  还有那个断电后15秒后通电才可以开机
可以设置固定ip给极米 ping不通才断电  还有我那个wifi插座是带功率的  设置两个条件给她  ping-off  和 功率 位10以下  以防万一
回复

使用道具 举报

23

主题

660

帖子

3108

积分

论坛元老

Rank: 8Rank: 8

积分
3108
金钱
2448
HASS币
10
发表于 2022-6-16 14:23:19 | 显示全部楼层
本帖最后由 wshc1216 于 2022-6-16 15:12 编辑

上电自动开机 几年前就有个官方小APP可以实现,只是没推广。以前我也想要接入。。但是后面发现意义不大,还是遥控器操作方便多。,既然拿遥控器,直接用遥控器开机就好了。
后面就做了联动,开投影,半天拉窗帘,晚上灯光改为夜灯。关闭投影恢复原状态。
回复

使用道具 举报

0

主题

27

帖子

172

积分

注册会员

Rank: 2

积分
172
金钱
145
HASS币
0
发表于 2022-9-7 22:55:33 | 显示全部楼层
感谢楼主,刚刚入门hass,已经把z6x顺利接入,谢谢谢谢
回复

使用道具 举报

1

主题

15

帖子

153

积分

注册会员

Rank: 2

积分
153
金钱
138
HASS币
0
发表于 2022-10-24 16:13:47 | 显示全部楼层
搞了半天还是没办法获取投影仪的状态,求帮check一下是哪里出问题了


                               
登录/注册后可看大图
回复

使用道具 举报

10

主题

63

帖子

403

积分

中级会员

Rank: 3Rank: 3

积分
403
金钱
340
HASS币
0
 楼主| 发表于 2022-10-24 21:16:07 | 显示全部楼层
cheukfaiho 发表于 2022-10-24 16:13
搞了半天还是没办法获取投影仪的状态,求帮check一下是哪里出问题了

我的绿米智能插座获取不到功率 所以没有做状态 你可以在开机状态手动点一下 state on 手动设置状态,以后就不出意外就不用手动设置了
找时间我再换个插座然后改一下流程就完美了
回复

使用道具 举报

0

主题

1

帖子

24

积分

新手上路

Rank: 1

积分
24
金钱
23
HASS币
0
发表于 2022-10-29 00:43:19 | 显示全部楼层
本帖最后由 yinchunhui 于 2022-10-29 03:18 编辑

请问如何把Mushroom的卡片与NodeRed里节点关联起来
回复

使用道具 举报

10

主题

63

帖子

403

积分

中级会员

Rank: 3Rank: 3

积分
403
金钱
340
HASS币
0
 楼主| 发表于 2022-11-1 21:21:30 | 显示全部楼层
yinchunhui 发表于 2022-10-29 00:43
请问如何把Mushroom的卡片与NodeRed里节点关联起来

nodered里建了两个节点Xgimi Power Off Button和Xgimi Power On Button,用于media_player扩展的开机和关机,然后直接把创建的media_player(Xgimi Z6x)用mushroom添加到了页面上
回复

使用道具 举报

16

主题

211

帖子

1710

积分

论坛技术达人

积分
1710
金钱
1499
HASS币
10
发表于 2022-11-2 10:02:41 | 显示全部楼层
有个问题。 关机后断开插座。如果要拿遥控器开机怎么办
回复

使用道具 举报

10

主题

63

帖子

403

积分

中级会员

Rank: 3Rank: 3

积分
403
金钱
340
HASS币
0
 楼主| 发表于 2022-11-4 14:57:30 | 显示全部楼层
lhy741059930 发表于 2022-11-2 10:02
有个问题。 关机后断开插座。如果要拿遥控器开机怎么办

我是没有这个需求 弄好这套以后极米投影仪遥控器很长时间没用了
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-27 06:39 , Processed in 0.127638 second(s), 34 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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