惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
N
News | PayPal Newsroom
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
T
Tailwind CSS Blog
博客园 - 叶小钗
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Project Zero
Project Zero
美团技术团队
雷峰网
雷峰网
Martin Fowler
Martin Fowler
P
Privacy & Cybersecurity Law Blog
T
The Blog of Author Tim Ferriss
S
Schneier on Security
V
V2EX
Cisco Talos Blog
Cisco Talos Blog
Blog — PlanetScale
Blog — PlanetScale
G
GRAHAM CLULEY
J
Java Code Geeks
V
Visual Studio Blog
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyberwarzone
Cyberwarzone
Recent Announcements
Recent Announcements
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
Forbes - Security
Forbes - Security
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Hacker News
The Hacker News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Cloudflare Blog
腾讯CDC
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
T
Threatpost
大猫的无限游戏
大猫的无限游戏
NISL@THU
NISL@THU
Cloudbric
Cloudbric
C
CERT Recently Published Vulnerability Notes
C
Check Point Blog
Microsoft Azure Blog
Microsoft Azure Blog

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟 从Python转向Pharo https://blog.just4fun.site/post/iot/iot-open-source-projects/ Python异步编程笔记 https://blog.just4fun.site/post/iot/iot-open-source-hardware-community/ 万物积木化开发者社区 CodeLab ❤️ Blender Scratch3技术分析之云变量 API(第7篇) [译]对管道(Pipes)的偏爱 [译]提出正确的问题比得到正确答案更重要 蓝牙设备与Scratch3.0 创建你的第一个Scratch3.0 Extension Scratch3技术分析之项目内部数据(第6篇) Scratch3技术分析之社区 API(第5篇) Scratch3技术分析之User API(第4篇) Scratch3技术分析之项目主页API(第3篇) Scratch3技术分析之静态资源API(第2篇) Scratch3.0、micro:bit与Windows7 https://blog.just4fun.site/post/iot/zerynth-vs-micropython/ 核聚变、方所与半宅空间 可视化编程为何是个糟糕的主意 codelab.club周末聚会 关于codelab.club '下一件大事'是一个房间 Hungry Robot - Eat everything 编程作为一种思考方式 今日简史 史蒂夫·乔布斯传 罗素自选文集 https://blog.just4fun.site/post/edx/tianjin-scratch-ai/ https://blog.just4fun.site/post/edx/richie-cms-openedx/ 徒步武功山 WebUSB与micro:bit 积木化编程与3D场景 夜宿武功山顶 scratch3-adapter接入优必选Alpha系列机器人 https://blog.just4fun.site/post/edx/video-migration-note/ scratch3-adapter重构笔记 https://blog.just4fun.site/post/edx/edx-community-members/ 两种硬件编程风格的比较 使用micro:bit自制PPT翻页笔 柏拉图对话集 scratch3.0 + micro:bit 七月电影放映计划 非营利组织的管理 Screenly--用树莓派让任何屏幕变为可编程的数字标牌 以最佳实践开始你的Django项目 micro:bit与事件驱动 为Scratch3.0设计的插件系统(上篇) OCR应用一例 近两年读过的一些好书 blockly开发之使用python驱动浏览器中的turtle(2) 牛顿新传 文学理论入门 逻辑的引擎 人生的意义 blockly开发之生成并运行js代码(1) blockly开发之hello world(0) micro:bit使用笔记 神器之Termux https://blog.just4fun.site/post/iot/micropython-notes/ Cozmo what is this Scratch的前世今生 下段旅程 我行在远方 爆裂 途中杂记 https://blog.just4fun.site/post/edx/open-edx-startup/ cozmo系列之入门 - 有性格且可编程的机器人 PaperWeekly开发笔记 创业二三事
Home Assistant 折腾笔记
种瓜 · 2019-06-13 · via 夜行人

文章目录

前言

折腾Home Assistant过程的中做的笔记。

写作本文时基于的环境为:

  • MacOS 10.13.5
  • Python 3.7.2
  • homeassistant==0.94.2

安装

有很多种安装方式可以安装Home Assistant。

对于开发调试而言,直接使用pip安装是最方便的(最新的版本建议用Python3.6以上来安装)

如果计划将Home Assistant产品化,Hass.io可能是最佳方案。Hass.io利用docker、树莓派将Home Assistant打包进容器(当然也可以跑在其他linux发行版里),如此一来,升级、备份、管理、添加组件变得简单。

Hass.io

Hass.io基于hassos,而hassos基于buildroot,buildroot允许你轻松构建裁剪版的嵌入式Linux。

这一块依然有许多可以做的工作,诸如更好的远程管理(balena.io提供了很好的思路和方案),更好的WiFi管理:wifi-connect。对于home-assistant的产品化,Hass.io给出了绝佳的思路。

配置文件

配置文件都在~/.homeassistant里,在Home Assistant 与 Yeelight彩光灯泡的通信过程分析一文里,我们分析了默认配置文件的生成过程。

配置文件列表为:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
➜  .homeassistant tree -a -I 'deps'
.
├── .HA_VERSION
├── .cloud
├── .storage
│   ├── auth
│   ├── auth_provider.homeassistant
│   ├── cloud
│   ├── core.area_registry
│   ├── core.config
│   ├── core.config_entries
│   ├── core.device_registry
│   ├── core.entity_registry
│   ├── core.restore_state
│   ├── frontend.user_data_7a04118ad289497dbaf068d2b098b016
│   ├── onboarding
│   └── person
├── automations.yaml
├── configuration.yaml
├── customize.yaml
├── groups.yaml
├── home-assistant.log
├── home-assistant_v2.db
├── home-assistant_v2.db-shm
├── home-assistant_v2.db-wal
├── scripts.yaml
├── secrets.yaml
└── tts

3 directories, 23 files

可以看到有两个隐藏目录: .cloud.storage, 里头存储一些用户私有数据。

configuration.yaml

是日常用到的配置文件, 相关文档参考Configuring Home Assistant

如果你采用hass.io安装home-assistant,web页面将自带hass-configurator,允许你从web页面编辑configuration.yaml(以及~/.homeassistant里的所有文件)

数据库

home-assistant_v2.db是sqlite数据库。可以使用DB Browser for SQLite打开。

, 可以看到这里头有四张表。

其中eventsstates的表结构值得关注,这两张表的结构,很能反映home-assistant设计的领域原语。

.storage

.storage目录里有很多用户相关的信息,包括用户的登陆信息(用户名/密码,加密后存在auth_provider.homeassistant文件中)。这可能有些反直觉,home-assistant没有将这些信息放在数据库,而是放在一个隐藏目录里。

自定义设备(entity)名

用户可以在web页面自定义设备名。

这些信息存储在.storage目录下的core.entity_registry文件里。

更新设备名称时,会触发一条websocket消息。

1
2
3
4
5
6
7
{
  "type": "config/entity_registry/update",
  "entity_id": "light.gateway_light_7c49eb179d9f",
  "name": "网关2",
  "new_entity_id": "light.gateway_light_7c49eb179d9f",
  "id": 29
}

handle消息的函数为websocket_update_entity

我们进一步跟踪HA是如何更新.storage文件的

及时生效

基于文件的存储如何做到及时生效呢?

在分析文件如何写入时,我们也看到异步读取配置文件的操作。

多用户

HA支持多用户,目前用户角色分为管理员和普通用户。这块的功能还在增强中。

目前还没有为角色分配设备的管理机制。

权限系统也尚未构建,对此有兴趣的朋友可以参考理解权限系统

开发者工具

HA在web面板里为开发者提供了一组开发工具:

  • /dev-service: 服务
  • /dev-state: 状态
  • /dev-event: 事件
  • /dev-template: 模版
  • /dev-mqtt: MQTT
  • /dev-info: 信息

Home Assistant Cloud

Home Assistant Cloud提供安全的远程连接,允许你远程控制设备(在你外出的时候),也允许Amazon Alexa and Google Assistant控制Home Assistant实例.

目前该服务由Home Assistant的合作伙伴Nabu Casa, Inc提供。Nabu Casa, Inc由Home Assistant 和 Hass.io的联合创始人创建。

Nabu Casa

The missing cloud piece for Home Assistant, by the founder of Home Assistant. Control your Home Assistant from anywhere. Fully encrypted.

All data is fully encrypted between your device and your Home Assistant instance. No snooping.

Nabu Casa秉承Home Assistant的理念:隐私优先, 同时它也为用户带来远程控制的便利。鱼和熊掌可以兼得。

我非常喜欢主页上的这段话

1
2
3
4
Let's keep advertisers in the dark
We live in a world where cloud companies are constantly trying to collect more of our data. With Nabu Casa we're breaking this trend.

We operate a cloud that won't store any of your data and processes commands locally. Your data stays local or with the companies you decide to share with.

如何做到这点呢,Nabu Casaprivacy里做了说明,策略就是: 开源!

首先home-assistant是开源的,此外nabucasa client是开源的:nabucasa

对于hass_nabucasa的交互逻辑,可以从测试代码中学习:test_cloud_api.py

我的cloud

这是我接入Nabu Casa云端之后的HA cloud页面。

当我打开Remote Control, 即可点击页面上的链接,进入远程控制页面,没有任何配置!与本地打开HA没有任何不同。

有了公网可访问的入口,更多的webhook就可以在集成里打开了!

开放生态

Home Assistant是个开放生态,其他厂商应该也可以提供Home Assistant Cloud服务。

近期如果有时间,准备对其做个更细致的技术分析。目前来看,只要实现nabucasa即可提供服务。

桌面应用

可以添加为chrome应用(在chrome设置中),之后像APP一样拖拽到桌面,对于交付很友好。