Advertisement
gednet

Bar custom card

Dec 30th, 2024
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.99 KB | Housing | 0 0
  1. type: custom:button-card
  2. entity: sensor.stan_peletu_zasobnik
  3. show_icon: true
  4. show_name: true
  5. show_label: false
  6. show_state: true
  7. state_display: |
  8.  [[[
  9.     return Math.round(Number(entity.state)) + ' kg';
  10.   ]]]
  11. name: w zasobniku
  12. custom_fields:
  13.   tytul: w magazynie
  14.   magazyn: |
  15.    [[[
  16.       var stan_mag = states["input_number.stan_peletu_magazyn_szt"].state;
  17.       return Math.round(Number(stan_mag)) + ' worków'
  18.     ]]]
  19.   zasobnik: |
  20.    [[[
  21.       var kolor = "#1C1C1C00";
  22.       var stan = states["input_number.test_procenty"].state;
  23.       var ikona
  24.       if (stan < 25) {var ikona = '<ha-icon icon="mdi:alert" style="width: 25px; height: 25px; color:#CC0000;"></ha-icon>'} else {var ikona = helpers.formatDateShort(states["script.kotlownia_napelnianie_zbiornika"].attributes.last_triggered)}
  25.       return ikona
  26.     ]]]
  27.   bar: |
  28.    [[[
  29.       var kolor = "gray";
  30.       var state = states["input_number.test_procenty"].state;
  31.       var r = 0; var g = 0; var b = 0;
  32.       if (state < 50 ) {
  33.         var r = 255;
  34.         var g = parseInt(5.1 * state);
  35.       } else {  
  36.         var g = 255;
  37.         var r = parseInt(510 - 5.10 * state);
  38.       }
  39.       var h = r * 0x10000 + g * 0x100 + b * 0x1;
  40.       var kolor = '#' + ('000000' + h.toString(16)).slice(-6);
  41.       return `
  42.       <div>
  43.       <div style="background:${kolor}; height: 14px; width:${state}%">
  44.       </div>
  45.       </div>
  46.       `
  47.     ]]]
  48. variables:
  49.   var_color: |-
  50.     [[[
  51.       var percentage = states["input_number.test_procenty"].state;
  52.       var r = 0; var g = 0; var b = 0;
  53.       if (percentage < 50 ) {
  54.         var r = 255;
  55.         var g = parseInt(5.1 * percentage);
  56.       } else {  
  57.         var g = 255;
  58.         var r = parseInt(510 - 5.10 * percentage);
  59.       }
  60.       var h = r * 0x10000 + g * 0x100 + b * 0x1;
  61.       var h = r * 0x10000 + g * 0x100 + b * 0x1;
  62.       return '#' + ('000000' + h.toString(16)).slice(-6);
  63.     ]]]
  64. styles:
  65.   custom_fields:
  66.     tytul:
  67.       - position: absolute
  68.       - left: 45%
  69.       - top: 10%
  70.       - color: white
  71.       - font-size: 12px
  72.     magazyn:
  73.       - position: absolute
  74.       - font-size: 14px
  75.       - left: 44%
  76.       - top: 32%
  77.     zasobnik:
  78.       - position: absolute
  79.       - color: white
  80.       - font-size: 14px
  81.       - left: 80%
  82.       - top: 25%
  83.       - animation: >-
  84.           [[[ if (states["sensor.procent_zasobnika_peletu"].state < 20) return
  85.           "blink 1.5s ease infinite"; ]]]
  86.     bar:
  87.       - position: absolute
  88.       - width: 75%
  89.       - height: 12%
  90.       - top: 75%
  91.       - left: 20%
  92.       - background: "#606060"
  93.   name:
  94.     - position: absolute
  95.     - left: 20%
  96.     - top: 10%
  97.     - color: white
  98.     - font-size: 12px
  99.   state:
  100.     - position: absolute
  101.     - left: 22%
  102.     - top: 32%
  103.     - color: white
  104.     - font-size: 15px
  105.   icon:
  106.     - left: 2%
  107.     - color: "[[[ return variables.var_color ]]]"
  108.   card:
  109.     - background-color: "#00000060"
  110.     - text-shadow: 0px 0px 5px black
  111. icon: mdi:fuel
  112. size: 16%
  113. aspect_ratio: 7
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement