UI-Lovelace-Minimalist / UI

UI-Lovelace-Minimalist is a "theme" for HomeAssistant
https://ui-lovelace-minimalist.github.io/UI/
Other
1.57k stars 421 forks source link

Custom Waste Collection card not working at all #940

Open AndLindemann opened 1 year ago

AndLindemann commented 1 year ago

Describe the bug Tried to add the custom paddy_waste_collection card, but it doesn't work at all, throws JS errors in console.

To Reproduce

          - type: "custom:button-card"
            template:
              - custom_card_paddy_waste_collection
            entity: sensor.abfall
            variables:
              ulm_custom_card_paddy_waste_collection_name: paper
              ulm_custom_card_paddy_waste_collection_icon: mdi:trash-can
[Error] anonymous@
_evalTemplate@https://..../ui_lovelace_minimalist/cards/button-card/button-card.js:425:73268
@https://..../ui_lovelace_minimalist/cards/button-card/button-card.js:425:73761
forEach@[native code]
_getTemplateOrValue@https://..../ui_lovelace_minimalist/cards/button-card/button-card.js:425:73726
render@https://..../ui_lovelace_minimalist/cards/button-card/button-card.js:425:70749
update@https://..../ui_lovelace_minimalist/cards/button-card/button-card.js:1:19902
performUpdate@https://..../ui_lovelace_minimalist/cards/button-card/button-card.js:1:16788
@https://..../ui_lovelace_minimalist/cards/button-card/button-card.js:1:16447
asyncFunctionResume@[native code]
@[native code]
promiseReactionJobWithoutPromise@[native code]
promiseReactionJob@[native code]
    render (button-card.js:425:70844)
    update (button-card.js:1:19903)
    performUpdate (button-card.js:1:16789)
    (anonyme Funktion) (button-card.js:1:16448)
    asyncFunctionResume
    (anonyme Funktion)
    promiseReactionJobWithoutPromise
    promiseReactionJob

Expected behavior Waste collection card displayed

Screenshots

sensor data

Additional context n/a

AndLindemann commented 1 year ago

Somehow it seems the card cannot access the variables:

Bildschirmfoto 2022-08-25 um 16 06 21

Dashboard code:

      - type: custom:button-card
        template: custom_card_paddy_waste_collection
        entity: sensor.abfall
        variables:
          ulm_custom_card_paddy_waste_collection_icon: "mdi:delete"
          ulm_custom_card_paddy_waste_collection_name: "Papier"

Card template code:

---
custom_card_paddy_waste_collection:
  template:
    - "card_generic_swap"
  variables:
    ulm_card_generic_swap_name: "[[[ return variables.ulm_custom_card_paddy_waste_collection_name; ]]]"
    ulm_card_generic_swap_icon: "[[[ return variables.ulm_custom_card_paddy_waste_collection_icon; ]]]"
  state:
    - operator: "template"

Now if I just replace the

   ulm_card_generic_swap_name: "[[[ return variables.ulm_custom_card_paddy_waste_collection_name; ]]]"
    ulm_card_generic_swap_icon: "[[[ return variables.ulm_custom_card_paddy_waste_collection_icon; ]]]"

in the template card with fixed strings, the card works. It can't be too difficult to get the card to properly access the variables, but I wasn't able to figure it out. Any hints? It's probably an easy fix, likely something has changed on how variables are handled since the card was last updated and it just needs some minor corrections to get it back to work?

SgtRootCanal commented 1 year ago

I am having the same issue. Changing the above variables to Strings also fixed it for me.

rust84 commented 1 year ago

Seems to be related to https://github.com/UI-Lovelace-Minimalist/UI/pull/783

Slightly different workaround which retains variables:

Card template:

custom_card_paddy_waste_collection:
  template:
    - "card_generic_swap"
  variables:
    ulm_card_generic_swap_name: "[[[ return variables.ulm_card_generic_swap_name ]]]"
    ulm_card_generic_swap_icon: "[[[ return variables.ulm_card_generic_swap_icon ]]]"

Card:

    type: "custom:button-card"
    template: custom_card_paddy_waste_collection
    entity: sensor.waste_collection_household
    variables:
      ulm_card_generic_swap_icon: mdi:delete
      ulm_card_generic_swap_name: Household
jameshirka commented 1 year ago

I created a pull request to fix this which is similar to @rust84 solution. https://github.com/UI-Lovelace-Minimalist/UI/pull/1107

This has got me up and running again.