找回密码
 立即注册

微信扫码登录

搜索
楼主: DDDear

[UI界面] Mattias UI 动态天气卡片

[复制链接]

2

主题

13

回帖

91

积分

论坛UI达人

积分
91
金钱
76
HASS币
0
发表于 前天 09:11 | 显示全部楼层
DDDear 发表于 2025-8-11 08:11
widget_weather在base/button_card_templates.yaml的文件里

谢谢大佬 我去试一试 不过我参照您的代码纯用button card写了一个 目前实现了约70%左右功能 还在调试
回复

使用道具 举报

16

主题

727

回帖

3919

积分

论坛元老

HomeAssistant

积分
3919
金钱
3171
HASS币
30
 楼主| 发表于 前天 10:40 | 显示全部楼层
DDDear 发表于 2025-8-11 08:11
widget_weather在base/button_card_templates.yaml的文件里

抱歉我看错了,widget_weather就在帖子正文的代码里,需要用button_card_templates的方式去调用
回复

使用道具 举报

16

主题

727

回帖

3919

积分

论坛元老

HomeAssistant

积分
3919
金钱
3171
HASS币
30
 楼主| 发表于 前天 10:41 | 显示全部楼层
rose骑士 发表于 2025-8-11 09:11
谢谢大佬 我去试一试 不过我参照您的代码纯用button card写了一个 目前实现了约70%左右功能 还在调试 ...

抱歉我看错了,widget_weather就在帖子正文的代码里,需要用button_card_templates的方式去调用
回复

使用道具 举报

2

主题

13

回帖

91

积分

论坛UI达人

积分
91
金钱
76
HASS币
0
发表于 昨天 08:58 | 显示全部楼层
DDDear 发表于 2025-8-11 10:41
抱歉我看错了,widget_weather就在帖子正文的代码里,需要用button_card_templates的方式去调用
...

大佬 现在显示 Button-card template 'base' is missing!
回复

使用道具 举报

16

主题

727

回帖

3919

积分

论坛元老

HomeAssistant

积分
3919
金钱
3171
HASS币
30
 楼主| 发表于 昨天 09:34 | 显示全部楼层
本帖最后由 DDDear 于 2025-8-12 09:36 编辑
rose骑士 发表于 2025-8-12 08:58
大佬 现在显示 Button-card template 'base' is missing!
  #################################################
  #                                               #
  #                     BASE                      #
  #                                               #
  #################################################

  base:
    variables:
      state: >
        [[[ return entity === undefined || entity.state; ]]]
      timeout: >
        [[[ return entity === undefined || Date.now() - Date.parse(entity.last_changed); ]]]
      light_color: >
        [[[ return entity === undefined || entity.state === 'unavailable' ? 'var(--state-icon-color)' : 'var(--button-card-light-color-no-temperature)'; ]]]
      circle_input: >
        [[[ return entity === undefined || Math.round(entity.attributes.brightness / 2.54); ]]]

    aspect_ratio: 1/1
    show_state: true
    show_icon: false
    state_display: >
      [[[ if (variables.state === true) return '未知'; ]]]
    tap_action:
      ui_sound_tablet: |
        [[[
          const screensaver = states['switch.rong_yao_chang_wan_ping_ban_2_screensaver'] === undefined || 
            states['switch.rong_yao_chang_wan_ping_ban_2_screensaver'].state;

          if (variables.state === 'off' && screensaver === 'off') {
            hass.callService('media_player', 'play_media', {
              entity_id: 'media_player.ci_wo_chromecast',
              media_content_id: '/local/mattias/sound/on.m4a',
              media_content_type: 'music'
            });
          }
          if (variables.state === 'on' && screensaver === 'off') {
            hass.callService('media_player', 'play_media', {
              entity_id: 'media_player.ci_wo_chromecast',
              media_content_id: '/local/mattias/sound/off.m4a',
              media_content_type: 'music'
            });
          }
        ]]]
      animation_card: |
        [[[
          const animation_speed_ms = 900;
          const animation = `card_bounce ${animation_speed_ms}ms cubic-bezier(0.22, 1, 0.36, 1)`;
          this.shadowRoot.getElementById("card").style.animation = animation;
          window.setTimeout(() => {
            this.shadowRoot.getElementById("card").style.animation = "none";
          }, animation_speed_ms)
        ]]]
      card_bounce: |
        [[[
          // add animation
          if (this.getElementsByTagName("style").length === 0) {

              // phone condition
              let mq = window.matchMedia('(max-width: 800px)').matches;

              let style = document.createElement('style');

              style.innerHTML = `
                  @keyframes card_bounce {
                      0%   { transform: scale(1); }
                      10%  { transform: scale(${ mq ? '0.92' : '0.94' }); }
                      25%  { transform: scale(1); }
                      30%  { transform: scale(${ mq ? '0.96' : '0.98' }); }
                      100% { transform: scale(1); }
                  }
              `;

              this.appendChild(style);
          }

          // duration
          let duration = 800;

          // animate
          this.style.animation = `card_bounce ${duration}ms cubic-bezier(0.22, 1, 0.36, 1)`;

          // reset
          window.setTimeout(() => { this.style.animation = "none"; }, duration + 100)
        ]]]
      action: toggle
      haptic: medium
    double_tap_action:
      haptic: success
    hold_action:
      action: more-info     
    styles:
      grid:
        - grid-template-areas: |
            "icon  circle"
            "n     n"
            "s     s"
        - grid-template-columns: repeat(2, 1fr)
        - grid-template-rows: auto repeat(2, min-content)
        - gap: 2%
        - align-items: start
      name:
        - justify-self: start
        - line-height: 115%
      state:
        - justify-self: start
        - line-height: 115%
      card:
        - font-family: Sf Display
        - border-radius: 30
        - -webkit-tap-highlight-color: rgba(0,0,0,0)
        - transition: none
        - padding: 10%
        - --mdc-ripple-color: >
            [[[
              return (variables.state === 'on' || variables.state === 'open' || variables.state === 'idle' ||  variables.state === 'heat' || variables.state === 'auto' || variables.state === 'dry'|| variables.state === 'fan_only' || variables.state === 'cool') ?
                'rgb(0, 0, 0)' :
                'rgba(255, 255, 255, 0.3)';
            ]]]
        - color: >
            [[[
              return (variables.state === 'on' || variables.state === 'open' || variables.state === 'idle' || variables.state === 'heat' || variables.state === 'auto' || variables.state === 'dry'|| variables.state === 'fan_only' || variables.state === 'cool') ?
                'rgba(0, 0, 0, 0.6)' :
                'rgba(255, 255, 255, 0.3)';
            ]]]
        - background-color: >
            [[[
              return (variables.state === 'on' || variables.state === 'open' || variables.state === 'idle' || variables.state === 'heat' || variables.state === 'auto' || variables.state === 'dry'|| variables.state === 'fan_only' || variables.state === 'cool') ?
                'rgba(255, 255, 255, 0.8)' :
                'rgba(115, 115, 115, 0.2)';
            ]]]
    extra_styles: |
      #name, #state {
        font-size: 1.34vw;
        letter-spacing: 0.05vw;
      }
      /* portrait */
      @media screen and (max-width: 800px) {
        #name, #state {
          font-size: 2vw;
          letter-spacing: 0.05vw;
        }
      }
      /* phone */
      @media screen and (max-width: 800px) {
        #name, #state {
          font-size: 3.1vw;
          letter-spacing: 0.12vw;
        }
      }
      @keyframes card_bounce {
        0% {
          transform: scale(1);
        }
        15% {
          transform: scale(0.9);
        }
        25% {
          transform: scale(1);
        }
        30% {
          transform: scale(0.98);
        }
        100% {
          transform: scale(1);
        }
      }
回复

使用道具 举报

2

主题

13

回帖

91

积分

论坛UI达人

积分
91
金钱
76
HASS币
0
发表于 昨天 12:18 | 显示全部楼层

谢大佬,不过我纯用button card手搓出来了 但有点问题 就是很明显的有卡片堆叠的痕迹 后面我会在论坛里把我的手搓代码写出来 但明显的卡片堆叠痕迹 这个 我也想问论坛里的大佬如何解决 非常感谢大佬的解答
回复

使用道具 举报

16

主题

727

回帖

3919

积分

论坛元老

HomeAssistant

积分
3919
金钱
3171
HASS币
30
 楼主| 发表于 昨天 17:15 | 显示全部楼层
rose骑士 发表于 2025-8-12 12:18
谢大佬,不过我纯用button card手搓出来了 但有点问题 就是很明显的有卡片堆叠的痕迹 后面我会在论坛里把 ...

我也是照葫芦画瓢改的,有问题可以先问问AI
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-8-13 16:38 , Processed in 0.416681 second(s), 4 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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