Advertisement
Guest User

advanced_auto_entity_docker_card

a guest
Mar 1st, 2023
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 7.49 KB | None | 0 0
  1. type: custom:auto-entities
  2. card:
  3.   type: grid
  4. card_param: cards
  5. filter:
  6.   include:
  7.     - custom_fields:
  8.         up: |
  9.          [[[
  10.             return `<ha-icon
  11.               icon="mdi:power"
  12.               style="width: 20px; height: 20px; color: #B58E31;">
  13.               </ha-icon><span> Up <span style=color: var(--text-color-sensor);>${states['sensor.rpi_monitor_raspberrypi'].attributes.up_time} hours</span></span>`
  14.           ]]]
  15.         disk_free: |
  16.          [[[
  17.             return `<ha-icon
  18.               icon="mdi:harddisk"
  19.               style="width: 20px; height: 20px; color: #B58E31;">
  20.               </ha-icon><span> Disk free: <span style=color: var(--text-color-sensor);>${ ((1 - states['sensor.rpi_monitor_raspberrypi'].attributes.fs_free_prcnt/100) * states['sensor.rpi_monitor_raspberrypi'].attributes.fs_total_gb).toFixed(0) }  GB</span></span>`
  21.           ]]]
  22.         cpu: |
  23.          [[[
  24.             return `<ha-icon
  25.               icon="mdi:thermometer"
  26.               style="width: 20px; height: 20px; color: #B58E31;">
  27.               </ha-icon><span> CPU: <span style=color: var(--text-color-sensor);>${states['sensor.rpi_monitor_raspberrypi'].attributes.temp_cpu_c} &degC</span></span>`
  28.           ]]]
  29.         mem: |
  30.          [[[
  31.             return `<ha-icon
  32.               icon="mdi:memory"
  33.               style="width: 20px; height: 20px; color: #B58E31;">
  34.               </ha-icon><span> RAM free: <span style=color: var(--text-color-sensor);>${Math.round(states['sensor.rpi_monitor_raspberrypi'].attributes.memory.free_mb)} MB</span></span>`
  35.           ]]]
  36.       entity: sensor.rpi_monitor_raspberrypi
  37.       name: rpi4
  38.       show_entity_picture: true
  39.       show_state: false
  40.       size: 40px
  41.       entity_picture: /local/images/raspberry_logo.png
  42.       styles:
  43.         custom_fields:
  44.           cpu:
  45.             - padding-bottom: 0px
  46.             - align-self: start
  47.             - padding-left: 2px
  48.             - font-size: 12px
  49.             - justify-self: start
  50.           up:
  51.             - padding-bottom: 0px
  52.             - align-self: start
  53.             - padding-left: 2px
  54.             - font-size: 12px
  55.             - justify-self: start
  56.           mem:
  57.             - padding-bottom: 0px
  58.             - align-self: start
  59.             - padding-left: 2px
  60.             - font-size: 12px
  61.             - justify-self: start
  62.           disk_free:
  63.             - padding-bottom: 0px
  64.             - align-self: start
  65.             - padding-left: 2px
  66.             - font-size: 12px
  67.             - justify-self: start
  68.         grid:
  69.           - grid-template-areas: '"i i" "n n" "up up" "disk_free disk_free" "cpu cpu" "mem mem"'
  70.           - grid-template-columns: 1fr 1fr
  71.           - grid-template-rows: 1fr min-content min-content min-content min-content
  72.         name:
  73.           - font-weight: bold
  74.           - font-size: 16px
  75.           - color: rgb(18,154,190)
  76.           - align-self: middle
  77.           - justify-self: middle
  78.           - padding-bottom: 4px
  79.         card:
  80.           - height: 165px
  81.       tap_action:
  82.         action: more-info
  83.       type: custom:button-card
  84.     - entity_id: sensor.docker_*_state
  85.       options:
  86.         custom_fields:
  87.           state: |
  88.            [[[
  89.               var state = `${states[entity.entity_id].state}`
  90.               var health = `${states[entity.entity_id.replace('state', 'health')].state}`
  91.               var state_to_show = state
  92.               if (state=='running' & health!='unknown') {var state_to_show=health}
  93.               return `<ha-icon
  94.                 icon="mdi:power"
  95.                 style="width: 20px; height: 20px; color: #B58E31;">
  96.                 </ha-icon><span> State: <span style=color: var(--text-color-sensor);>${state_to_show}</span></span>`
  97.             ]]]
  98.           up: |
  99.            [[[
  100.               return `<ha-icon
  101.                 icon="mdi:timer-check-outline"
  102.                 style="width: 20px; height: 20px; color: #B58E31;">
  103.                 </ha-icon><span> <span style=color: var(--text-color-sensor);>${states[entity.entity_id.replace('state', 'status')].state}</span></span>`
  104.             ]]]
  105.           cpu: |
  106.            [[[
  107.               return `<ha-icon
  108.                 icon="mdi:chip"
  109.                 style="width: 20px; height: 20px; color: #B58E31;">
  110.                 </ha-icon><span> CPU: <span style=color: var(--text-color-sensor);>${states[entity.entity_id.replace('state', 'cpu')].state}%</span></span>`
  111.             ]]]
  112.           mem: |
  113.            [[[
  114.               return `<ha-icon
  115.                 icon="mdi:memory"
  116.                 style="width: 20px; height: 20px; color: #B58E31;">
  117.                 </ha-icon><span> RAM: <span style=color: var(--text-color-sensor);>${states[entity.entity_id.replace('state', 'memory')].state} MB</span></span>`
  118.             ]]]
  119.         show_entity_picture: true
  120.         show_state: false
  121.         name: >
  122.          [[[ return `${entity.attributes.friendly_name.replace(' State', '')}`
  123.           ]]]
  124.         size: 70px
  125.         state:
  126.           - entity_picture: /local/images/docker_2.png
  127.             styles:
  128.               entity_picture:
  129.                 - filter: |
  130.                    [[[
  131.                       var state = `${states[entity.entity_id].state}`
  132.                       var health = `${states[entity.entity_id.replace('state', 'health')].state}`
  133.                       if (health=='unhealthy') {return 'hue-rotate(195deg)'}
  134.                       if (state=='exited') {return 'grayscale(90%)'}
  135.                       else {return ''}
  136.                     ]]]
  137.             operator: default
  138.         styles:
  139.           custom_fields:
  140.             cpu:
  141.               - padding-bottom: 0px
  142.               - align-self: start
  143.               - padding-left: 2px
  144.               - font-size: 12px
  145.               - justify-self: start
  146.             up:
  147.               - padding-bottom: 0px
  148.               - align-self: start
  149.               - padding-left: 2px
  150.               - font-size: 12px
  151.               - justify-self: start
  152.             mem:
  153.               - padding-bottom: 0px
  154.               - align-self: start
  155.               - padding-left: 2px
  156.               - font-size: 12px
  157.               - justify-self: start
  158.             state:
  159.               - padding-bottom: 0px
  160.               - align-self: start
  161.               - padding-left: 2px
  162.               - font-size: 12px
  163.               - justify-self: start
  164.           grid:
  165.             - grid-template-areas: '"i i" "n n" "state state" "up up" "cpu cpu" "mem mem"'
  166.             - grid-template-columns: 1fr 1fr
  167.             - grid-template-rows: 1fr min-content min-content min-content min-content
  168.           name:
  169.             - font-weight: bold
  170.             - font-size: 16px
  171.             - color: |
  172.                [[[
  173.                   var state = `${states[entity.entity_id].state}`
  174.                   var health = `${states[entity.entity_id.replace('state', 'health')].state}`
  175.                   if (health=='unhealthy') {return 'rgb(178,116,52)'}
  176.                   if (state=='exited') {return 'rgb(117,126,130)'}
  177.                   else {return 'rgb(18,154,190)'}
  178.                 ]]]
  179.             - align-self: middle
  180.             - justify-self: middle
  181.             - padding-bottom: 4px
  182.           card:
  183.             - height: 165px
  184.         tap_action:
  185.           action: call-service
  186.           service: switch.toggle
  187.           service_data:
  188.             entity_id: >
  189.              [[[ return `${entity.entity_id.replace('sensor',
  190.               'switch').replace('_state', '')}` ]]]
  191.         type: custom:button-card
  192.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement