fablav

Simple light with slider

Feb 5th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.75 KB | Software | 0 0
  1. type: custom:button-card
  2. entity: light.hue_color_lamp_2
  3. tap_action:
  4.   action: more-info
  5. show_icon: false
  6. name: Light 1
  7. custom_fields:
  8.   slider:
  9.     card:
  10.       type: custom:my-slider-v2
  11.       entity: light.hue_color_lamp_2
  12.       colorMode: brightness
  13.       styles:
  14.         container:
  15.           - border-radius: 100px
  16.           - overflow: visible
  17.           - background: none
  18.         card:
  19.           - height: 40px
  20.           - padding: 0 20px
  21.           - background: |
  22.              [[[
  23.                 if (
  24.                   entity.state === 'on' &&
  25.                   entity.attributes.rgb_color &&
  26.                   entity.attributes.brightness > 0
  27.                 ) {
  28.                   let [r, g, b] = entity.attributes.rgb_color;
  29.                   // Calculate a dynamic gradient based on the light's RGB colour
  30.                   let darkR = Math.min(255, Math.floor(r * 0.6));
  31.                   let darkG = Math.min(255, Math.floor(g * 0.6));
  32.                   let darkB = Math.min(255, Math.floor(b * 0.6));
  33.                   let lightR = Math.min(255, Math.floor(r * 1.3));
  34.                   let lightG = Math.min(255, Math.floor(g * 1.3));
  35.                   let lightB = Math.min(255, Math.floor(b * 1.3));
  36.                   return `linear-gradient(to right, rgb(${darkR}, ${darkG}, ${darkB}), rgb(${lightR}, ${lightG}, ${lightB}))`;
  37.                 }
  38.                 // Fallback plain colour when off
  39.                 return "#4e4457";
  40.               ]]]
  41.           - transition: background 0.5s ease-in-out
  42.         track:
  43.           - overflow: visible
  44.           - background: none
  45.         progress:
  46.           - background: none
  47.         thumb:
  48.           - background: |
  49.              [[[
  50.                 if (
  51.                   entity.state === 'on' &&
  52.                   entity.attributes.rgb_color &&
  53.                   entity.attributes.brightness > 0
  54.                 ) {
  55.                   let [r, g, b] = entity.attributes.rgb_color;
  56.                   // Darken the base colour significantly for the thumb
  57.                   let dr = Math.floor(r * 0.3);
  58.                   let dg = Math.floor(g * 0.3);
  59.                   let db = Math.floor(b * 0.3);
  60.                   return `rgb(${dr}, ${dg}, ${db})`;
  61.                 }
  62.                 // Fallback thumb colour when off
  63.                 return "#393646";
  64.               ]]]
  65.           - top: 2px
  66.           - right: "-18px"
  67.           - height: 36px
  68.           - width: 36px
  69.           - border-radius: 100px
  70. styles:
  71.   grid:
  72.     - grid-template-areas: "\"n\" \"slider\""
  73.     - grid-template-columns: 1fr
  74.     - grid-template-rows: 1fr min-content min-content
  75.   card:
  76.     - background: |
  77.        [[[
  78.           if (
  79.             entity.state === 'on' &&
  80.             entity.attributes.rgb_color &&
  81.             entity.attributes.brightness > 0
  82.           ) {
  83.             let [r, g, b] = entity.attributes.rgb_color;
  84.             // Calculate a dynamic overall card background gradient
  85.             let darkR = Math.min(255, Math.floor(r * 0.4));
  86.             let darkG = Math.min(255, Math.floor(g * 0.4));
  87.             let darkB = Math.min(255, Math.floor(b * 0.4));
  88.             let darkerR = Math.min(255, Math.floor(r * 0.5));
  89.             let darkerG = Math.min(255, Math.floor(g * 0.5));
  90.             let darkerB = Math.min(255, Math.floor(b * 0.5));
  91.             return `linear-gradient(to right, rgb(${darkR}, ${darkG}, ${darkB}), rgb(${darkerR}, ${darkerG}, ${darkerB}))`;
  92.           }
  93.           // Fallback plain colour when off
  94.           return "#393646";
  95.         ]]]
  96.     - padding: 16px
  97.     - "--mdc-ripple-press-opacity": 0
  98.     - transition: background 0.5s ease-in-out
  99.   name:
  100.     - justify-self: start
  101.     - font-size: 14px
  102.     - margin: 4px 0 12px 0
  103.     - color: var(--contrast20)
  104.  
Tags: ha
Add Comment
Please, Sign In to add comment