diff --git a/lovelace/templates/network_share.yaml b/lovelace/templates/network_share.yaml new file mode 100644 index 0000000..71aeb62 --- /dev/null +++ b/lovelace/templates/network_share.yaml @@ -0,0 +1,88 @@ +button_network_share: + variables: + warning_from_state: 80 + critical_from_state: 90 + bar_color_normal: '#69B34C' + bar_color_warning: '#FAB733' + bar_color_critical: '#FF4E11' + bar_color_background: '#E5E6E8' + show_icon: false + show_entity_picture: true + entity_picture: /local/share.png + name: > + [[[ + if (isNaN(entity.state)) { + return 'Unavailable'; + } + return `${entity.attributes.nameorig}`; + ]]] + styles: + grid: + - grid-template-areas: '"i n" + "i bar" + "i state"' + - grid-template-columns: 40px auto + - column-gap: 5px + - grid-template-rows: 1fr + card: + - color: '#000' + - font-size: 1em + - border-style: none + - --mdc-ripple-color: none + icon: + - width: 100% + img_cell: + - justify-content: start + name: + - justify-self: start + custom_fields: + bar: + - grid-area: bar + - font-size: 0.8em + - padding: 2px 0 + - width: 100% + state: + - grid-area: state + - justify-self: start + - color: '#888' + - font-size: 0.8em + custom_fields: + state: > + [[[ + if (isNaN(entity.state)) { + return 'Unknown'; + } + + function formatBytes(a,b=2){if(!+a)return"0 Bytes";const c=0>b?0:b,d=Math.floor(Math.log(a)/Math.log(1000));return`${parseFloat((a/Math.pow(1000,d)).toFixed(c))} ${["Bytes", "KB","MB","GB","TB","PB","EB","ZB","YB"][d]}`} + + var free = parseInt(entity.attributes.free); + var used = parseInt(entity.attributes.used); + + var spaceFree = Math.max(0, free * 1000); + var spaceTotal = (free+used) * 1000; + + return `${formatBytes(spaceFree, 0)} free of ${formatBytes(spaceTotal, 0)}`; + ]]] + bar: > + [[[ + var pctUsed = 100; + + if (!isNaN(entity.state)) { + var free = parseInt(entity.attributes.free); + var used = parseInt(entity.attributes.used); + + var spaceFree = Math.max(0, free * 1000); + var spaceTotal = (free+used) * 1000; + + pctUsed = Math.ceil(100-((spaceFree / spaceTotal) * 100)); + } + + let barColor = variables.bar_color_normal; + + barColor = (pctUsed > variables.warning_from_state ) ? variables.bar_color_warning : barColor; + barColor = (pctUsed > variables.critical_from_state ) ? variables.bar_color_critical : barColor; + + return `