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

 找回密码
 立即注册
查看: 5153|回复: 11

[技术探讨] 这段卡片代码会导致ha core 崩溃吗?

[复制链接]

77

主题

1391

帖子

2万

积分

元老级技术达人

积分
24360
金钱
22929
HASS币
290
发表于 2022-12-11 21:41:10 | 显示全部楼层 |阅读模式
本帖最后由 dscao 于 2022-12-12 14:00 编辑

今天在想弄一个卡片,简单显示系统中所有电量实体,而不想去一个一个增加实体到卡片,于是找了个代码稍加修改:
markdown卡片中输入:
{% set result = namespace(sensors=[]) %}
{% for state in states.sensor %}
  {% if (is_state_attr(state.entity_id, 'device_class', 'battery') )%}
    {% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ ' %)'] %}
  {% endif %}
{% endfor %}
{% for state in states.binary_sensor %}
  {% if (is_state_attr(state.entity_id, 'device_class', 'battery'))%}
    {% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ ')'] %}
  {% endif %}
{% endfor %}

**系统中电池电量** 传感器:

{{result.sensors|join('\n')}}


开始以为效果不错,但可能实体太多了。反应有点慢,后来系统就无响应了,再之后出现core自动重启了。

之后发生好多次,一开始以为是迁移多模2出问题了,多模2中间也不联网了,折腾好久米家app增加设备时发现多模网关,点击增加后才重新联网,结果token都改变了。还好不用重新配对重启后正常了。

由于昨天配对Zigbee的小主机供电的计量插座重启了pve,今天又出现
WARN: no efidisk configured! Using temporary efivars disk.
TASK WARNINGS: 1折腾半天,发现pve7.3新版本要求增加一个EFI硬盘。
一下子出现好多问题,搞得我都不清楚哪里弄出了这个系统崩溃的问题。

但我在另一外的hass中测试并不有出现反应慢,可能是这边的实体比较少。

谁有兴趣的可以测试一下,到底这个代码是不是导致系统崩溃的原因。

22-12-11 20:22:49 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:23:02 WARNING (MainThread) [supervisor.homeassistant.websocket] Connection is closed
22-12-11 20:23:15 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:23:15 ERROR (MainThread) [supervisor.misc.tasks] Watchdog found a problem with Home Assistant API!
22-12-11 20:23:15 INFO (SyncWorker_1) [supervisor.docker.interface] Restarting ghcr.io/home-assistant/qemux86-64-homeassistant
22-12-11 20:23:25 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:23:57 INFO (MainThread) [supervisor.homeassistant.core] Wait until Home Assistant is ready
22-12-11 20:24:05 INFO (MainThread) [supervisor.resolution.evaluate] Starting system evaluation with state CoreState.RUNNING
22-12-11 20:24:05 INFO (MainThread) [supervisor.resolution.evaluate] System evaluation complete
22-12-11 20:24:05 INFO (MainThread) [supervisor.store.git] Update add-on https://github.com/dscao/rtl_433-hass-addons repository
22-12-11 20:24:05 INFO (MainThread) [supervisor.store.git] Update add-on https://github.com/home-assistant/addons repository
22-12-11 20:24:05 INFO (MainThread) [supervisor.store.git] Update add-on https://github.com/dscao/npc-hass-addons/ repository
22-12-11 20:24:05 INFO (MainThread) [supervisor.store.git] Update add-on https://github.com/zigbee2mqtt/hassio-zigbee2mqtt repository
22-12-11 20:24:05 INFO (MainThread) [supervisor.store.git] Update add-on https://github.com/esphome/hassio repository
22-12-11 20:24:05 INFO (MainThread) [supervisor.store.git] Update add-on https://github.com/hassio-addons/repository-beta repository
22-12-11 20:24:05 INFO (MainThread) [supervisor.store.git] Update add-on https://github.com/AlexxIT/hassio-addons repository
22-12-11 20:24:05 INFO (MainThread) [supervisor.store.git] Update add-on https://github.com/esphome/home-assistant-addon repository
22-12-11 20:24:05 INFO (MainThread) [supervisor.store.git] Update add-on https://github.com/hassio-addons/repository repository
22-12-11 20:24:06 INFO (MainThread) [supervisor.updater] Fetching update data from https://version.home-assistant.io/stable.json
22-12-11 20:24:09 INFO (MainThread) [supervisor.store] Loading add-ons from store: 125 all - 0 new - 0 remove
22-12-11 20:24:09 INFO (MainThread) [supervisor.store] Loading add-ons from store: 125 all - 0 new - 0 remove
22-12-11 20:30:45 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:30:45 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:31:21 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:31:21 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:31:57 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:31:57 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:32:33 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:32:33 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:32:52 INFO (MainThread) [supervisor.homeassistant.api] Updated Home Assistant API token
22-12-11 20:33:30 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:33:39 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:34:06 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:34:15 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:34:53 INFO (MainThread) [supervisor.homeassistant.core] Detect a running Home Assistant instance
22-12-11 20:34:53 INFO (MainThread) [supervisor.api.proxy] Home Assistant WebSocket API request initialize
22-12-11 20:34:53 INFO (MainThread) [supervisor.api.proxy] WebSocket access from df843657_nodered
22-12-11 20:34:59 INFO (MainThread) [supervisor.api.proxy] Home Assistant WebSocket API request running
22-12-11 20:57:24 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:57:24 WARNING (MainThread) [supervisor.misc.tasks] Watchdog miss API response from Home Assistant
22-12-11 20:59:55 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 20:59:55 ERROR (MainThread) [supervisor.misc.tasks] Watchdog found a problem with Home Assistant API!
22-12-11 20:59:55 INFO (SyncWorker_2) [supervisor.docker.interface] Restarting ghcr.io/home-assistant/qemux86-64-homeassistant
22-12-11 21:00:02 INFO (MainThread) [supervisor.api.proxy] Home Assistant WebSocket API error: Received message 257:None is not str
22-12-11 21:00:02 INFO (MainThread) [supervisor.api.proxy] Home Assistant WebSocket API connection is closed
22-12-11 21:00:38 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 21:01:09 INFO (MainThread) [supervisor.resolution.check] Starting system checks with state CoreState.RUNNING
22-12-11 21:01:09 INFO (MainThread) [supervisor.resolution.checks.base] Run check for IssueType.PWNED/ContextType.ADDON
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.checks.base] Run check for IssueType.DNS_SERVER_IPV6_ERROR/ContextType.DNS_SERVER
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.checks.base] Run check for IssueType.DNS_SERVER_FAILED/ContextType.DNS_SERVER
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.checks.base] Run check for IssueType.SECURITY/ContextType.CORE
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.checks.base] Run check for IssueType.TRUST/ContextType.SUPERVISOR
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.checks.base] Run check for IssueType.FREE_SPACE/ContextType.SYSTEM
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.checks.base] Run check for IssueType.IPV4_CONNECTION_PROBLEM/ContextType.SYSTEM
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.check] System checks complete
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.evaluate] Starting system evaluation with state CoreState.RUNNING
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.evaluate] System evaluation complete
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.fixup] Starting system autofix at state CoreState.RUNNING
22-12-11 21:01:10 INFO (MainThread) [supervisor.resolution.fixup] System autofix complete
22-12-11 21:01:14 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config:
22-12-11 21:01:36 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config: [Errno 104] Connection reset by peer
22-12-11 21:01:36 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config: [Errno 104] Connection reset by peer
22-12-11 21:02:27 INFO (MainThread) [supervisor.homeassistant.core] Wait until Home Assistant is ready
22-12-11 21:02:35 INFO (MainThread) [supervisor.resolution.evaluate] Starting system evaluation with state CoreState.RUNNING
22-12-11 21:02:36 INFO (MainThread) [supervisor.resolution.evaluate] System evaluation complete


回复

使用道具 举报

18

主题

587

帖子

4289

积分

元老级技术达人

积分
4289
金钱
3667
HASS币
182
发表于 2022-12-11 23:16:50 | 显示全部楼层
都是supervisor的log,不好定位问题啊。调到debug level, 看看homeassistant log呢

docker container exec -it homeassistant  tail -f /config/home-assistant.log


省得HA重启后log没了
回复

使用道具 举报

7

主题

349

帖子

3233

积分

论坛元老

Rank: 8Rank: 8

积分
3233
金钱
2884
HASS币
0
发表于 2022-12-12 13:06:22 | 显示全部楼层
我个人经验,模板和md单独用都没啥问题,
但是在md里写模板,特别是带枚举的模板,特别又多次编辑这个带枚举的模板md卡片,
那就会出现负载越来越高,直到弄死ha。
建议:给这段模板做个template sensor,然后md里引用sensor

评分

参与人数 1金钱 +20 收起 理由
dscao + 20 谢谢!

查看全部评分

回复

使用道具 举报

77

主题

1391

帖子

2万

积分

元老级技术达人

积分
24360
金钱
22929
HASS币
290
 楼主| 发表于 2022-12-12 13:17:12 | 显示全部楼层
yuyuye 发表于 2022-12-12 13:06
我个人经验,模板和md单独用都没啥问题,
但是在md里写模板,特别是带枚举的模板,特别又多次编辑这个带枚 ...

应该是这个问题,昨晚删除了这段。到今天都没出现崩溃重启了。
另一个地方的系统应该是实体比较少,倒是一直正常。

回头按你的建议试试。谢谢!
回复

使用道具 举报

77

主题

1391

帖子

2万

积分

元老级技术达人

积分
24360
金钱
22929
HASS币
290
 楼主| 发表于 2022-12-17 00:34:10 | 显示全部楼层
本帖最后由 dscao 于 2022-12-17 17:16 编辑

看来这种枚举还是少用好,后来加到模板里面了,也就这一个相似的代码。死机倒是没有了,总体的CPU平均到了60%,今天回家感觉反应慢了很多,看了历史记录原来是25%左右。
把后来加的相关模板实体删除后,重启终于CPU占用回到了25%左右。

1.jpg
回复

使用道具 举报

17

主题

800

帖子

5740

积分

论坛元老

Rank: 8Rank: 8

积分
5740
金钱
4935
HASS币
0
发表于 2022-12-17 09:08:48 | 显示全部楼层
本帖最后由 sirakawa 于 2022-12-17 09:10 编辑

一直在这么用貌似没遇到啥问题。。
单纯用entity_id判断会好一些- -?
      - type: markdown
        content: >-
          * Battery
          {% for state in states.sensor -%}
            {% if state.entity_id[0:("sensor.battery_" | length)] | trim == "sensor.battery_" %}
              * {{ state.name | lower }} : {{ state.state }} %
            {% endif %}
          {%- endfor %}
          {% for state in states.sensor -%}
            {% if state.entity_id[(state.entity_id | length)-8:(state.entity_id | length)] == "_battery" %}
              * {{ state.name | lower }} : {{ state.state }} %
            {% endif %}
          {%- endfor %}

回复

使用道具 举报

47

主题

1657

帖子

6692

积分

论坛元老

Rank: 8Rank: 8

积分
6692
金钱
5025
HASS币
40
发表于 2023-2-5 18:41:46 | 显示全部楼层
请问大佬《pve7.3新版本要求增加一个EFI硬盘。》不加启动虚拟机有警告,但是不影响使用,不清楚有没有稳定性影响
折腾精神永存,感恩感谢论坛每一位愿意分享和帮助过我的大佬,论坛有你更精彩
回复

使用道具 举报

77

主题

1391

帖子

2万

积分

元老级技术达人

积分
24360
金钱
22929
HASS币
290
 楼主| 发表于 2023-2-5 21:35:14 | 显示全部楼层
jjcs 发表于 2023-2-5 18:41
请问大佬《pve7.3新版本要求增加一个EFI硬盘。》不加启动虚拟机有警告,但是不影响使用,不清楚有没有稳定 ...

我一台试了两次加EFI硬盘,第二次成功了,之后就没问题了。
另一台也试了好几次,可每次都不能正常启动。干脆就让它每次启动有警告了。
回复

使用道具 举报

0

主题

3

帖子

54

积分

注册会员

Rank: 2

积分
54
金钱
51
HASS币
0
发表于 2023-4-10 10:28:24 | 显示全部楼层
各位好,我找到 EFI Disk 的解決方法了,

https://jhartman.pl/2021/11/08/p ... -other-uefi-images/

评分

参与人数 2金钱 +28 收起 理由
kaka0992 + 8 感谢楼主分享!
dscao + 20 感谢分享!实测有用。

查看全部评分

回复

使用道具 举报

20

主题

265

帖子

1852

积分

金牌会员

Rank: 6Rank: 6

积分
1852
金钱
1587
HASS币
0
发表于 2023-4-12 16:06:23 | 显示全部楼层
applepie 发表于 2023-4-10 10:28
各位好,我找到 EFI Disk 的解決方法了,

https://jhartman.pl/2021/11/08/proxmox-7-cant-boot-to-uefi-h ...

厉害了
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-27 04:04 , Processed in 0.155788 second(s), 35 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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