Home Assistant API文档
https://dev-docs.home-assistant.io/en/master/
这里是设备的基本前缀
以下是Home Assistant的全部设备前缀及代表的设备类型:
1. `air_quality`:空气质量监测器设备;
2. `alarm_control_panel`:报警面板设备;
3. `automation`:自动化设备,可用于创建自动化场景;
4. `binary_sensor.`:二元传感器设备,如门窗开关、动作传感器等;
5. `camera.`:摄像头设备;
6. `climate.`:温度调节设备,如空调、暖气等;
7. `cover.`:遮盖设备,如窗帘、百叶窗等;
8. `device_tracker.`:设备跟踪器设备,可用于跟踪人员或物品的位置信息;
9. `fan.`:风扇设备;
10. `geo_location.`:地理位置设备;
11. `group.`:组设备,可将多个设备组合在一起以便进行统一控制;
12. `humidifier.`:加湿器设备;
13. `image_processing.`:图像处理设备,例如面部识别、图像分析等;
14. `input_boolean.`:布尔输入设备,如开关等;
15. `input_datetime.`:日期时间输入设备;
16. `input_number.`:数字输入设备;
17. `input_select.`:下拉菜单输入设备;
18. `input_text.`:文本输入设备;
19. `light.`:灯光设备;
20. `lock.`:锁设备,如门锁、保险柜等;
21. `media_player.`:媒体播放设备,如音响、电视等;
22. `notify.`:通知设备,可用于发送消息通知;
23. `person.`:人员跟踪设备;
24. `plant.`:植物设备,可用于监测植物的状态;
25. `remote.`:遥控器设备;
26. `scene.`:场景设备,可用于快速设置设备状态;
27. `script.`:脚本设备,可用于执行自定义操作;
28. `sensor.`:传感器设备;
29. `simple_alarm.`:简单报警设备;
30. `sleep_number.`:床垫调节设备;
31. `switch.`:开关设备;
32. `timer.`:计时器设备;
33. `tts.`:语音转换设备,可用于将文本转换为语音输出;
34. `vacuum.`:吸尘器设备。
需要注意的是,这只是目前Home Assistant所支持的设备前缀列表,随着Home Assistant的不断发展和更新,可能会增加或删减一些前缀。
MQTT Switch
https://www.home-assistant.io/integrations/switch.mqtt/#retain
Mqtt说明文档
(重要)REST API
https://developers.home-assistant.io/docs/api/rest
每一个接口都会有对应的说明
(重要)WebSocket API
https://developers.home-assistant.io/docs/api/websocket/
接口说明
准备
1:首先你需要安装好homeassistant并确定设备是怎么连接,如果是局域网连接的话就需要你在局域网内进行开发,建议在局域网内做一个内网穿透
(比如natapp或者frp),这样写出来的接口就可以在有网络的情况下就可以控制连接的设备。
2:需要获取access_token
:登录homeassistant点击左下角的用户名字并在右侧页面中滑至最底部创建令牌 (一定要记住)。
REST API接口说明
如果你的ip
没有申请SSL证书那就以http
请求反之则是https
。在/api
前加上你的ip:端口
以/api/
接口为例完整的接口为http://39.108.152.203:8123/api/
GET请求(均为查询homeassistant设备信息)
需要在头部设置参数access_token
Authorization: Bearer ACCESS_TOKEN
/api/
:如果API已启动并正在运行,则返回一条消息
{
"message": "API running."
}
/api/config
:以JSON形式返回当前配置
{
"components":[
"sensor.cpuspeed",
"frontend",
"config.core",
"http",
"map",
"api",
"sun",
"config",
"discovery",
"conversation",
"recorder",
"group",
"sensor",
"websocket_api",
"automation",
"config.automation",
"config.customize"
],
"config_dir":"/home/ha/.homeassistant",
"elevation":510,
"latitude":45.8781529,
"location_name":"Home",
"longitude":8.458853651,
"time_zone":"Europe/Zurich",
"unit_system":{
"length":"km",
"mass":"g",
"temperature":"\u00b0C",
"volume":"L"
},
"version":"0.56.2",
"whitelist_external_dirs":[
"/home/ha/.homeassistant/www",
"/home/ha/.homeassistant/"
]
}
/api/events
:返回一个事件对象数组。每个事件对象都包含事件名称和侦听器计数。
[
{
"event": "state_changed",
"listener_count": 5
},
{
"event": "time_changed",
"listener_count": 2
}
]
/api/services
:
返回一个服务对象数组。每个对象都包含域(domain
)及其包含的服务(services
)。
[
{
"domain": "browser",
"services": [
"browse_url"
]
},
{
"domain": "keyboard",
"services": [
"volume_up",
"volume_down"
]
}
]
/api/history/period/< timestamp>
:返回过去状态更改的数组。每个对象都包含实体的进一步详细信息。
<timestamp>(YYYY MM DDThh:MM:ssTZD)是可选的,默认为请求时间前1天。它决定了周期的开始。
[
[
{
"attributes": {
"friendly_name": "Weather Temperature",
"unit_of_measurement": "\u00b0C"
},
"entity_id": "sensor.weather_temperature",
"last_changed": "2016-02-06T22:15:00+00:00",
"last_updated": "2016-02-06T22:15:00+00:00",
"state": "-3.9"
},
{
"attributes": {
"friendly_name": "Weather Temperature",
"unit_of_measurement": "\u00b0C"
},
"entity_id": "sensor.weather_temperature",
"last_changed": "2016-02-06T22:15:00+00:00",
"last_updated": "2016-02-06T22:15:00+00:00",
"state": "-1.9"
},
]
]
您可以传递以下可选的GET参数:
-
filter_entity_id=<entity_ids>以在一个或多个实体上进行筛选(逗号分隔)。
-
end_time=<timestamp>以URL编码的格式选择周期的结束(默认为1天)。
对于第一个和最后一个状态以外的状态,minimal_response只返回last_changed和state(速度快得多)。 -
no_attributes跳过从数据库返回的属性(速度要快得多)。
-
significant_changes_only仅返回显著的状态更改。
1:
http://localhost:8123/api/history/period/2016-12-29T00:00:00+02:00
2:
http://localhost:8123/api/history/period/2016-12-29T00:00:00+02:00?minimal_response
3:
http://localhost:8123/api/history/period/2016-12-29T00:00:00+02:00?filter_entity_id=sensor.temperature
4:
http://localhost:8123/api/history/period/2016-12-29T00:00:00+02:00?end_time=2016-12-31T00%3A00%3A00%2B02%3A00
/api/logbook/< timestamp>
:返回日志条目的数组
<timestamp>(YYYY MM DDThh:MM:ssTZD)是可选的,默认为请求时间前1天。它决定了周期的开始。
[
{
"context_user_id": null,
"domain": "alarm_control_panel",
"entity_id": "alarm_control_panel.area_001",
"message": "changed to disarmed",
"name": "Security",
"when": "2020-06-20T16:44:26.127295+00:00"
},
{
"context_user_id": null,
"domain": "homekit",
"entity_id": "alarm_control_panel.area_001",
"message": "send command alarm_arm_night for Security",
"name": "HomeKit",
"when": "2020-06-21T02:59:05.759645+00:00"
},
{
"context_user_id": null,
"domain": "alarm_control_panel",
"entity_id": "alarm_control_panel.area_001",
"message": "changed to armed_night",
"name": "Security",
"when": "2020-06-21T02:59:06.015463+00:00"
}
]
您可以传递以下可选的GET参数:
- entity=<entity_id>以筛选一个实体。
- end_time=<timestamp>,以URL编码格式选择从<timestaff>开始的时段结束。
1:
http://localhost:8123/api/logbook/2016-12-29T00:00:00+02:00
2:
http://localhost:8123/api/logbook/2016-12-29T00:00:00+02:00?end_time=2099-12-31T00%3A00%3A00%2B02%3A00&entity=sensor.temperature
3:
http://localhost:8123/api/logbook/2016-12-29T00:00:00+02:00?end_time=2099-12-31T00%3A00%3A00%2B02%3A00
/api/states
:返回状态对象的数组。每个状态都有以下属性:entity_id、state、last_changed和attributes
[
{
"attributes": {},
"entity_id": "sun.sun",
"last_changed": "2016-05-30T21:43:32.418320+00:00",
"state": "below_horizon"
},
{
"attributes": {},
"entity_id": "process.Dropbox",
"last_changed": "22016-05-30T21:43:32.418320+00:00",
"state": "on"
}
]
/api/states/<entity_id>
:返回指定entity_id的状态对象。如果未找到,则返回404。
{
"attributes":{
"azimuth":336.34,
"elevation":-17.67,
"friendly_name":"Sun",
"next_rising":"2016-05-31T03:39:14+00:00",
"next_setting":"2016-05-31T19:16:42+00:00"
},
"entity_id":"sun.sun",
"last_changed":"2016-05-30T21:43:29.204838+00:00",
"last_updated":"2016-05-30T21:50:30.529465+00:00",
"state":"below_horizon"
}
/api/error_log
:以明文响应的形式检索Home Assistant当前会话期间记录的所有错误。
15-12-20 11:02:50 homeassistant.components.recorder: Found unfinished sessions
15-12-20 11:03:03 netdisco.ssdp: Error fetching description at http://192.168.1.1:8200/rootDesc.xml
15-12-20 11:04:36 homeassistant.components.alexa: Received unknown intent HelpIntent
/api/camera_proxy/< camera entity_id>
:返回指定相机entity_id的数据(图像)。
http://localhost:8123/api/camera_proxy/camera.my_sample_camera?time=1462653861261
/api/calendars
:返回日历实体的列表。
[
{
"entity_id": "calendar.holidays",
"name": "National Holidays",
},
{
"entity_id": "calendar.personal",
"name": "Personal Calendar",
}
]
/api/calendars/< calendar entity_id>
:返回指定日历实体id在开始时间和结束时间之间的日历事件列表(独占)。响应中的事件有一个开始和结束,包含日期时间或全天事件的日期。
http://localhost:8123/api/calendars/calendar.holidays?start=2022-05-01T07:00:00.000Z&end=2022-06-12T07:00:00.000Z
[
{
"summary": "Cinco de Mayo",
"start": {
"date": "2022-05-05"
},
"end": {
"date": "2022-05-06"
},
},
{
"summary": "Birthday Party",
"start": {
"dateTime": "2022-05-06T20:00:00-07:00"
},
"end": {
"dateTime": "2022-05-06T23:00:00-07:00"
},
"description": "Don't forget to bring balloons",
"location": "Brian's House"
}
]
POST请求(均为操作homeassistant设备接口)
/api/states/<entity_id>
:
更新或创建状态。您可以创建所需的任何状态,它不必由Home Assistant中的实体支持。此端点在Home Assistant中设置设备的表示形式,并且不会与实际设备通信。要与设备通信,请使用POST/api/services//端点。
如果实体存在,则返回代码为200,如果设置了新实体的状态,则返回码为201。将返回一个位置标头,其中包含新资源的URL。响应主体将包含一个JSON编码的State对象。
{
"attributes": {
"next_rising":"2016-05-31T03:39:14+00:00",
"next_setting":"2016-05-31T19:16:42+00:00"
},
"entity_id": "sun.sun",
"last_changed": "2016-05-30T21:43:29.204838+00:00",
"last_updated": "2016-05-30T21:47:30.533530+00:00",
"state": "below_horizon"
}
curl
-H “Authorization: Bearer ACCESS_TOKEN”
-H “Content-Type: application/json”
-d ‘{“state”: “25”, “attributes”: {“unit_of_measurement”: “°C”}}’
http://localhost:8123/api/states/sensor.kitchen_temperature
/api/events/<event_type>
:触发event_type为的事件,您可以传递一个可选的JSON对象以用作event_data。
{
"next_rising":"2016-05-31T03:39:14+00:00",
}
如果成功,则返回一条消息。
{
"message": "Event download_file fired."
}
(控制)/api/services/< domain>/< service>
:调用特定域中的服务。将在服务执行后或10秒后返回,以先到者为准。
您可以传递一个可选的JSON对象以用作service_data。
{
"entity_id": "light.Ceiling"
}
返回在执行服务时已更改的状态列表
[
{
"attributes": {},
"entity_id": "sun.sun",
"last_changed": "2016-05-30T21:43:32.418320+00:00",
"state": "below_horizon"
},
{
"attributes": {},
"entity_id": "process.Dropbox",
"last_changed": "22016-05-30T21:43:32.418320+00:00",
"state": "on"
}
]
如何获取控制设备的参数
示例1:打开灯(需要参数access_token、设备的entity_id)
curl
-H “Authorization: Bearer ACCESS_TOKEN”
-H “Content-Type: application/json”
-d ‘{“entity_id”: “switch.christmas_lights”}’
http://localhost:8123/api/services/switch/turn_on
首先通过get请求的/api/states接口获取所有设备信息(我这里入库了)
然后通过get请求的/api/services
接口获取所有设备服务对象数组找到domain是switch
可以看到其json格式的数据
那么打开开关完整的接口就是
http://your_homeassistant_host:8123/api/service/switch/turn_on
示例2:控制空调模式(需要参数token、设备的entity_id、空调模式参数和值)
首先通过get请求的/api/states
接口获取所有设备信息(我这里入库了)
然后通过get请求的/api/services
接口获取所有设备服务对象数组找到domain是climate
这里以控制空调模式为例
控制空调模式我们就需要拿到fields下的hvac_mode
参数(制冷为例首先需要开启空调
)
curl
-H “Authorization: Bearer ACCESS_TOKEN”
-H “Content-Type: application/json”
-d ‘{“entity_id”: “switch.christmas_lights”,“hvac_mode”: “cool”}’
http://localhost:8123/api/services/climate/set_hvac_mode
如果需要设置温度需要注意参数的类型值是int、booleam还是String(设置26度
)
curl
-H “Authorization: Bearer ACCESS_TOKEN”
-H “Content-Type: application/json”
-d ‘{“entity_id”: “switch.christmas_lights”,“temperature”: 26}’
http://localhost:8123/api/services/climate/set_temperature
WebSocket API接口说明
homeassistant自己提供了一套websocket连接,这里需要密钥去验证
这里需要前端去连接socket
ws://your_homeassistant_ip:端口/api/websocket会返回
{
"type": "auth_required",
"ha_version": "2021.5.3"
}
连接成功后需要马上发送一条信息给到socket
{
"type": "auth",
"access_token": "your access_token"
}
如果客户端提供了有效的身份验证,则身份验证阶段将由服务器发送auth_ok消息来完成:
{
"type": "auth_ok",
"ha_version": "2021.5.3"
}
如果数据不正确,服务器将回复auth_invalid消息并断开会话。
{
"type": "auth_invalid",
"message": "Invalid password"
}
发送消息subscribe_events将为您的客户端订阅事件总线。您可以监听所有事件,也可以监听特定的事件类型。如果您想监听多个事件类型,则必须发送多个subscribe_events命令。
{
"id": 18,
"type": "subscribe_events",
// Optional
"event_type": "state_changed"
}
订阅成功后对于每个匹配的事件,homeassistant服务器将发送一条类型为event的消息。消息中的id将指向listen_event命令的原始id。
具体订阅信息查看websocket api文档
开发
注意内网还是外网(我这里是用的内网安装的homeassistant使用natapp临时做的穿透)
这里以java为例,我这里创建的是一个maven项目
Maven依赖:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.8</version>
</dependency>
这里需要用到access_token
GET请求(查询服务对象数组)
String auth="your access_token";
OkHttpClient client = new OkHttpClient.Builder().build();
Request reqeust = new Request.Builder().url("http://pndspp.natappfree.cc/api/services")
.header("Authorization", "Bearer " + auth)
.header("User-Agent", "linux")
.header("Accept", "*/*")
.build();
Response resp = client.newCall(reqeust).execute();
String result = resp.body().string();
System.out.println(result);
POST请求(控制灯带闪烁)
JSONObject reqJSON = new JSONObject();
reqJSON.put("entity_id", "light.lemesh_wy0c09_2738_light");
//灯带闪烁(间隔时间长)
reqJSON.put("flash", "long");
String body = reqJSON.toJSONString();
String auth="your access_token";
OkHttpClient client = new OkHttpClient.Builder().build();
Request reqeust = new Request.Builder().url("http://pndspp.natappfree.cc/api/services/light/toggle")
.post(okhttp3.RequestBody.create(MediaType.parse("application/json"), body))
.header("Authorization", "Bearer " + auth)
.header("User-Agent", "linux")
.header("Accept", "*/*")
.build();
Response resp = client.newCall(reqeust).execute();
String result = resp.body().string();
System.out.println(result);
Mysql表设计(自己的想法)
目前一共五张表
home_token
:用户homeassistant的token和用户id绑定
CREATE TABLE `home_token` (
`id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT 'id 入库接口为非必填,修改接口为必填',
`creater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '固定字段,创建者',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '固定字段,修改者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '固定字段,创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '固定字段,修改时间',
`del` smallint DEFAULT '0' COMMENT '固定字段,是否删除,0:未删除;1:删除',
`version` int DEFAULT NULL COMMENT '版本(用于乐观锁)',
`us_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '用户id',
`token` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT 'homeassistant令牌',
`state` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT 'API running.' COMMENT '运行状态',
`person` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'homeassistant用户',
`gps_accuracy` varchar(50) COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'gps精度',
`longitude` varchar(50) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '经度',
`latitude` varchar(50) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '纬度',
`realm_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '域名',
`events` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '获取所有的event名称和监听者数量',
`remarks` text COLLATE utf8mb4_bin COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='用户homeassistant的token'
home_services
:服务对象数组
CREATE TABLE `home_services` (
`id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT 'id 入库接口为非必填,修改接口为必填',
`creater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '固定字段,创建者',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '固定字段,修改者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '固定字段,创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '固定字段,修改时间',
`del` smallint DEFAULT '0' COMMENT '固定字段,是否删除,0:未删除;1:删除',
`version` int DEFAULT NULL COMMENT '版本(用于乐观锁)',
`user_id` varchar(64) COLLATE utf8mb4_bin NOT NULL COMMENT '用户id',
`domain` varchar(100) COLLATE utf8mb4_bin NOT NULL COMMENT '服务域',
`services` text COLLATE utf8mb4_bin NOT NULL COMMENT '服务对象数组json格式',
`remarks` text COLLATE utf8mb4_bin COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='服务对象数组'
home_device_prefix
:连接的设备名称前缀
CREATE TABLE `home_device_prefix` (
`id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT 'id 入库接口为非必填,修改接口为必填',
`creater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '固定字段,创建者',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '固定字段,修改者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '固定字段,创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '固定字段,修改时间',
`del` smallint DEFAULT '0' COMMENT '固定字段,是否删除,0:未删除;1:删除',
`version` int DEFAULT NULL COMMENT '版本(用于乐观锁)',
`prefix_name` varchar(50) COLLATE utf8mb4_bin NOT NULL COMMENT '设备名前缀',
`remarks` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='连接的设备名称前缀'
home_device
:连接的设备
CREATE TABLE `home_device` (
`id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT 'id 入库接口为非必填,修改接口为必填',
`creater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '固定字段,创建者',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '固定字段,修改者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '固定字段,创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '固定字段,修改时间',
`del` smallint DEFAULT '0' COMMENT '固定字段,是否删除,0:未删除;1:删除',
`version` int DEFAULT NULL COMMENT '版本(用于乐观锁)',
`user_id` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '用户id',
`name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '设备名',
`home_room` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '设备位置',
`state` varchar(50) COLLATE utf8mb4_bin NOT NULL COMMENT '设备状态',
`prefix` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '前缀',
`entity_id` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '设备entity_id',
`remarks` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='连接的设备'
home_control
:服务控制参数(通过参数控制设备)
CREATE TABLE `home_control` (
`id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT 'id 入库接口为非必填,修改接口为必填',
`creater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '固定字段,创建者',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '固定字段,修改者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '固定字段,创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '固定字段,修改时间',
`del` smallint DEFAULT '0' COMMENT '固定字段,是否删除,0:未删除;1:删除',
`version` int DEFAULT NULL COMMENT '版本(用于乐观锁)',
`link` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '控制链接',
`status` int NOT NULL COMMENT '状态(0:开关 1:面板 2:下拉框)',
`prefix` varchar(100) COLLATE utf8mb4_bin NOT NULL COMMENT '设备前缀',
`parameter` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '参数json',
`remarks` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='服务控制参数'
home_token:state是调用get请求的/api/
接口,先查询是否开启,再做后续操作
person,gps_accuracy,longitude,latitude是通过get请求的/api/states
接口中的entity_id前缀为person对象获取到它里面attributes
对象的friendly_name
也就是person,需要说明的是gps_accuracy,longitude,latitude这三个不一定会在前缀为person对象里面attributes
对象中出现所以还需要一层判断是否有key
attributes.containsKey("longitude")
home_services:通过调用get请求的/api/services
接口获取并入库,services字段存services对象json格式
home_device_prefix:只在home_device表中插入设置了前缀的设备信息
home_device:只在表中插入home_device_prefix设置了前缀的设备信息,remarks中存入整个json对象
home_control:自己入库存一些控制参数