|
| 1 | +--- |
| 2 | +title: custom_card_homeassistant_updates |
| 3 | +hide: |
| 4 | + - toc |
| 5 | +--- |
| 6 | +<!-- markdownlint-disable MD046 --> |
| 7 | + |
| 8 | +# Custom-card "Homeassistant updates" |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +!! Attention !! |
| 13 | + |
| 14 | +This card needs additional template sensors and a group.updaters sensor to work, all detail can be found in this readme. |
| 15 | + |
| 16 | +## Credits |
| 17 | + |
| 18 | +- Author: AndyVRD - 2021 |
| 19 | +- Special thanks to [basbruss](https://github.com/basbruss/UI) |
| 20 | +- Version: 1.0.1 |
| 21 | + |
| 22 | +## Changelog |
| 23 | + |
| 24 | +<details> |
| 25 | +<summary>1.0.0</summary> |
| 26 | +Initial release |
| 27 | +</details> |
| 28 | +<details> |
| 29 | +<summary>1.0.1</summary> |
| 30 | +Added support for ulm_language variables |
| 31 | +</details> |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +```yaml |
| 36 | + - type: 'custom:button-card' |
| 37 | + template: card_homeassistant_updates |
| 38 | + variables: |
| 39 | + ulm_card_homeassistant_entity: 'group.updaters' |
| 40 | + ulm_card_homeassistant_core: "sensor.core_updates" |
| 41 | + ulm_card_homeassistant_supervisor: "sensor.supervisor_updates" |
| 42 | + ulm_card_homeassistant_os: "sensor.os_updates" |
| 43 | +``` |
| 44 | +
|
| 45 | +## Requirements |
| 46 | +
|
| 47 | +n/a |
| 48 | +
|
| 49 | +## Variables |
| 50 | +
|
| 51 | +<table> |
| 52 | +<tr> |
| 53 | +<th>Variable</th> |
| 54 | +<th>Example</th> |
| 55 | +<th>Required</th> |
| 56 | +<th>Explanation</th> |
| 57 | +</tr> |
| 58 | +<tr> |
| 59 | +<td>entity_</td> |
| 60 | +<td>group.updaters</td> |
| 61 | +<td>yes</td> |
| 62 | +<td>Group of template sensors</td> |
| 63 | +</tr> |
| 64 | +<tr> |
| 65 | +<td>core_</td> |
| 66 | +<td>sensor.core_updates</td> |
| 67 | +<td>yes</td> |
| 68 | +<td>sensor core installed/latest version</td> |
| 69 | +</tr> |
| 70 | +<tr> |
| 71 | +<td>os_</td> |
| 72 | +<td>sensor.os_updates</td> |
| 73 | +<td>no</td> |
| 74 | +<td>sensor os installed/latest version</td> |
| 75 | +</tr> |
| 76 | +<tr> |
| 77 | +<td>supervisor_</td> |
| 78 | +<td>sensor.supervisor_updates</td> |
| 79 | +<td>no</td> |
| 80 | +<td>sensor supervisor installed/latest version</td> |
| 81 | +</tr> |
| 82 | +</table> |
| 83 | +
|
| 84 | +## Template code |
| 85 | +
|
| 86 | +```yaml |
| 87 | +--- |
| 88 | +card_homeassistant_updates: |
| 89 | + triggers_update: "all" |
| 90 | + styles: |
| 91 | + grid: |
| 92 | + - grid-template-areas: "'item1' 'item2'" |
| 93 | + - grid-template-columns: "1fr" |
| 94 | + - grid-template-rows: "min-content min-content" |
| 95 | + - row-gap: "12px" |
| 96 | + card: |
| 97 | + - border-radius: "var(--border-radius)" |
| 98 | + - box-shadow: "var(--box-shadow)" |
| 99 | + - padding: "12px" |
| 100 | + custom_fields: |
| 101 | + item1: |
| 102 | + card: |
| 103 | + triggers_update: "all" |
| 104 | + type: "custom:button-card" |
| 105 | + template: |
| 106 | + - "icon_info_updates" |
| 107 | + - "ulm_language_variables" |
| 108 | + icon: 'mdi:home-assistant' |
| 109 | + tap_action: |
| 110 | + action: "none" |
| 111 | + entity: "[[[ return variables.ulm_card_homeassistant_entity ]]]" |
| 112 | + name: > |
| 113 | + [[[ |
| 114 | + if(states[variables.ulm_card_homeassistant_core].state ==='True' || states[variables.ulm_card_homeassistant_supervisor].state ==='True' || states[variables.ulm_card_homeassistant_os].state ==='True'){ |
| 115 | + return 'Updates beschikbaar!'; |
| 116 | + } else { |
| 117 | + return 'Geen updates' |
| 118 | + } |
| 119 | + ]]] |
| 120 | + label: > |
| 121 | + [[[ |
| 122 | + if(variables.ulm_card_homeassistant_core){ |
| 123 | + if(states[variables.ulm_card_homeassistant_core].state ==='True'){ |
| 124 | + var core = 'Core: ' + states[variables.ulm_card_homeassistant_core].attributes.installed_version + ' -> ' + states[variables.ulm_card_homeassistant_core].attributes.latest_version; |
| 125 | + } else { |
| 126 | + var core = 'Core: ' + states[variables.ulm_card_homeassistant_core].attributes.installed_version; |
| 127 | + } |
| 128 | + } |
| 129 | + if(variables.ulm_card_homeassistant_supervisor){ |
| 130 | + if(states[variables.ulm_card_homeassistant_supervisor].state ==='True'){ |
| 131 | + var supervisor = 'Supervisor: ' + states[variables.ulm_card_homeassistant_supervisor].attributes.installed_version + ' -> ' + states[variables.ulm_card_homeassistant_supervisor].attributes.latest_version; |
| 132 | + } else { |
| 133 | + var supervisor = 'Supervisor: ' + states[variables.ulm_card_homeassistant_supervisor].attributes.installed_version; |
| 134 | + } |
| 135 | + } |
| 136 | + if(variables.ulm_card_homeassistant_os){ |
| 137 | + if(states[variables.ulm_card_homeassistant_os].state ==='True'){ |
| 138 | + var os = 'Os: ' + states[variables.ulm_card_homeassistant_os].attributes.installed_version + ' -> ' + states[variables.ulm_card_homeassistant_os].attributes.latest_version; |
| 139 | + } else { |
| 140 | + var os = 'Os: ' + states[variables.ulm_card_homeassistant_os].attributes.installed_version; |
| 141 | + } |
| 142 | + } |
| 143 | + if(variables.ulm_card_homeassistant_core && variables.ulm_card_homeassistant_supervisor && variables.ulm_card_homeassistant_os){ |
| 144 | + return supervisor + '<br>' + core + '<br>' + os; |
| 145 | + } else if(variables.ulm_card_homeassistant_core && variables.ulm_card_homeassistant_supervisor){ |
| 146 | + return supervisor + '<br>' + core; |
| 147 | + } else if(variables.ulm_card_homeassistant_core){ |
| 148 | + return core; |
| 149 | + } |
| 150 | + ]]] |
| 151 | + styles: |
| 152 | + icon: |
| 153 | + - color: "rgba(var(--color-theme),0.9)" |
| 154 | + item2: |
| 155 | + card: |
| 156 | + type: "custom:button-card" |
| 157 | + template: "list_3_items" |
| 158 | + custom_fields: |
| 159 | + item1: |
| 160 | + card: |
| 161 | + type: "custom:button-card" |
| 162 | + template: "widget_icon" |
| 163 | + icon: "mdi:file-document" |
| 164 | + tap_action: |
| 165 | + action: url |
| 166 | + url_path: https://www.home-assistant.io/latest-release-notes/ |
| 167 | + item2: |
| 168 | + card: |
| 169 | + type: "custom:button-card" |
| 170 | + template: "widget_icon" |
| 171 | + icon: "mdi:cog" |
| 172 | + tap_action: |
| 173 | + action: navigate |
| 174 | + navigation_path: /config/server_control |
| 175 | + |
| 176 | + item3: |
| 177 | + card: |
| 178 | + type: "custom:button-card" |
| 179 | + template: "widget_icon" |
| 180 | + icon: "mdi:update" |
| 181 | + tap_action: |
| 182 | + action: navigate |
| 183 | + navigation_path: /config/dashboard |
| 184 | + |
| 185 | +icon_info_updates: |
| 186 | + color: var(--google-grey) |
| 187 | + show_icon: true |
| 188 | + show_label: true |
| 189 | + show_name: true |
| 190 | + state: |
| 191 | + - value: "on" |
| 192 | + styles: |
| 193 | + custom_fields: |
| 194 | + notification: |
| 195 | + - border-radius: "50%" |
| 196 | + - position: "absolute" |
| 197 | + - left: "28px" |
| 198 | + - top: "8px" |
| 199 | + - height: "16px" |
| 200 | + - width: "16px" |
| 201 | + - border: "2px solid var(--card-background-color)" |
| 202 | + - font-size: "12px" |
| 203 | + - line-height: "14px" |
| 204 | + - background-color: > |
| 205 | + [[[ |
| 206 | + return "rgba(var(--color-blue),1)"; |
| 207 | + ]]] |
| 208 | + icon: |
| 209 | + - color: 'rgba(var(--color-blue),1)' |
| 210 | + img_cell: |
| 211 | + - background-color: 'rgba(var(--color-blue), 0.2)' |
| 212 | + styles: |
| 213 | + icon: |
| 214 | + - color: 'rgba(var(--color-theme),0.2)' |
| 215 | + label: |
| 216 | + - justify-self: start |
| 217 | + - align-self: start |
| 218 | + - font-weight: bolder |
| 219 | + - font-size: 12px |
| 220 | + - filter: opacity(40%) |
| 221 | + - margin-left: 16px |
| 222 | + - text-align: "start" |
| 223 | + name: |
| 224 | + - align-self: end |
| 225 | + - justify-self: start |
| 226 | + - font-weight: bold |
| 227 | + - font-size: 14px |
| 228 | + - margin-left: 16px |
| 229 | + - margin-bottom: 4px |
| 230 | + state: |
| 231 | + - justify-self: start |
| 232 | + - align-self: start |
| 233 | + - font-weight: bolder |
| 234 | + - font-size: 12px |
| 235 | + - filter: opacity(40%) |
| 236 | + - margin-left: 12px |
| 237 | + img_cell: |
| 238 | + - background-color: 'rgba(var(--color-theme),0.05)' |
| 239 | + - border-radius: 50% |
| 240 | + - place-self: center |
| 241 | + - width: 42px |
| 242 | + - height: 42px |
| 243 | + grid: |
| 244 | + - grid-template-areas: '"i n" "i l"' |
| 245 | + - grid-template-columns: min-content auto |
| 246 | + - grid-template-rows: min-content min-content |
| 247 | + card: |
| 248 | + - border-radius: 21px 8px 8px 21px |
| 249 | + - box-shadow: none |
| 250 | + - padding: 0px |
| 251 | + # - background-color: 'rgba(var(--color-theme),0)' |
| 252 | + custom_fields: |
| 253 | + notification: > |
| 254 | + [[[ |
| 255 | + if ( entity.state =="unavailable" || entity.state =="on" ){ |
| 256 | + return `<ha-icon icon="mdi:party-popper" style="width: 12px; height: 12px; color: var(--primary-background-color);"></ha-icon>`; |
| 257 | + } |
| 258 | + ]]] |
| 259 | + size: 20px |
| 260 | + |
| 261 | +``` |
| 262 | + |
| 263 | +## Template sensors code |
| 264 | + |
| 265 | +```yaml |
| 266 | + - platform: command_line |
| 267 | + name: core_updates |
| 268 | + command: 'curl http://supervisor/core/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"latest_version":.data.version_latest,"installed_version":.data.version,"update_available":.data.update_available}''' |
| 269 | + value_template: '{{ value_json.update_available }}' |
| 270 | + scan_interval: 600 |
| 271 | + json_attributes: |
| 272 | + - update_available |
| 273 | + - latest_version |
| 274 | + - installed_version |
| 275 | + |
| 276 | + - platform: command_line |
| 277 | + name: supervisor_updates |
| 278 | + command: 'curl http://supervisor/supervisor/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"latest_version":.data.version_latest,"installed_version":.data.version,"update_available":.data.update_available}''' |
| 279 | + value_template: '{{ value_json.update_available }}' |
| 280 | + scan_interval: 600 |
| 281 | + json_attributes: |
| 282 | + - update_available |
| 283 | + - latest_version |
| 284 | + - installed_version |
| 285 | + |
| 286 | + - platform: command_line |
| 287 | + name: os_updates |
| 288 | + command: 'curl http://supervisor/os/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"latest_version":.data.version_latest,"installed_version":.data.version,"update_available":.data.update_available}''' |
| 289 | + value_template: '{{ value_json.update_available }}' |
| 290 | + scan_interval: 600 |
| 291 | + json_attributes: |
| 292 | + - update_available |
| 293 | + - latest_version |
| 294 | + - installed_version |
| 295 | +``` |
| 296 | +
|
| 297 | +## Template sensor group.updates |
| 298 | +
|
| 299 | +```yaml |
| 300 | +group: |
| 301 | + updaters: |
| 302 | + name: Updates |
| 303 | + entities: |
| 304 | + - binary_sensor.updater_core |
| 305 | + - binary_sensor.updater_supervisor |
| 306 | + - binary_sensor.updater_os |
| 307 | +``` |
0 commit comments