custom-cards / button-card

❇️ Lovelace button-card for home assistant
MIT License
1.93k stars 233 forks source link

Entity bug in V4.0b15 #734

Closed andyblac closed 1 year ago

andyblac commented 1 year ago

Checklist

Version of the card Version: 4.0b15

Describe the bug

  tap_action:
    action: "more-info"
    entity: "[[[ return variables.ulm_card_person_entity; ]]]"
  name: "[[[ return states[variables.ulm_card_person_entity].attributes.friendly_name ]]]"
  entity: "[[[ return variables.ulm_card_person_entity; ]]]"
  icon: "[[[ return variables.ulm_card_person_icon; ]]]"
  show_entity_picture: "[[[ return variables.ulm_card_person_use_entity_picture ]]]"
  entity_picture:
    "[[[ return variables.ulm_card_person_use_entity_picture ? states[variables.ulm_card_person_entity].attributes.entity_picture\
    \ : null ]]]"

in V3.5 the above code works fine, but in v4.0b12, when you set an entity in the tap_action and then tap on it in the dashboard you see the following error.

Screenshot 2023-07-27 at 09 52 33

in the example above the action entity and the main entity, both use the same entity variable.

Expected behavior it should show the person enity

RomRider commented 1 year ago

Can you share the relevant main card + custom_field config please? The code has not changed on the custom_fields part on those new versions

RomRider commented 1 year ago

This works well:

          - type: custom:button-card
            variables:
              entity: light.test_light
            styles:
              grid:
                - grid-template-areas: "'test' 'icon'"
            custom_fields:
              test:
                card:
                  icon: mdi:fan
                  type: custom:button-card
                  entity: '[[[ return variables.entity; ]]]'
                  tap_action:
                    action: more-info
                    entity: '[[[ return variables.entity; ]]]'

So there's something else going on with your code

BTW, using templates for entity or show_entity_picture outside of a custom field doesn't work and has never been possible

andyblac commented 1 year ago
          - type: "custom:button-card"
            template:
              - custom_card_andyblac_person
            entity: person.christine_leek
            variables:
              ulm_card_person_entity: person.christine_leek
              ulm_card_person_use_entity_picture: false
              ulm_card_person_icon: mdi:face-woman
              ulm_card_person_battery: sensor.christines_iphone_icloudv3_battery
              ulm_address: sensor.christines_iphone_icloudv3_zone_name
              ulm_card_person_eta: sensor.christines_iphone_icloudv3_zone_distance

thats the dashbaord code, I have also attached the entier YAML for the template. custom_card_andyblac_person.yaml.zip

BTW this is just tweaked code from the Lovelace Minimalist project, lost of templates are now broken in 4.0 beta.

RomRider commented 1 year ago

Yeah, so what you are doing has never been possible, as stated in my last comment, you can't template entity or show_entity_picture in the main button-card. This never worked so it's unrelated to the latest beta.

andyblac commented 1 year ago

this is strange because it works in 3.5 and Minimalist project use it all over.

andyblac commented 1 year ago

like here https://github.com/UI-Lovelace-Minimalist/UI/blob/main/custom_components/ui_lovelace_minimalist/lovelace/ulm_templates/card_templates/cards/card_person.yaml

andyblac commented 1 year ago

show entity picture still works

Screenshot 2023-07-27 at 10 34 13
RomRider commented 1 year ago

Yes, but if you look here https://ui-lovelace-minimalist.github.io/UI/usage/cards/card_person/#usage, you'll see they redefine the entity in the main config + on the variables.

And again, show_entity_picture doesn't support templates (it works magically because the picture exists, else I fall back to the icon)

andyblac commented 1 year ago

just like i do in my above code. I used their code as a base.

RomRider commented 1 year ago

What is this, then entity: "[[[ return variables.ulm_card_person_entity; ]]]" in your first post ?

This is not needed entity_picture: "[[[ return variables.ulm_card_person_use_entity_picture ? states[variables.ulm_card_person_entity].attributes.entity_picture\ \ : null ]]]" as I do it in the code directly (and anyway, it's not templatable)

andyblac commented 1 year ago

from the template line 14 and again line 31.

https://github.com/UI-Lovelace-Minimalist/UI/blob/main/custom_components/ui_lovelace_minimalist/lovelace/ulm_templates/card_templates/cards/card_person.yaml#L14

RomRider commented 1 year ago

I was speaking about this:

  tap_action:
    action: "more-info"
    entity: "[[[ return variables.ulm_card_person_entity; ]]]"
  name: "[[[ return states[variables.ulm_card_person_entity].attributes.friendly_name ]]]"
  entity: "[[[ return variables.ulm_card_person_entity; ]]]" # <<<<<<<<< THIS HERE
  icon: "[[[ return variables.ulm_card_person_icon; ]]]"
  show_entity_picture: "[[[ return variables.ulm_card_person_use_entity_picture ]]]"
  entity_picture:
    "[[[ return variables.ulm_card_person_use_entity_picture ? states[variables.ulm_card_person_entity].attributes.entity_picture\
    \ : null ]]]"
andyblac commented 1 year ago

yes exactly the same in there code, line 31

andyblac commented 1 year ago
Screenshot 2023-07-27 at 10 41 09
andyblac commented 1 year ago

if i comment out the entity from the tap_action everything works as expected, but this then means we can nolonger have a different entity for tap actions ?

RomRider commented 1 year ago

Ok, you need to share the full context... and how you instantiate the template else it's impossible to know what we're taking about. Just showing me what you shared initially and not how you use it will make me think you are trying to template the entity config entry...

andyblac commented 1 year ago

i'm not sure, this the code i use with minimalist project. should I report the bug there instead ? I gave you my full code for dashboard and the template import.

RomRider commented 1 year ago

Alright, I found the bug now that I understand the context :)

andyblac commented 1 year ago

sorry I could not be more help, still learning all this stuff.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 4.0.0-dev.16 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

andyblac commented 1 year ago

thanks alot fix works, how can I send you a donation ?

RomRider commented 1 year ago

You can't :D

andyblac commented 1 year ago

hahah, ok, i'll keep trying to help find bugs.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 4.0.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: