xyboox

Power Icon

Jan 28th, 2021 (edited)
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 5.40 KB | None | 0 0
  1. base:
  2.   aspect_ratio: 1/1
  3.   show_state: true
  4.   show_icon: false
  5.   state:
  6.     - value: 'on'
  7.       styles:
  8.         card: [background-color: 'rgba(255, 255, 255, 0.8)']
  9.         name: [color: 'rgba(0, 0, 0, 0.6)']
  10.         state: [color: 'rgba(0, 0, 0, 0.6)']
  11.   tap_action:
  12.     action: toggle
  13.     haptic: light
  14.   styles:
  15.     custom_fields:
  16.       circle:
  17.        [
  18.           top: 8.5%,
  19.           left: 52%,
  20.           width: 3.5vw,
  21.           position: absolute,
  22.           letter-spacing: 0.03vw,
  23.         ]
  24.  
  25. sensor:
  26.   template: ['base']
  27.   custom_fields:
  28.     circle: >
  29.      [[[
  30.         const power = states['sensor.' + entity.entity_id.split('.')[1] + '_power'].state;
  31.         if (power <= 10) {
  32.           return `
  33.             <svg viewBox="0 0 100 50">
  34.               <path fill="#f72403" d="M85.81,37H69.69V12.85H85.81m1.35-4H83.79v-4H71.7v4H68.34a2.68,2.68,0,0,0-2.68,2.68V42.41a2.69,2.69,0,0,0,2.68,2.68H87.16a2.68,2.68,0,0,0,2.68-2.68V11.5A2.69,2.69,0,0,0,87.16,8.82Z" />
  35.               <text x="37%" y="75%" fill="#8d8e90" font-size="16" text-anchor="middle" alignment-baseline="middle">${power}%</text>
  36.             </svg>
  37.           `;
  38.         }
  39.         if (power <= 20) {
  40.           return `
  41.             <svg viewBox="0 0 100 50">
  42.               <path fill="#a13f2a" d="M85.75,35h-16V13h16m1.34-4H83.75V5h-12V9H68.41a2.66,2.66,0,0,0-2.66,2.66V42.34A2.67,2.67,0,0,0,68.41,45H87.09a2.66,2.66,0,0,0,2.66-2.66V11.66A2.67,2.67,0,0,0,87.09,9Z" />
  43.               <text x="37%" y="75%" fill="#8d8e90" font-size="16" text-anchor="middle" alignment-baseline="middle">${power}%</text>
  44.             </svg>
  45.           `;
  46.         }
  47.         if (power <= 30) {
  48.           return `
  49.             <svg viewBox="0 0 100 50">
  50.               <path fill="#f96602" d="M85.74,31H69.61V12.84H85.74m1.35-4H83.72v-4H71.63v4H68.26a2.68,2.68,0,0,0-2.68,2.68V42.4a2.69,2.69,0,0,0,2.68,2.68H87.09a2.68,2.68,0,0,0,2.68-2.68V11.49A2.69,2.69,0,0,0,87.09,8.81Z" />
  51.               <text x="37%" y="75%" fill="#8d8e90" font-size="16" text-anchor="middle" alignment-baseline="middle">${power}%</text>
  52.             </svg>
  53.           `;
  54.         }
  55.         if (power <= 40) {
  56.           return `
  57.             <svg viewBox="0 0 100 50">
  58.               <path fill="#fa9801" d="M85.86,29H69.71V12.85H85.86m1.36-4H83.84v-4H71.73v4H68.35a2.69,2.69,0,0,0-2.68,2.69v31a2.7,2.7,0,0,0,2.68,2.69H87.22a2.69,2.69,0,0,0,2.68-2.69v-31A2.7,2.7,0,0,0,87.22,8.81Z" />
  59.               <text x="37%" y="75%" fill="#8d8e90" font-size="16" text-anchor="middle" alignment-baseline="middle">${power}%</text>
  60.             </svg>
  61.           `;
  62.         }
  63.         if (power <= 50) {
  64.           return `
  65.             <svg viewBox="0 0 100 50">
  66.               <path fill="#fccc00" d="M85.78,27H69.62V12.85H85.78m1.35-4H83.76v-4H71.64v4H68.27a2.7,2.7,0,0,0-2.69,2.69v31a2.71,2.71,0,0,0,2.69,2.69H87.13a2.69,2.69,0,0,0,2.69-2.69v-31A2.7,2.7,0,0,0,87.13,8.81Z" />
  67.               <text x="37%" y="75%" fill="#8d8e90" font-size="16" text-anchor="middle" alignment-baseline="middle">${power}%</text>
  68.             </svg>
  69.           `;
  70.         }
  71.         if (power <= 60) {
  72.           return `
  73.             <svg viewBox="0 0 100 50">
  74.               <path fill="#fffb00" d="M85.7,25.05h-16V13h16M87,9H83.69V5h-12V9H68.33a2.66,2.66,0,0,0-2.66,2.67V42.42a2.67,2.67,0,0,0,2.66,2.66H87a2.66,2.66,0,0,0,2.66-2.66V11.7A2.67,2.67,0,0,0,87,9Z" />
  75.               <text x="37%" y="75%" fill="#8d8e90" font-size="16" text-anchor="middle" alignment-baseline="middle">${power}%</text>
  76.             </svg>
  77.           `;
  78.         }
  79.         if (power <= 70) {
  80.           return `
  81.             <svg viewBox="0 0 100 50">
  82.               <path fill="#ccfa00" d="M85.82,20.9H69.7V12.84H85.82m1.35-4H83.81v-4H71.71v4H68.35a2.68,2.68,0,0,0-2.68,2.68V42.4a2.69,2.69,0,0,0,2.68,2.68H87.17a2.68,2.68,0,0,0,2.68-2.68V11.49A2.69,2.69,0,0,0,87.17,8.81Z" />
  83.               <text x="37%" y="75%" fill="#8d8e90" font-size="16" text-anchor="middle" alignment-baseline="middle">${power}%</text>
  84.             </svg>
  85.           `;
  86.         }
  87.         if (power <= 80) {
  88.           return `
  89.             <svg viewBox="0 0 100 50">
  90.               <path fill="#99fa00" d="M85.74,18.88H69.61v-6H85.74m1.35-4H83.72v-4H71.63v4H68.26a2.68,2.68,0,0,0-2.68,2.68V42.4a2.69,2.69,0,0,0,2.68,2.68H87.09a2.68,2.68,0,0,0,2.68-2.68V11.49A2.69,2.69,0,0,0,87.09,8.81Z" />
  91.               <text x="37%" y="75%" fill="#8d8e90" font-size="16" text-anchor="middle" alignment-baseline="middle">${power}%</text>
  92.             </svg>
  93.           `;
  94.         }
  95.         if (power <= 90) {
  96.           return `
  97.             <svg viewBox="0 0 100 50">
  98.               <path fill="#65f902" d="M85.82,16.87H69.7v-4H85.82m1.35-4H83.81v-4H71.71v4H68.35a2.68,2.68,0,0,0-2.68,2.68V42.4a2.69,2.69,0,0,0,2.68,2.68H87.17a2.68,2.68,0,0,0,2.68-2.68V11.49A2.69,2.69,0,0,0,87.17,8.81Z" />
  99.               <text x="37%" y="75%" fill="#8d8e90" font-size="16" text-anchor="middle" alignment-baseline="middle">${power}%</text>
  100.             </svg>
  101.           `;
  102.         }
  103.         if (power <= 100) {
  104.           return `
  105.             <svg viewBox="0 0 100 50">
  106.               <path fill="#4af900" d="M87.09,8.81H83.72v-4H71.63v4H68.26a2.68,2.68,0,0,0-2.68,2.68V42.4a2.69,2.69,0,0,0,2.68,2.68H87.09a2.68,2.68,0,0,0,2.68-2.68V11.49A2.69,2.69,0,0,0,87.09,8.81Z" />
  107.               <text x="37%" y="75%" fill="#8d8e90" font-size="16" text-anchor="middle" alignment-baseline="middle">${power}%</text>
  108.             </svg>
  109.           `;
  110.         }
  111.       ]]]
  112.  
Add Comment
Please, Sign In to add comment