请选择 进入手机版 | 继续访问电脑版

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

 找回密码
 立即注册
查看: 4746|回复: 6

[求助] 请问各位大佬,homeassistant有能自动创建新实体id的功能吗?

[复制链接]

8

主题

68

帖子

329

积分

论坛分享达人

积分
329
金钱
261
HASS币
0
发表于 2019-9-23 17:17:31 | 显示全部楼层 |阅读模式
求一个关键词就行,主要是用rest获取json后,想通过获取的数据自动创建新的entity_id,

就是找不到对应功能的组件,不知道有没有这个功能啊

回复

使用道具 举报

5

主题

322

帖子

1345

积分

金牌会员

Rank: 6Rank: 6

积分
1345
金钱
1023
HASS币
0
发表于 2019-9-23 17:21:54 | 显示全部楼层
这个有用么?https://dev-docs.home-assistant. ... .core.HomeAssistant


set(entity_id: str, new_state: Any, attributes: Optional[Dict] = None, force_update: bool = False, context: Optional[homeassistant.core.Context] = None) → None[source]
Set the state of an entity, add entity if it does not exist.

Attributes is an optional dict to specify attributes of this state.

If you just update the attributes and not the state, last changed will not be affected.
回复

使用道具 举报

30

主题

493

帖子

4767

积分

论坛元老

佑桑

Rank: 8Rank: 8

积分
4767
金钱
4259
HASS币
156

教程狂人

发表于 2019-9-23 17:26:40 | 显示全部楼层
本帖最后由 chinyaolin 于 2019-9-23 17:28 编辑

變通的做法您考慮看看
把获取的数据轉存於 MQTT 中
- alias: mqtt_topic_temperature_158d_3F59C8720049
  trigger:
    - platform: mqtt
      topic: 'home/OpenMQTTGateway_ESP32_BLE/BTtoMQTT/3F59C8720049'
  condition:
    - condition: template
      value_template: '{{ not trigger.payload_json.tem == "" }}'
  action:
    - service: mqtt.publish
      data_template:
        topic: home/OpenMQTTGateway_ESP32_BLE/BTtoMQTT/3F59C8720049/tem
        payload: '{{ trigger.payload_json.tem | float | round(1) }}'
ASRock H370 PRO4, 48GB, 8TBx3 + 2TBx3
ESXi 6.7 + Ununtu + Docker + HASS.IO -> Homeassistant OS
(Home Assistant Supervised 官方文件)
回复

使用道具 举报

1

主题

36

帖子

305

积分

论坛技术达人

积分
305
金钱
264
HASS币
20
发表于 2019-9-24 10:45:15 | 显示全部楼层
Entity父类中有个方法generate_entity_id
在初始化自己的实体的时候用这个方法生成实体id,并赋值给self.entity_id
比如我这个电灯init方法:
    def __init__(self, light_index, light_name, hass):
        self._light_index = light_index
        self._name = light_name
        self._state = None
        self._brightness = None
        self._light_helper = None
        self._hass = hass
        self.entity_id = async_generate_entity_id(
            ENTITY_ID_FORMAT, PLATFORM_NAME + "_index_"+str(self._light_index), hass=self._hass
        )
回复

使用道具 举报

8

主题

68

帖子

329

积分

论坛分享达人

积分
329
金钱
261
HASS币
0
 楼主| 发表于 2019-10-13 11:43:25 | 显示全部楼层
看来用config配置文件无法实现这个功能 不过还是谢谢楼上各位大佬了,指出了一些方向
回复

使用道具 举报

3

主题

17

帖子

74

积分

注册会员

Rank: 2

积分
74
金钱
57
HASS币
0
发表于 2020-11-21 19:48:44 | 显示全部楼层
lijunxiong2006 发表于 2019-9-24 10:45
Entity父类中有个方法generate_entity_id
在初始化自己的实体的时候用这个方法生成实体id,并赋值给self.en ...

大佬,能详细说下怎么做吗?
回复

使用道具 举报

3

主题

17

帖子

74

积分

注册会员

Rank: 2

积分
74
金钱
57
HASS币
0
发表于 2020-11-21 21:08:45 | 显示全部楼层
lijunxiong2006 发表于 2019-9-24 10:45
Entity父类中有个方法generate_entity_id
在初始化自己的实体的时候用这个方法生成实体id,并赋值给self.en ...

大佬,能详细说下怎么做吗?
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-19 01:34 , Processed in 0.100228 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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