Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can custom styles used in auto-entities? #428

Open
idominiki opened this issue Feb 28, 2024 · 1 comment
Open

Can custom styles used in auto-entities? #428

idominiki opened this issue Feb 28, 2024 · 1 comment

Comments

@idominiki
Copy link

idominiki commented Feb 28, 2024

Hi guys!

I have the following sensor / card in my filters:

        filter:
          include:
            - entity_id: sensor.kochfeld_powerstate
              options:
                type: "custom:button-card"
                template: card_input_boolean
                custom_fields:
                  item1:
                    card:
                      custom_fields:
                        item1:
                          card:
                            styles:
                                icon:
                                  - color: >
                                      [[[
                                        if (entity.state == 'An'){
                                          return 'rgba(var(--color-blue),1)';
                                        }
                                        return 'rgba(var(--color-theme),0.2)';
                                      ]]]
                                img_cell:
                                  - background-color: >
                                      [[[
                                        var color = "blue";
                                        if (entity.state == 'An'){
                                          return 'rgba(var(--color-blue),0.2)';
                                        }
                                        return 'rgba(var(--color-theme),0.05)';
                                      ]]]

As the sensor is not a binary_sensor the img_cell and icon is always colored. So I add a custom style which checks the state of the entity id.

On a normal card outside auto-entities the config is working well, while I got the following error with auto-entities:
image

Does custom styles not working with auto-entities?

Thanks!
Dominik

@danielbrunt57
Copy link

Try using config.entity instead of entity.
Ie.
Either if (config.entity.state == 'An'){
or if (states(config.entity) == 'An'){

Here is my auto-entities card for batteries where you can see I am using state: '{{ states(config.entity)|int(0) }}%'.:

filter:
  include:
    - integration: battery_notes
      domain: sensor
      attributes:
        device_class: battery
      state: < 101
      options:
        type: custom:template-entity-row
        entity: this.entity_id
        name: >-
          {{state_attr(config.entity,'friendly_name')}}
          ({{state_attr(config.entity,'battery_type_and_quantity')}})
        secondary: >-
          Replaced: {{
          state_attr(config.entity,'battery_last_replaced')|relative_time() }}
          ago
        state: '{{ states(config.entity)|int(0) }}%'
        hold_action: |
          {
            "action": "call-service",
            "service": "battery_notes.set_battery_replaced",
            "data": {
              "device_id": "{{ device_id(config.entity) }}",
              },
            "confirmation": {
              "text": "Update Battery Replaced Date",
              },
          }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants