Joshua Rutschmann пре 6 година
родитељ
комит
1e5c6a99da
3 измењених фајлова са 17 додато и 209 уклоњено
  1. 1
    1
      config/configuration.yaml
  2. 16
    7
      config/ui-lovelace.yaml
  3. 0
    201
      config/www/gauge-card.js

+ 1
- 1
config/configuration.yaml Прегледај датотеку

@@ -16,7 +16,7 @@ zone:
16 16
   - name: Work
17 17
     latitude: 47.6626744
18 18
     longitude: 9.1721211
19
-    icon: mdi:work
19
+    icon: mdi:briefcase
20 20
 # Enables the frontend
21 21
 frontend:
22 22
   themes: !include midnight.yaml

+ 16
- 7
config/ui-lovelace.yaml Прегледај датотеку

@@ -1,9 +1,5 @@
1 1
 title: Tannenhof
2 2
 
3
-resources:
4
-  - url: /local/gauge-card.js?v=1
5
-    type: js
6
-
7 3
 views:
8 4
     # View tab title.
9 5
   - title: Josh's Room
@@ -13,7 +9,6 @@ views:
13 9
     background: radial-gradient(crimson, skyblue)
14 10
     # Each view can have a different theme applied. Theme should be defined in the frontend.
15 11
     theme: dark-mode
16
-
17 12
     cards:
18 13
       - id: 698b0d61c8d64ee9a0b762080adbd009  # Automatically created id
19 14
         type: weather-forecast
@@ -27,16 +22,30 @@ views:
27 22
           - group.lights
28 23
           - cover.blinds
29 24
           - media_player.spotify
25
+          - device_tracker.david 
26
+          - device_tracker.david 
30 27
         # The markdown card will render markdown text.
31
-      - type: custom:gauge-card
28
+      - type: light
29
+        entity: light.led_strip
30
+      - type: gauge
32 31
         title: Temperature
33 32
         entity: sensor.dht_sensor_temperature
34 33
         min: -20
35 34
         max: 35
36
-      - type: custom:gauge-card
35
+      - type: sensor
36
+        entity: sensor.dht_sensor_temperature
37
+        name: Temperature
38
+        height: 75
39
+        line_color: "#3498db"
40
+      - type: gauge
37 41
         title: Printer Hotend
38 42
         entity: sensor.octoprint_actual_tool0_temp
39 43
         severity:
40 44
           red: 50
41 45
           green: 0
42 46
           amber: 40
47
+      - type: iframe
48
+        url: https://www.rainviewer.com/map.html
49
+        aspect_ratio: 75%
50
+
51
+

+ 0
- 201
config/www/gauge-card.js Прегледај датотеку

@@ -1,201 +0,0 @@
1
-class GaugeCard extends HTMLElement {
2
-  constructor() {
3
-    super();
4
-    this.attachShadow({ mode: 'open' });
5
-  }
6
-  setConfig(config) {
7
-    if (!config.entity) {
8
-      throw new Error('Please define an entity');
9
-    }
10
-
11
-    const root = this.shadowRoot;
12
-    if (root.lastChild) root.removeChild(root.lastChild);
13
-
14
-    const cardConfig = Object.assign({}, config);
15
-    if (!cardConfig.scale) cardConfig.scale = "50px";
16
-    if (!cardConfig.min) cardConfig.min = 0;
17
-    if (!cardConfig.max) cardConfig.max = 100;
18
-
19
-    const entityParts = this._splitEntityAndAttribute(cardConfig.entity);
20
-    cardConfig.entity = entityParts.entity;
21
-    if (entityParts.attribute) cardConfig.attribute = entityParts.attribute;
22
-
23
-    const card = document.createElement('ha-card');
24
-    const shadow = card.attachShadow({ mode: 'open' });
25
-    const content = document.createElement('div');
26
-    const style = document.createElement('style');
27
-    style.textContent = `
28
-      ha-card {
29
-        --base-unit: ${cardConfig.scale};
30
-        height: calc(var(--base-unit)*3);
31
-        position: relative;
32
-      }
33
-      .container{
34
-        width: calc(var(--base-unit) * 4);
35
-        height: calc(var(--base-unit) * 2);
36
-        position: absolute;
37
-        top: calc(var(--base-unit)*1.5);
38
-        left: 50%;
39
-        overflow: hidden;
40
-        text-align: center;
41
-        transform: translate(-50%, -50%);
42
-      }
43
-      .gauge-a{
44
-        z-index: 1;
45
-        position: absolute;
46
-        background-color: var(--primary-background-color);
47
-        width: calc(var(--base-unit) * 4);
48
-        height: calc(var(--base-unit) * 2);
49
-        top: 0%;
50
-        border-radius:calc(var(--base-unit) * 2.5) calc(var(--base-unit) * 2.5) 0px 0px ;
51
-      }
52
-      .gauge-b{
53
-        z-index: 3;
54
-        position: absolute;
55
-        background-color: var(--paper-card-background-color);
56
-        width: calc(var(--base-unit) * 2.5);
57
-        height: calc(var(--base-unit) * 1.25);
58
-        top: calc(var(--base-unit) * 0.75);
59
-        margin-left: calc(var(--base-unit) * 0.75);
60
-        margin-right: auto;
61
-        border-radius: calc(var(--base-unit) * 2.5) calc(var(--base-unit) * 2.5) 0px 0px ;
62
-      }
63
-      .gauge-c{
64
-        z-index: 2;
65
-        position: absolute;
66
-        background-color: var(--label-badge-yellow);
67
-        width: calc(var(--base-unit) * 4);
68
-        height: calc(var(--base-unit) * 2);
69
-        top: calc(var(--base-unit) * 2);
70
-        margin-left: auto;
71
-        margin-right: auto;
72
-        border-radius: 0px 0px calc(var(--base-unit) * 2) calc(var(--base-unit) * 2) ;
73
-        transform-origin: center top;
74
-        transition: all 1.3s ease-in-out;
75
-      }
76
-      .gauge-data{
77
-        z-index: 4;
78
-        color: var(--primary-text-color);
79
-        line-height: calc(var(--base-unit) * 0.3);
80
-        position: absolute;
81
-        width: calc(var(--base-unit) * 4);
82
-        height: calc(var(--base-unit) * 2.1);
83
-        top: calc(var(--base-unit) * 1.2);
84
-        margin-left: auto;
85
-        margin-right: auto;
86
-        transition: all 1s ease-out;
87
-      }
88
-      .gauge-data #percent{
89
-        font-size: calc(var(--base-unit) * 0.55);
90
-      }
91
-      .gauge-data #title{
92
-        padding-top: calc(var(--base-unit) * 0.15);
93
-        font-size: calc(var(--base-unit) * 0.30);
94
-      }
95
-    `;
96
-    content.innerHTML = `
97
-      <div class="container">
98
-        <div class="gauge-a"></div>
99
-        <div class="gauge-b"></div>
100
-        <div class="gauge-c" id="gauge"></div>
101
-        <div class="gauge-data"><div id="percent"></div><div id="title"></div></div>
102
-      </div>
103
-    `;
104
-    card.appendChild(content);
105
-    card.appendChild(style);
106
-    card.addEventListener('click', event => {
107
-      this._fire('hass-more-info', { entityId: cardConfig.entity });
108
-    });
109
-    root.appendChild(card);
110
-    this._config = cardConfig;
111
-  }
112
-
113
-  _splitEntityAndAttribute(entity) {
114
-      let parts = entity.split('.');
115
-      if (parts.length < 3) {
116
-          return { entity: entity };
117
-      }
118
-
119
-      return { attribute: parts.pop(), entity: parts.join('.') };
120
-  }
121
-
122
-  _fire(type, detail, options) {
123
-    const node = this.shadowRoot;
124
-    options = options || {};
125
-    detail = (detail === null || detail === undefined) ? {} : detail;
126
-    const event = new Event(type, {
127
-      bubbles: options.bubbles === undefined ? true : options.bubbles,
128
-      cancelable: Boolean(options.cancelable),
129
-      composed: options.composed === undefined ? true : options.composed
130
-    });
131
-    event.detail = detail;
132
-    node.dispatchEvent(event);
133
-    return event;
134
-  }
135
-
136
-  _translateTurn(value, config) {
137
-    return 5 * (value - config.min) / (config.max - config.min)
138
-  }
139
-
140
-  _computeSeverity(stateValue, sections) {
141
-    let numberValue = Number(stateValue);
142
-    const severityMap = {
143
-      red: "var(--label-badge-red)",
144
-      green: "var(--label-badge-green)",
145
-      amber: "var(--label-badge-yellow)",
146
-      normal: "var(--label-badge-blue)",
147
-    }
148
-    if (!sections) return severityMap["normal"];
149
-    let sortable = [];
150
-    for (let severity in sections) {
151
-      sortable.push([severity, sections[severity]]);
152
-    }
153
-    sortable.sort((a, b) => { return a[1] - b[1] });
154
-
155
-    if (numberValue >= sortable[0][1] && numberValue < sortable[1][1]) {
156
-      return severityMap[sortable[0][0]]
157
-    }
158
-    if (numberValue >= sortable[1][1] && numberValue < sortable[2][1]) {
159
-      return severityMap[sortable[1][0]]
160
-    }
161
-    if (numberValue >= sortable[2][1]) {
162
-      return severityMap[sortable[2][0]]
163
-    }
164
-    return severityMap["normal"];
165
-  }
166
-
167
-  _getEntityStateValue(entity, attribute) {
168
-    if (!attribute) {
169
-      return entity.state;
170
-    }
171
-
172
-    return entity.attributes[attribute];
173
-  }
174
-
175
-  set hass(hass) {
176
-    const config = this._config;
177
-    const entityState = this._getEntityStateValue(hass.states[config.entity], config.attribute);
178
-    let measurement = "";
179
-    if (config.measurement == null)
180
-      measurement = hass.states[config.entity].attributes.unit_of_measurement;
181
-    else
182
-      measurement = config.measurement;
183
-
184
-    const root = this.shadowRoot;
185
-    if (entityState !== this._entityState) {
186
-      root.getElementById("percent").textContent = `${entityState} ${measurement}`;
187
-      root.getElementById("title").textContent = config.title;
188
-      const turn = this._translateTurn(entityState, config) / 10;
189
-      root.getElementById("gauge").style.transform = `rotate(${turn}turn)`;
190
-      root.getElementById("gauge").style.backgroundColor = this._computeSeverity(entityState, config.severity);
191
-      this._entityState = entityState;
192
-    }
193
-    root.lastChild.hass = hass;
194
-  }
195
-
196
-  getCardSize() {
197
-    return 1;
198
-  }
199
-}
200
-
201
-customElements.define('gauge-card', GaugeCard);

Loading…
Откажи
Сачувај