MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

项目背景与痛点

Hisense TV integration for Home Assistant (sehaas/ha_hisense_tv)是一个针对 Home Assistant 平台的第三方插件,旨在实现 Hisense 智能电视与 Home Assistant 的无缝集成。在现代智能家居体系中,电视作为重要的娱乐与控制节点,它的联动性直接影响到整个平台的体验质量。绝大多数制造商并未向第三方开发者提供完备的开发接口,这使得家用系统构建者在集成智能设备时倍感头痛。

此项目的重要性在于它填补了智能电视与自动化管理平台之间的鸿沟。对于喜爱手动定制 Home Assistant 的用户而言,此插件不仅提升互动性,更能在一定程度上实现智能控制与管理。

核心技术揭秘

Hisense TV integration for Home Assistant 主要依赖 Python 编程语言以及 asyncio 子库,以确保同时支持异步操作。项目的主核心是实现 Hisense 电视API的请求和响应操作,通过 Home Assistant 的插件框架,提供电视控制的一系列功能。

该项目中的关键部分在于如何解析与执行电视设备API及如何通过Home Assistant 外部组件提供用户体验接口。项目中一定的抽象层帮助简化这种通信,包装电视设备的API以使其更易于调用,且通过 Home Assistant 的事件循环机制提高了调用效率。

以下是一个简化数据流图,描述了处理逻辑过程中的主要组件和路径。

graph TD subgraph "用户操作" A[发送命令] A --> B[API 发起异步请求] end subgraph "数据处理" B --> C{"设备响应?"} C -->|是| D[解析响应] C -->|否| E[处理错误] end subgraph "结果反馈" D --> F[返回状态] E --> G[抛出异常] end

功能亮点与差异

此项目的亮点主要集中在其无缝兼容性和灵活性上。作为一个开源项目,它允许用户进行广泛的定制与扩展,以满足其特定需求。相比于其他一些更封闭、支持受限的解决方案,此插件给予用户完全的自由去定制其电视自动化体验。例如,你可以利用定时任务或自动化规则来特定时间切换到特定输入源或更改音量等。

此外,由于它使用 Python 和 Home Assistant 的插件机制,技术支持范围非常广泛,这意味着当基础库更新时,这些插件也更容易进行适配和维护。

应用场景与落地建议

在生产环境中使用此插件前,开发者需要注意添加适当的错误处理与日志记录,这对于长期稳定运行尤为关键。此外,敏感的操作例如设备控制需配置合适的权限管理,以确保应用安全性和可靠性。

推荐的业务场景是家庭自动化与智能家庭环境中。对于构建整体智能套房,家庭自动化控制室或者智能屋内尤其合适,可以通过 Home Assistant 用户界面或语音助手的方式,轻松实施电视的自动化动作。

综合评价

Hisense TV integration for Home Assistant 插件在保持开源的同时,兼顾了兼容性和稳定性,能够为用户提供易于集成的电视控制方案。尽管在高度定制方面可能不如原装控制器方便,但是它提供了无限的扩展机会,这对于拥有高度定制需求的家庭用户来说无疑是一个加分点。其核心优势在于开源、易用与功能接口的广泛。

总体而言,此项目充分展现了如何藉由既有开源技术和开发经验,搭建出具有高度实用性的自动化管理系统,它能有效帮助用户智能家居、精确控制并唤起用户的创造力。

关于

GitHub 原始描述(英文)

Hisense TV integration for Home Assistant

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
392
价值分
120
活跃状态
活跃

语言占比

Python

Release

README

Hisense TV Integration for Home Assistant

Integration an Hisense TV as media player into Home Assistant. The communication is handled via the integrated MQTT broker and wake-on-LAN. Requires Home Assistant >= 2021.12.x.

Current features:

  • Turn on / off
  • Display current status
    • Source (TV, HDMI, Apps)
    • Channel name / number
    • EPG data of current show
  • Volume control
  • Media browser
    • LNB selector
    • Channel selector
    • Apps
  • Read picture setting

TBD:

  • Expose ON/OFF as switch
  • Expose all keys as buttons
  • Enhance EPG/guide handling

Configuration

The TV provides a MQTT broker on port 36669. Home Assistant can only communicate with one MQTT broker, so you have to create a bridge between the two broker.

MQTT

The MQTT broker is secured by credentials. Some TVs (like mine) even require client certificates for incomming connections. I won’t include them in this repo, but you can find them online or extract them yourself. See Acknowledgment.

Connection shema:

+-----------+          +-----------+
| Home      |  client  | Mosquitto |
| Assistant |--------->|           |
+-----------+          +-----------+
                            /\
                     bridge ||
                            \/
                      +-------------+
                      | Hisense TV  |
                      | MQTT Broker |
                      +-------------+

The mosquitto bridge configuration using client certificates.

connection hisense
address <TV_IP_ADDRESS>:36669
username <HISENSE_MQTT_USERNAME>
password  <HISENSE_MQTT_PASSWORD>
clientid HomeAssistant
bridge_tls_version tlsv1.2
bridge_cafile hisense_ca.pem
bridge_certfile hisense_client.pem
bridge_keyfile hisense_client.key
bridge_insecure true
start_type automatic
try_private true
topic /remoteapp/# both 0 <MQTT_PREFIX> ""

Replace <TV_IP_ADDRESS>, credentials and <MQTT_PREFIX> according to your setup. The <MQTT_PREFIX> is needed if you have multiple TVs, otherwise you should just use the default hisense:

topic /remoteapp/# both 0 hisense ""

(Optional) If you have multiple TVs you have to replicate the whole configuration for each TV. The <MQTT_PREFIX> must be unique for every TV. For example:

topic /remoteapp/# both 0 livingroom_tv ""
topic /remoteapp/# both 0 kids_tv ""

(Optional) This setup uses the same prefix for incoming and outgoing messages. The integration supports separated values. You have to adapt the topic setup accordingly.

Wake-on-LAN

The TV can be turned on by a Wake-on-LAN packet. The MAC address must be configured during integration setup.

Setup in Home Assistant

The integration can be added via the Home Assistant UI. Add the integration and setup your TV. During the first setup your TV should be turned on. The integration requires a PIN code from you TV. The PIN will be triggered automatically during setup. This is a onetime step where the client HomeAssistant is requesting access to remote controll the TV.

YMMV

Tested on an Hisense A71 Series with mandatory client certificates. gettvstate does not return a state but can be used to authenticate the client. The

Acknowledgment

Everything I needed to write this integration could be gathered from these sources. Information about the MQTT topics, credentials or certificates can be found there.

评论

暂无评论