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

标题: 这段卡片代码会导致ha core 崩溃吗? [打印本页]

作者: dscao    时间: 2022-12-11 21:41
标题: 这段卡片代码会导致ha core 崩溃吗?
本帖最后由 dscao 于 2022-12-12 14:00 编辑

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

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

  13. {{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



作者: louis_lee    时间: 2022-12-11 23:16
都是supervisor的log,不好定位问题啊。调到debug level, 看看homeassistant log呢

  1. docker container exec -it homeassistant  tail -f /config/home-assistant.log
复制代码


省得HA重启后log没了
作者: yuyuye    时间: 2022-12-12 13:06
我个人经验,模板和md单独用都没啥问题,
但是在md里写模板,特别是带枚举的模板,特别又多次编辑这个带枚举的模板md卡片,
那就会出现负载越来越高,直到弄死ha。
建议:给这段模板做个template sensor,然后md里引用sensor
作者: dscao    时间: 2022-12-12 13:17
yuyuye 发表于 2022-12-12 13:06
我个人经验,模板和md单独用都没啥问题,
但是在md里写模板,特别是带枚举的模板,特别又多次编辑这个带枚 ...

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

回头按你的建议试试。谢谢!
作者: dscao    时间: 2022-12-17 00:34
本帖最后由 dscao 于 2022-12-17 17:16 编辑

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

[attach]44188[/attach]

作者: sirakawa    时间: 2022-12-17 09:08
本帖最后由 sirakawa 于 2022-12-17 09:10 编辑

一直在这么用貌似没遇到啥问题。。
单纯用entity_id判断会好一些- -?
  1.       - type: markdown
  2.         content: >-
  3.           * Battery
  4.           {% for state in states.sensor -%}
  5.             {% if state.entity_id[0:("sensor.battery_" | length)] | trim == "sensor.battery_" %}
  6.               * {{ state.name | lower }} : {{ state.state }} %
  7.             {% endif %}
  8.           {%- endfor %}
  9.           {% for state in states.sensor -%}
  10.             {% if state.entity_id[(state.entity_id | length)-8:(state.entity_id | length)] == "_battery" %}
  11.               * {{ state.name | lower }} : {{ state.state }} %
  12.             {% endif %}
  13.           {%- endfor %}
复制代码


作者: jjcs    时间: 2023-2-5 18:41
请问大佬《pve7.3新版本要求增加一个EFI硬盘。》不加启动虚拟机有警告,但是不影响使用,不清楚有没有稳定性影响
作者: dscao    时间: 2023-2-5 21:35
jjcs 发表于 2023-2-5 18:41
请问大佬《pve7.3新版本要求增加一个EFI硬盘。》不加启动虚拟机有警告,但是不影响使用,不清楚有没有稳定 ...

我一台试了两次加EFI硬盘,第二次成功了,之后就没问题了。
另一台也试了好几次,可每次都不能正常启动。干脆就让它每次启动有警告了。
作者: applepie    时间: 2023-4-10 10:28
各位好,我找到 EFI Disk 的解決方法了,

https://jhartman.pl/2021/11/08/p ... -other-uefi-images/
作者: kaka0992    时间: 2023-4-12 16:06
applepie 发表于 2023-4-10 10:28
各位好,我找到 EFI Disk 的解決方法了,

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

厉害了
作者: xyz5378    时间: 2023-8-1 11:18
我这里修改为seabios  添加efi磁盘  再更换为uefi 启动   就成功了
作者: riture    时间: 2023-8-5 10:00
终于解决那个报错了,谢谢




欢迎光临 『瀚思彼岸』» 智能家居技术论坛 (https://bbs.hassbian.com/) Powered by Discuz! X3.5