|
1 | 1 | ---
|
2 | 2 | popup_weather_forecast:
|
| 3 | + variables: |
| 4 | + ulm_weather_popup_surpress_first_forecast: false |
3 | 5 | show_icon: false
|
4 | 6 | show_name: false
|
5 | 7 | show_label: false
|
@@ -97,37 +99,72 @@ popup_weather_forecast:
|
97 | 99 | temp: "[[[ return entity.attributes.temperature + '°' ]]]"
|
98 | 100 | tempminmax: "[[[ return 'Max. ' + entity.attributes.forecast[0].temperature + '° Min. ' + entity.attributes.forecast[0].templow + '°' ]]]"
|
99 | 101 | - type: "vertical-stack"
|
100 |
| - cards: |
101 |
| - - type: "custom:button-card" |
102 |
| - template: "popup_weather_row" |
103 |
| - entity: "[[[ return entity.entity_id ]]]" |
104 |
| - variables: |
105 |
| - ulm_popup_weather_entity_idx: 0 |
106 |
| - - type: "custom:button-card" |
107 |
| - template: "popup_weather_row" |
108 |
| - entity: "[[[ return entity.entity_id ]]]" |
109 |
| - variables: |
110 |
| - ulm_popup_weather_entity_idx: 1 |
111 |
| - - type: "custom:button-card" |
112 |
| - template: "popup_weather_row" |
113 |
| - entity: "[[[ return entity.entity_id ]]]" |
114 |
| - variables: |
115 |
| - ulm_popup_weather_entity_idx: 2 |
116 |
| - - type: "custom:button-card" |
117 |
| - template: "popup_weather_row" |
118 |
| - entity: "[[[ return entity.entity_id ]]]" |
119 |
| - variables: |
120 |
| - ulm_popup_weather_entity_idx: 3 |
121 |
| - - type: "custom:button-card" |
122 |
| - template: "popup_weather_row" |
123 |
| - entity: "[[[ return entity.entity_id ]]]" |
124 |
| - variables: |
125 |
| - ulm_popup_weather_entity_idx: 4 |
126 |
| - - type: "custom:button-card" |
127 |
| - template: "popup_weather_row" |
128 |
| - entity: "[[[ return entity.entity_id ]]]" |
129 |
| - variables: |
130 |
| - ulm_popup_weather_entity_idx: 5 |
| 102 | + cards: > |
| 103 | + [[[ |
| 104 | + let rows = []; |
| 105 | +
|
| 106 | + function generate_weather_row(index) { |
| 107 | + var row = { |
| 108 | + 'type': 'custom:button-card', |
| 109 | + 'template': 'popup_weather_row', |
| 110 | + 'entity': entity.entity_id, |
| 111 | + 'variables': { |
| 112 | + 'ulm_popup_weather_entity_idx': index |
| 113 | + } |
| 114 | + }; |
| 115 | + return row; |
| 116 | + } |
| 117 | +
|
| 118 | + let surpress_first_forecast = ('ulm_weather_popup_surpress_first_forecast' in variables) ? variables.ulm_weather_popup_surpress_first_forecast : false; |
| 119 | +
|
| 120 | + let index = 0; |
| 121 | + for (let forecast in entity.attributes.forecast) { |
| 122 | +
|
| 123 | + if ((index == 0) && surpress_first_forecast) { |
| 124 | + index++; |
| 125 | + continue; |
| 126 | + } |
| 127 | +
|
| 128 | + rows.push(generate_weather_row(index)); |
| 129 | + index++; |
| 130 | + if (rows.length >= 6) { |
| 131 | + break; |
| 132 | + } |
| 133 | + } |
| 134 | + return rows; |
| 135 | + ]]] |
| 136 | + # Code above create following cards |
| 137 | + # cards: |
| 138 | + # - type: "custom:button-card" |
| 139 | + # template: "popup_weather_row" |
| 140 | + # entity: "[[[ return entity.entity_id ]]]" |
| 141 | + # variables: |
| 142 | + # ulm_popup_weather_entity_idx: 0 |
| 143 | + # - type: "custom:button-card" |
| 144 | + # template: "popup_weather_row" |
| 145 | + # entity: "[[[ return entity.entity_id ]]]" |
| 146 | + # variables: |
| 147 | + # ulm_popup_weather_entity_idx: 1 |
| 148 | + # - type: "custom:button-card" |
| 149 | + # template: "popup_weather_row" |
| 150 | + # entity: "[[[ return entity.entity_id ]]]" |
| 151 | + # variables: |
| 152 | + # ulm_popup_weather_entity_idx: 2 |
| 153 | + # - type: "custom:button-card" |
| 154 | + # template: "popup_weather_row" |
| 155 | + # entity: "[[[ return entity.entity_id ]]]" |
| 156 | + # variables: |
| 157 | + # ulm_popup_weather_entity_idx: 3 |
| 158 | + # - type: "custom:button-card" |
| 159 | + # template: "popup_weather_row" |
| 160 | + # entity: "[[[ return entity.entity_id ]]]" |
| 161 | + # variables: |
| 162 | + # ulm_popup_weather_entity_idx: 4 |
| 163 | + # - type: "custom:button-card" |
| 164 | + # template: "popup_weather_row" |
| 165 | + # entity: "[[[ return entity.entity_id ]]]" |
| 166 | + # variables: |
| 167 | + # ulm_popup_weather_entity_idx: 5 |
131 | 168 | buttons:
|
132 | 169 | card:
|
133 | 170 | type: "custom:button-card"
|
|
0 commit comments