找回密码
 立即注册

微信扫码登录

搜索
查看: 3557|回复: 66

[UI界面] 【更新V2】自制第三方卡片分享,popup-button-card,一个自带弹窗的按钮卡片

  [复制链接]

38

主题

257

回帖

2301

积分

论坛UI达人

积分
2301
金钱
2001
HASS币
60
发表于 2025-9-27 12:47:30 | 显示全部楼层 |阅读模式
本帖最后由 gasment 于 2025-10-24 22:54 编辑

少废话,先上图
演示.webp

弹窗方案之前最早用的broswer-mod,这货除了弹窗功能外还附带了很多杂七杂八的东西,而且弹窗比较死板,兼容性也不好,用了不久就放弃了;
后面换为了bubble-card的popup子卡片,效果蛮好,功能丰富,但是弹窗样式修改不友好,动点啥都要去趴css样式,能实现的效果也比较受限;


于是我就琢磨自己搞,新弹窗卡!由于没有编程基础,只能依靠ai代劳,在与gpt大战300回合后,终于是把基础功能搓出来了
我将其命名为popup-button-card

它的卡片插入方式类似broswer-mod,在特定字段插入其他卡片的代码,这样就不会像bubble-card的pop-up子卡片一样需要占用仪表盘位置,也不需要为弹窗内容预留卡片空间,非常适合以一个小按钮,带出一坨大卡片的使用情况,而这坨大卡片,又不会影响原有卡片或面板的布局,
同时它又比broswer-mod灵活更多,支持超多自定义选项和不同的弹窗展开方式,动画也更优雅


2025.10.24 更新v2.2.5
  • 新增:弹窗content内容,支持外部卡片引用
2025.10.21 更新v2.2.4
  • 改进:优化弹窗动画
  • 新增:filter_for_ha_action_to_close_popup配置,可为any_ha_action_to_close_popup配置过滤器,自定义何种操作需要自动收起弹窗,何种操作不需要,配置示例见下文说明
2025.10.8 更新v2.2.2
  • 修复:上一版本修改造成的单卡片宽度错误问题
  • 修复:修复与ha自带more-info弹窗的兼容性,现在可以正常在弹窗内触发more-info窗口
  • 修复:优化在全屏弹窗模式时,弹窗外部滑动拦截的逻辑
  • 新增:为expand_side以外的所有yaml配置项,添加js模板支持(实验性,自行测试)
  • 新增:any_ha_action_to_close_popup配置,可选参数true/false,可用于启用和关闭单次交互操作后,自动关闭弹窗
  • 改进:content中内嵌的卡片的默认布局,在不配置styles->content->height/width时,默认为包裹内部卡片所需的最小宽高,并且水平垂直居中,如需底部居中,可使用margin-bottom属性,eg.
styles:
  content:
    - margin-bottom: 100px  #100px差不多是可以避开关闭按钮的高度

2025.10.5 更新v2.1.6
  • 修复按钮的宽高属性逻辑,现在不配置时宽高由其内元素撑开,需要具体尺寸则配置为具体尺寸,需要自动拉伸到外部容器尺寸时,配置为100%

2025.10.5 更新v2.1.5

  • 修复:单弹窗模式(multi_expand: false),快速切换弹窗时出现的按钮元素残留问题
  • 新增:当弹窗内容为空时(不配置content),不再执行弹窗呼出
  • 新增:启用弹窗外部模糊效果时(popup_outside_blur: true),禁止弹窗外部的滑动操
  • 改进:将name/state/label的文本渲染方式从textContent换为innerHTML,以支持html语法,比如换行
    换行示例
    name: 示例<br>按钮
    styles:
      name:
         - line-height: 1.2
    默认行高为1.1,可配置styles属性自定义
  • 修复:全屏弹窗打开时,已打开非全屏弹窗的无法关闭和关闭延迟问题

2025.10.2  更新v2.1.3
  • 修复单弹窗模式时,新旧弹窗交替产生的重叠和闪烁问题
  • 修复单弹窗模式时,关闭弹窗过程中的按钮闪烁问题

2025.10.1  更新v2.1
  • 新增popup_outside_blur配置,用于启用和禁用非弹窗区域的背景模糊功能,如图:
     *背景模糊量可调,由styles->popup_outside_blur样式控制
     *开启背景模糊的卡片,单页面多弹窗功能将不再有效

blur.webp

  • 修复全屏模式的嵌套功能,现在可正常在全屏弹窗中,嵌入非全屏弹窗,如图
full_screen_with_small_popup.webp

*目前有一个bug还无法解决,因为ios/ipad系统的限制,在全屏弹窗中拉起局部弹窗,如上图,模糊效果无法覆盖全屏,可以使用纯色+透明度来模拟接近效果,后文提及,安卓和PC没有这个问题


安装说明:
复制本项目仓库地址:
游客,如果您要查看本帖隐藏内容请回复
  ,在HACS添加Custom repositories,Repositories填写仓库地址,Type选择Dashboard;
搜索:popup-button-card,下载安装,按提示刷新页面点击新建卡片,往下滑,如正常安装就会看到这个卡片,如图,如果没有,清除浏览器缓存,ctrl+f5强制刷新
{7DBDEE0E-3ED8-4167-A9C6-85C92A00204F}.png


配置说明:

配置项效果 使用说明 配置示例
type 声明卡片类型 必须 type: custom:popup-button-card
variables 配置变量,可在卡片或模板中复用 可选,用法与button-card一致
template 模板引用 可选,用法与button-card一致
card_function 配置卡片角色 可选,接受参数button/content,默认button;
详细用法见下文
card_function:content
name 文本元素,布局受grid配置控制 可选,接受字符串与js表达式 name: 我的按钮
label 文本元素,布局受grid配置控制 可选,接受字符串与js表达式 label: 我的标签
state 文本元素,布局受grid配置控制 可选,接受字符串与js表达式 state: 114514
button_icon 按钮图标,布局受grid配置控制 可选,接受mdi图标与文件路径 button_icon: mdi:lightbulb-group
expand_side 弹窗的展开方向(相对于按钮) 可选,默认向下;
接受参数:top/bottom/left/right/full_screen
expand_side: bottom
button_effect 弹窗展开时,按钮的凸显效果 可选,接受参数true/fasle button_effect: true
button_effect_color 按钮的凸显效果的颜色 可选,接受常见颜色代码或js表达式 button_effect_color: blue
any_ha_action_to_close_popup 是否启用弹窗内的单次ha action服务
调用(实体操作)后,自动关闭弹窗
可选,默认false any_ha_action_to_close_popup: true
filter_for_ha_action_to_close_popup any_ha_action_to_close_popup为true时,
可过滤特定操作触发自动关闭弹窗
可选,配置方法见下文
updown_slide_to_close_popup 是否启用上下滑动屏幕时,自动收起弹窗 可选,接受参数true/false updown_slide_to_close_popup: true
multi_expand 是否启用单页面上的多个弹窗并存 可选,接受true/false
(最好同一页面的所有弹窗保持一致启用或禁用)
multi_expand: true
tap_action 按钮点击动作 可选,支持两种行为,popup & action,配置方式见下文
hold_action 按钮长按动作 可选,支持两种行为,popup & action,配置方式见下文
popup_outside_blur 开启或关闭弹窗外部的背景模糊效果 可选,接受true/false,
注意开启popup_outside_blur后,multi_expand会失效
popup_outside_blur: true
styles 卡片内各元素的css样式定义 可选,支持通用css样式插入,
支持js表达式返回值,配置方式见下文
content 弹窗内容 可在此处接上其他卡片的yaml代码,
或者通过id引用已存在的内容,配置方式见下文

JS表达式写法
  • 基本与button-card一致
  • 分行符使用“|”、“>-”,另起一行使用[[[···]]]包裹js代码
  • 读取实体主属性使用:states[your_entity_id].state
  • 读取实体附加属性使用:states[your_entity_id].attributes.xxxxx
  • 可以使用变量代替实体id: states[${variables.your_entity_id}].state
  • 支持赋值变量var/cont/let,支持if else 多行嵌套
  • 使用return返回数值
  • 示例:
button_effect_color: |
    [[[
        var state = states[`sensor.entity`].state
        if (state === "off"){
        return "#D7DFED"
        } else if (state === "cool"){
        return "#2483FF"
        } else if (state === "heat"){
        return "#FF6B6B"
        } else if (state === "dry"){
        return "#54CEAE"
        } else if (state === "fan_only"){
        return "#4CCBA9"
        } else if (state === "auto"){
        return "#464BD8"
        } else {
        return "#D7DFED"
        }
    ]]]

card_function写法
  • 当不配置card_function或配置card_function:button时,卡片作为主角色,提供按钮与弹窗,支持上文全部配置参数
  • 当配置card_function:content时,卡片作为弹窗内容提供者,不再支持上文参数,它具有自己的配置项和配置写法
  • 当配置card_function:content时,卡片将提供一个可供内部嵌套的卡片容器,以承载弹窗内容,同时提供一个卡片id,用于主角色卡片的索引引用
  • button主角色卡片可以跨视图引用content内容卡,但不能跨仪表盘引用
  • 当配置card_function:content时,卡片在非编辑模式下不可见,编辑模式时可见
  • content卡配置示例:
配置项 效果 使用说明 配置示例
type 声明卡片类型 必须 type: custom:popup-button-card
card_function 声明卡片角色 必须 card_function:content
content_id 声明卡片ID 必须,id必须唯一 content_id:example_id
content 弹窗内容 支持单卡片或多卡片,多卡片自动使用垂直堆叠 见下文
content内嵌卡片写法&完整配置示例
type: custom:popup-button-card
card_function: content
content_id: example-id
content:
  card:  #单卡片
    type: custom:button-card
    ····
type: custom:popup-button-card
card_function: content
content_id: example-id
content:
 cards:  #多卡片
   - type: custom:button-card
       ····
   - type: custom:button-card
       ····
   - type: custom:button-card
       ····

filter_for_ha_action_to_close_popup用法
  • 支持两个数组入口
  • include_keyword,如果实体操作包含include_keyword内的关键词,则触发自动关闭弹窗
  • exclude_keyword,如果实体操作包含exclude_keyword内的关键词,则不会触发自动关闭弹窗
配置示例:
filter_for_ha_action_to_close_popup:
  include_keyword: 
    - switch.entity
    - light.entity
    - light.turn_off
    - switch.turn_off
    - more-info
    - navigation
  exclude_keyword: 
    - vacuum.start
    - sensor.entity

tap_action & hold_action用法
  • 两个交互都支持两种行为,popup & action,action使用官方卡片写法,也就是互动选项的yaml代码,两者写法一致
  • tap_action & hold_action配置互斥,不可配置为相同行为
  • 配置示例1,点击打开弹窗,长按切换实体开关
tap_action: popup
hold_action:
  action: perform-action
  perform_action: switch.toggle
  target:
    entity_id: switch.entity
  • 配置示例2,点击切换实体开关,长按打开弹窗
tap_action: 
  action: perform-action
  perform_action: switch.toggle
  target:
    entity_id: switch.entity
hold_action: popup

styles用法
  • styles由多个数组构成,每个数组入口固定,数组内可配置通用css样式,或使用js表达式动态返回
  • styles->content,设置弹窗外部包裹容器的样式
styles:
  content:
    - box-shadow: none
    - background: lightgray
    - width: 95%
    - height: 300px
  • styles->button,设置按钮的样式
styles:
  button:
    - height: 60px
    - width: 100%  
    - background: |
        [[[
            if (states[`switch.entity`].state === "on"){
                return "green"
            } else {
                return "red"
            }
        ]]]
    - border-radius: 10px
  • styles->name/label/state,设置3个文本的样式
styles:
  name:
    - font-weight: bold  #加粗字体
    - font-size: 16px  #字体大小
    - color: white   #字体颜色
    - letter-spacing: 1px  #文件间距
    - margin-left: 2px  #左右像素位移
    - margin-top: 2px  #上下像素位移
  label: #同上
  state: #同上
  • styles->icon,设置图标的样式
styles:
  icon:
    - width: 40px  #图标高度
    - height: 40px #图标宽度
    - color: white  #图标颜色
  • styles->grid,设置name/label/state/icon的布局位置,grid写法可直接参考button-card
styles:
  grid:
    - display: grid
    - grid-template-areas: |
        "i n l"
        "i s s"
    - grid-template-columns: auto auto auto
    - grid-template-rows: 25px 25px
    - justify-items: center
  • styles->overlay,仅全屏模式弹窗有效,设置弹窗卡片内容之外的背景样式,不配置时为模糊效果,可以配置为纯色
styles:
  overlay:
    - background: white #纯色
    - backdrop-filter: none
  • styles->popup_close_button,仅全屏模式有效,设置弹窗关闭按钮的样式
styles:
  popup_close_button:
    - bottom: 20px
    - width: 56px
    - height: 56px
    - background: rgba(255, 64, 64, 0.9)
    - color: white
    - font-size: 26px
  • styles->popup_outside_blur,用于配置弹窗外的背景模糊量,非全屏模式有效,由于ios端限制,此效果与PC/Android存在差异
styles:
  popup_outside_blur:
    - backdrop-filter: blur(100px)  #默认10px,越大越模糊

content用法
  • content用于插入其他卡片到弹窗内,理论上支持所有卡片,但兼容性不一,需要自行测试
  • 有两种插入方式,直接插入 & 外部引用
1.、直接插入,适合内嵌简单、yaml配置量低的卡片。示例:
content:
  card:
    type: vertical-stack
    cards:
      - type: button
        show_name: true
        show_icon: true
        entity: switch.ui_lovelace_minimalist_pre_release
      - type: light
        entity: light.xxxx_light
2、外部引用,适合复杂、yaml配置量大的卡片,方便独立维护与修改,支持跨视图引用。示例:
content:
  from_id: example-id
* example-id为card_function:content时配置的content_id

完整配置示例:
type: custom:popup-button-card
name: 示例按钮
button_icon: mdi:lightbulb-group
expand_side: bottom
button_effect: true
button_effect_color: yellow
updown_slide_to_close_popup: true
any_ha_action_to_close_popup: fasle
tap_action: popup
hold_action: none
multi_expand: true
popup_outside_blur: true
styles:
  popup_outside_blur:
    - backdrop-filter: blur(100px)
  content:
    - box-shadow: none
    - background: rgba(0,0,0,0)
    - width: 200px
  button:
    - height: 60px
    - width: auto
    - background: orange
    - border-radius: 10px
  name:
    - font-weight: bold
    - font-size: 16px
    - color: white
    - letter-spacing: 1px
    - margin-left: 2px
  icon:
    - width: 40px
    - height: 40px
    - color: white
  state:
    - font-weight: bold
    - font-size: 16px
    - color: white
    - letter-spacing: 1px
    - margin-left: 2px
  label:
    - font-weight: bold
    - font-size: 16px
    - color: white
    - letter-spacing: 1px
    - margin-left: 2px
  overlay:
    - background: gray #纯色
    - backdrop-filter: none
  popup_close_button:
    - bottom: 20px
    - width: 56px
    - height: 56px
    - background: rgba(255, 64, 64, 0.9)
    - color: white
    - font-size: 26px
  grid:
    - display: grid
    - grid-template-areas: |
        "i n l"
        "i s s"
    - grid-template-columns: auto auto auto
    - grid-template-rows: 25px 25px
    - justify-items: center
content:
  from_id: example_id


{B46625F0-E11A-4440-8DEE-E8963C1BFA14}.png
image.png
{9F0A98AC-C8C5-40A0-8CB2-D44078285F16}.png
image.png
动画3.webp
动画4.webp
image.png
{C7FD334B-4CC6-4C6D-AAF7-0E06920CB643}.png
expand-side.webp
color-effect.webp
updown-close.webp
updown-still.webp
full_screen.webp

popup_button_card.js

19.51 KB, 下载次数: 16

v1

popup_button_card.js

71.35 KB, 下载次数: 0

v2.2.4

评分

参与人数 4金钱 +35 收起 理由
hnb123 + 5 感谢楼主分享!
Tamaki + 5 高手,这是高手!
sorrypqa + 20 大神666!
lc0888 + 5 赠人玫瑰,手留余香!

查看全部评分

回复

使用道具 举报

64

主题

1629

回帖

1万

积分

元老级技术达人

积分
13436
金钱
11733
HASS币
80
发表于 2025-9-27 14:19:56 | 显示全部楼层
broswer-mod这玩意的确不好用,各种疑难杂症
回复

使用道具 举报

2

主题

59

回帖

488

积分

中级会员

积分
488
金钱
427
HASS币
0
发表于 2025-9-27 15:13:02 | 显示全部楼层
学习学习
回复

使用道具 举报

7

主题

89

回帖

1830

积分

金牌会员

积分
1830
金钱
1734
HASS币
0
发表于 2025-9-27 15:22:38 | 显示全部楼层
学习学习学习学习
回复

使用道具 举报

2

主题

59

回帖

488

积分

中级会员

积分
488
金钱
427
HASS币
0
发表于 2025-9-27 16:03:26 | 显示全部楼层
  expand_side: left   #弹窗出现的方向,接受top/bottom/left/right,
            content:  #content弹窗内容
              card:  #可以在此后面衔接任意卡片代码,将会出现在弹窗容器中
                # type: custom:button-card

                # type: vertical-stack
                type: vertical-stack
                # card_mod:
                #   style: |
                #     ha-card {
                #       background: white;
                #       border-radius: 12px;
                #       padding: 16px;
                #       box-shadow: 0 2px 4px rgba(0,0,0,0.1);
                #     }
                cards:
                  - type: horizontal-stack



                    # title: 用电状态
                    cards:
                      - type: sensor
                        entity: sensor.watermetertest_yongliang
                        name: 水表量
                        icon: mdi:home-lightning-bolt-outline
                      - type: sensor
                        entity: sensor.jin_ri_yong_shui_liang
                        name: 今日用水量
                        icon: mdi:home-lightning-bolt-outline
                        detail: 1
                      - type: sensor
                        entity: sensor.zuo_ri_yong_shui_liang
                        name: 昨日用水量
                        icon: mdi:home-lightning-bolt-outline
                        # unit: 元
                        detail: 1

怎么设置都在右下角,然后总是有一段距离是怎么回事
QQ_1758960156569.png
回复

使用道具 举报

38

主题

257

回帖

2301

积分

论坛UI达人

积分
2301
金钱
2001
HASS币
60
 楼主| 发表于 2025-9-27 17:32:57 | 显示全部楼层
Zuray 发表于 2025-9-27 16:03
expand_side: left   #弹窗出现的方向,接受top/bottom/left/right,
            content:  #content弹 ...

代码和截图贴全一些,现在看不出问题
回复

使用道具 举报

0

主题

36

回帖

931

积分

高级会员

积分
931
金钱
895
HASS币
0
发表于 2025-9-27 18:28:49 | 显示全部楼层
学习学习
回复

使用道具 举报

2

主题

59

回帖

488

积分

中级会员

积分
488
金钱
427
HASS币
0
发表于 2025-9-27 19:19:27 | 显示全部楼层
          - type: custom:popup-button-card    #固定首行,不可变
            unique_id: xxxx11122333     #唯一id,用于弹窗机制,可配置任意字母数字,不重复即可
            name: 示例名称

            style:
              left: 380px
              top: 180px
              width: 30px
              height: 56px
            #name: |    #或模板写法,以空调为例
            #   [[[
            #       var state = states[`climate.entity`].state;
            #       if (state === "off"){
            #         return "已关机";
            #       } else if (state === "cool"){
            #         return "制冷模式";
            #       } else if (state === "heat"){
            #         return "制热模式";
            #       } else if (state === "dry"){
            #         return "除湿模式";
            #       } else if (state === "fan_only"){
            #         return "送风模式";
            #       } else if (state === "auto"){
            #         return "自动模式";
            #       } else {
            #         return "未 知";
            #       }
            #   ]]]
            button_icon: mdi:xxxxx   #支持内置mdi图标,或图标文件url路径
            #button_icon: /local/path_to_your_file    #文件路径写法
            #button_icon: |    #模板写法,以开关为例,on/off返回不同图标
            #   [[[
            #       var state = states[`switch.entity`].state;
            #        if (state === "on"){
            #          return "/local/switch_on.svg"
            #        } else {
            #          return "/local/switch_off.svg"
            #        }
            #   ]]]
            expand_side: left   #弹窗出现的方向,接受top/bottom/left/right
            expand_area_grid: 0px  #弹窗与按钮之间的空隙距离
            button_effect: true    #true/false , 是否开启弹窗打开后,按钮的额外视觉效果
            button_effect_color: "#D7DFED"  #上一条按钮额外视觉效果的颜色选项,接受html颜色代码或rgb值,html颜色代码记得使用双引号括起来
            #button_effect_color: rgb(255,255,255)  #rgb值写法
            #button_effect_color: |    #模板写法,以空调为例
            #   [[[
            #       var state = states[`climate.entity`].state
            #       if (state === "off"){
            #         return "#D7DFED"
            #       } else if (state === "cool"){
            #         return "#2483FF"
            #       } else if (state === "heat"){
            #         return "#FF6B6B"
            #       } else if (state === "dry"){
            #         return "#54CEAE"
            #       } else if (state === "fan_only"){
            #         return "#4CCBA9"
            #       } else if (state === "auto"){
            #         return "#464BD8"
            #       } else {
            #         return "#D7DFED"
            #       }
            #   ]]]
            updown_slide_to_close_popup: true  #true/false , 页面上下滑动时,是否自动关闭弹窗
            styles:    # css styles 属性配置,此部分与button-card雷同,通用css样式基本都可配置
              content:   #content字段,负责配置弹窗容器的样式
                - box-shadow: none  #关闭阴影
                - background: rgba(0,0,0,0) #透明背景
                - margin-top: "13px"   #弹窗整体上下位移
                - margin-left: "10px"  #弹窗整体左右位移
              button:   #button字段,负责配置按钮的样式
                - height: 70px  #按钮高度
                - width: 70px   #按钮宽度
                - background: |  #按钮背景色,与上面button_effect_color写法一致
                    [[[
                        var state = states[`climate.entity`].state
                        if (state === "off"){
                          return "#D7DFED"
                        } else if (state === "cool"){
                          return "#C9E9F9"
                        } else if (state === "heat"){
                          return "#F4CECE"
                        } else if (state === "dry"){
                          return "#C8F4E8"
                        } else if (state === "fan_only"){
                          return "#ACF1B0"
                        } else if (state === "auto"){
                          return "#BABCE8"
                        } else {
                          return "#D7DFED"
                        }
                    ]]]
                - border-radius: 20px   #按钮圆角
              name:   #name字段,负责文本内容样式控制
                - font-weight: bold   #文本加粗
                - font-size: 14px   #字体大小
                - color: rgb(85,110,127)  #字体颜色
                - letter-spacing: 1px  #字符间距
                - margin-left: 2px  #整体左右位移
              icon:  #icon字段,负责图标样式控制
                - width: 50px   #图标高度
                - height: 50px  #图标宽度
                - color: white  #图标颜色
              grid:  #grid字段,负责图标与文本的布局形式
                - display: grid
                - grid-template-areas: |  #"i"代表icon,图标,“n”代表name文本,它们上下左右排布会对应到按钮布局上,比如这里icon位于name上方
                    "i"
                    "n"
                - grid-template-columns: auto  #列宽度
                - grid-template-rows: 45px 25px #行宽度
                - justify-items: start #水平对齐方式,start/center/end
            content:  #content弹窗内容
              card:  #可以在此后面衔接任意卡片代码,将会出现在弹窗容器中
                # type: custom:button-card

                # type: vertical-stack
                type: vertical-stack
                # card_mod:
                #   style: |
                #     ha-card {
                #       background: white;
                #       border-radius: 12px;
                #       padding: 16px;
                #       box-shadow: 0 2px 4px rgba(0,0,0,0.1);
                #     }
                cards:
                  - type: horizontal-stack



                    # title: 用电状态
                    cards:
                      - type: sensor
                        entity: sensor.watermetertest_yongliang
                        name: 水表量
                        icon: mdi:home-lightning-bolt-outline
                      - type: sensor
                        entity: sensor.jin_ri_yong_shui_liang
                        name: 今日用水量
                        icon: mdi:home-lightning-bolt-outline
                        detail: 1
                      - type: sensor
                        entity: sensor.zuo_ri_yong_shui_liang
                        name: 昨日用水量
                        icon: mdi:home-lightning-bolt-outline
                        # unit: 元
                        detail: 1

                  



QQ_1758971934217.png
回复

使用道具 举报

38

主题

257

回帖

2301

积分

论坛UI达人

积分
2301
金钱
2001
HASS币
60
 楼主| 发表于 2025-9-27 20:44:16 | 显示全部楼层
Zuray 发表于 2025-9-27 19:19
- type: custom:popup-button-card    #固定首行,不可变
            unique_id: xxxx11122333  ...

不要乱加style字段,自带的styles已经支持通用css样式修改

你想改弹窗大小,直接在styles.content内改就行了
type: custom:popup-button-card    #固定首行,不可变
unique_id: xxxx11122333
name: 示例名称
button_icon: mdi:xxxxx   #支持内置mdi图标,或图标文件url路径
expand_side: left   #弹窗出现的方向,接受top/bottom/left/right
expand_area_grid: 0px  #弹窗与按钮之间的空隙距离
button_effect: true    #true/false , 是否开启弹窗打开后,按钮的额外视觉效果
button_effect_color: "#D7DFED"  #上一条按钮额外视觉效果的颜色选项,接受html颜色代码或rgb值,html颜色代码记得使用双引号括起来
updown_slide_to_close_popup: true  #true/false , 页面上下滑动时,是否自动关闭弹窗
styles:    # css styles 属性配置,此部分与button-card雷同,通用css样式基本都可配置
  content:   #content字段,负责配置弹窗容器的样式
    - box-shadow: none  #关闭阴影
    - background: rgba(0,0,0,0) #透明背景
    - margin-top: "13px"   #弹窗整体上下位移
    - margin-left: "10px"  #弹窗整体左右位移
    - width: 30px
    - height: 56px
  button:   #button字段,负责配置按钮的样式
    - height: 70px  #按钮高度
    - width: 70px   #按钮宽度
    - background: blue
    - border-radius: 20px   #按钮圆角
  name:   #name字段,负责文本内容样式控制
    - font-weight: bold   #文本加粗
    - font-size: 14px   #字体大小
    - color: rgb(85,110,127)  #字体颜色
    - letter-spacing: 1px  #字符间距
    - margin-left: 2px  #整体左右位移
  icon:  #icon字段,负责图标样式控制
    - width: 50px   #图标高度
    - height: 50px  #图标宽度
    - color: white  #图标颜色
  grid:  #grid字段,负责图标与文本的布局形式
    - display: grid
    - grid-template-areas: |  #"i"代表icon,图标,“n”代表name文本,它们上下左右排布会对应到按钮布局上,比如这里icon位于name上方
        "i"
        "n"
    - grid-template-columns: auto  #列宽度
    - grid-template-rows: 45px 25px #行宽度
    - justify-items: start #水平对齐方式,start/center/end
  content:  #content弹窗内容
    card:  #可以在此后面衔接任意卡片代码,将会出现在弹窗容器中
      type: vertical-stack
      cards:
        - type: horizontal-stack
          cards:
            - type: sensor
              entity: sensor.watermetertest_yongliang
              name: 水表量
              icon: mdi:home-lightning-bolt-outline
            - type: sensor
              entity: sensor.jin_ri_yong_shui_liang
              name: 今日用水量
              icon: mdi:home-lightning-bolt-outline
              detail: 1
            - type: sensor
              entity: sensor.zuo_ri_yong_shui_liang
              name: 昨日用水量
              icon: mdi:home-lightning-bolt-outline
              # unit: 元
              detail: 1


回复

使用道具 举报

mhbj 手机认证

5

主题

43

回帖

279

积分

中级会员

积分
279
金钱
231
HASS币
0
发表于 2025-9-27 20:53:20 | 显示全部楼层
学习以下,这个不错
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian ( 晋ICP备17001384号-1 )

GMT+8, 2025-11-19 23:33 , Processed in 0.072715 second(s), 11 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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