button-card: button card templates fail to load randomly
Checklist
- [x ] I updated the card to the latest version available
- [x ] I cleared the cache of my browser
Describe the bug I get the following at random times, it takes several refreshes or HA restart to fix the error
It only shows on button templates that are not in use, in the above screen shot there is 5 sensor butttons, 2 in use, 3 not, the error only shows only show on ones not in use.
the browser console shows the following.
[Error] anonymous@
_evalTemplate@https://homeassistant.local:8123/hacsfiles/button-card/button-card.js:425:9393
@https://homeassistant.local:8123/hacsfiles/button-card/button-card.js:425:12392
forEach@[native code]
_buildStyleGeneric@https://homeassistant.local:8123/hacsfiles/button-card/button-card.js:425:12357
_getIconHtml@https://homeassistant.local:8123/hacsfiles/button-card/button-card.js:519:161
_gridHtml@https://homeassistant.local:8123/hacsfiles/button-card/button-card.js:499:544
_cardHtml@https://homeassistant.local:8123/hacsfiles/button-card/button-card.js:479:32
render@https://homeassistant.local:8123/hacsfiles/button-card/button-card.js:425:6933
update@https://homeassistant.local:8123/hacsfiles/button-card/button-card.js:1:19879
performUpdate@https://homeassistant.local:8123/hacsfiles/button-card/button-card.js:1:16767
@https://homeassistant.local:8123/hacsfiles/button-card/button-card.js:1:16426
render (button-card.js:425:6967)
update (button-card.js:1:19880)
performUpdate (button-card.js:1:16768)
(anonymous function) (button-card.js:1:16427)
[Error] Unhandled Promise Rejection: AbortError: The operation was aborted.
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (light-entity-card.js.map, line 0)
light-entity-card v6.1.0 is installed
Version of the card Version: 3.5.0
To Reproduce This is the configuration I used:
styles:
custom_fields:
s1: &card_andyblac_room_sensor_1_icon_styling
- position: "absolute"
- left: "4%"
- bottom: "44%"
- width: "14%"
- height: "14%"
custom_fields:
s1:
card:
type: "custom:button-card"
template: >
[[[
let templates = [ 'card_andyblac_room_sensor_1_icon' ];
if (variables?.sensor_1?.templates?.length) {
templates.push(...variables.sensor_1.templates);
}
return templates;
]]]
variables: "[[[ return variables?.sensor_1; ]]]"
state:
- operator: "template"
value: "[[[ return !variables.sensor_1; ]]]"
styles:
card:
- display: "none"
entity: "[[[ return variables?.sensor_1?.entity_id; ]]]"
card_andyblac_room_sensor_1_icon:
tap_action:
action: "more-info"
size: "15px"
show_icon: true
show_name: false
styles:
icon:
- width: "90%"
- height: "90%"
- line-height: "0"
- color: "[[[ return variables.ulm_card_room_sensor_color ? 'rgba(var(--color-'+variables.ulm_card_room_sensor_color+'),0.4)' : 'rgba(var(--color-theme),0.2)'; ]]]"
# - color: "rgba(var(--color-theme),0.2)"
card:
- background: "none"
- box-shadow: "none"
- padding: "0px"
state:
- styles:
icon:
- color: "[[[ return variables.ulm_card_room_sensor_color ? 'rgba(var(--color-'+variables.ulm_card_room_sensor_color+'),1)' : 'rgba(var(--color-theme),0.7)'; ]]]"
# - color: "rgba(var(--color-theme),0.7)"
id: "on"
value: "[[[ return (entity?.state == '0' || entity?.state == 'off' || entity?.state == 'closed' || entity?.state == 'disarmed') ? '' : entity?.state; ]]]"
Screenshots
Expected behavior where the error are on scren it should just a empty space, when the sensor button is not in use, like the 2nd screenshot
Desktop (please complete the following information):
- Browser safari]
- Version 16.5.2
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (1 by maintainers)
Commits related to this issue
- fix(variables): variables was `undefined` if none where provided. Fix #718 — committed to custom-cards/button-card by RomRider a year ago
- fix(templates): `variables` was `undefined` if none where provided. Fix #718 — committed to custom-cards/button-card by RomRider a year ago
- chore(release): 4.0.0-dev.13 [skip ci] ## [4.0.0-dev.13](https://github.com/custom-cards/button-card/compare/v4.0.0-dev.12...v4.0.0-dev.13) (2023-07-26) ### Bug Fixes * **templates:** `variables` w... — committed to custom-cards/button-card by semantic-release-bot a year ago
- chore(release): 4.0.0 [skip ci] ## [4.0.0](https://github.com/custom-cards/button-card/compare/v3.5.0...v4.0.0) (2023-07-29) ### โ BREAKING CHANGES * **helpers:** If you were using any of the beta ... — committed to custom-cards/button-card by semantic-release-bot a year ago
Because itโs easier for me from a code perspective and avoid weird conflicts (and thus potential new unneeded questions/issues ๐ )