本帖最后由 s763279737 于 2025-5-29 22:35 编辑
我给我的空调做了一个100级的风速调节,现在我想让图标旋转起来,并且旋转速度随风速大小变化。
但是我card-mod的代码试了很多种都没用,求大佬改正。
卡片的样子
原始代码:
type: custom:mushroom-number-card
entity: number.211106240247007_fan_speed
secondary_info: state
primary_info: none
layout: horizontal
visibility:
- condition: state
entity: climate.211106240247007_climate
state_not: "off"
deepseek给我的几种代码:
card_mod:
style: |
/* 定义旋转动画 */
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
/* 根据风速动态设置旋转速度 */
mushroom-shape-icon {
{% set speed = states(entity) | int %}
{% if speed > 0 %}
animation: spin {{ (2.5 - (speed / 100) * 2) | round(1) }}s linear infinite;
{% endif %}
}
card_mod:
style: |
/* 定义旋转动画 */
@keyframes fan-spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* 强制穿透所有层级并应用动画 */
ha-card {
--animation-duration: {{ (3 - (states(entity)|float/100)*2.5 | round(1) }}s;
}
mushroom-shape-icon {
display: flex !important;
justify-content: center;
align-items: center;
}
mushroom-shape-icon > * {
display: block !important;
animation: fan-spin var(--animation-duration, 2s) linear infinite;
animation-play-state: running;
transform-origin: center center !important;
{% if states(entity)|int == 0 %}
animation: none !important;
{% endif %}
}
|