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

Feature Request: Allow Template For Battery Entity #165

Open
Colorado4Wheeler opened this issue May 6, 2024 · 10 comments
Open

Feature Request: Allow Template For Battery Entity #165

Colorado4Wheeler opened this issue May 6, 2024 · 10 comments

Comments

@Colorado4Wheeler
Copy link

I would love to be able to template the battery entity. I use this with auto entities and it works great, allowing me to filter the results as needed, but I can't display the battery percentage because the battery entity won't allow a template, i.e.:

    - type: custom:flower-card
      entity: plant.ecowitt_outdoor_1_ch1
      show_bars:
        - temperature
        - humidity
        - moisture
      display_type: full
      battery_sensor: >-
        {{ sensor.outdoor_1_ch1_battery_level }}

Obviously the above would be a single line but I used that example just to show my request. My actual use case is a much more complex template that extracts the entity name to re-assemble the battery entity name.

@Olen
Copy link
Owner

Olen commented May 6, 2024

Please provide a PR.
For now, I have a problem understanding the use case. Why would a template be needed to just add a simple entity_id?

Maybe you can use something like this?
https://github.com/iantrich/config-template-card
(No idea if it works or is still maintained, it was just something that showed up on a google search)

@Colorado4Wheeler
Copy link
Author

When configuring manually providing the entity_id is fine, works great, but if you use something like Auto Entities there is no way to populate the battery field since it's not part of the plant entity itself. My request is so that I can template the proper value into that field when it is auto generated.

@Colorado4Wheeler
Copy link
Author

My mistake, this should have been on the flower card - although, if we are using Home Assistant's built-in Plant system as a base for this replacement, the HA plant does have the ability to link to a battery entity on the plant template itself, which should then translate to the Flower Card.

@Olen
Copy link
Owner

Olen commented May 13, 2024

I am pretty sure my flower-card does not work with the standard HA-plant-integration.

I have - on purpose - not added a battery entity to the plant device, as for many of my plants, I use different physical sensors for e.g temperature, humidity, light etc. Any of these (can) have batteries, so I don't like to include a single battery to the plant as I want the plant to be an autonomous entity and plants themselves do not usually have batteries...

Regarding templating of the card config, I have no idea how to attack that, so I would really need help there.

@marefr
Copy link

marefr commented Jun 13, 2024

I think I've solved what your asking for using the auto entities. Works for me at least.

Dashboard example (each card is an area, Vardagsrum (living room) in this example):

views:
  - title: Home
    cards:
      - square: false
        type: grid
        title: Vardagsrum
        cards:
          - type: custom:auto-entities
            filter:
              template: |-
                {% for state in states.plant -%}
                  {%- if state.entity_id | regex_match("plant.plant.*", ignorecase=True) and area_id(state.entity_id) == 'vardagsrum' -%}
                    {{
                      {
                        'entity': state.entity_id,
                        'type': 'custom:flower-card',
                        'battery_sensor': state.entity_id | regex_replace(find='plant\\.plant\\_([\\d]+)', replace='sensor.mi_flora_\\1_battery', ignorecase=False),
                        'show_bars': [
                          'moisture',
                          'conductivity',
                          'temperature',
                          'illuminance',
                          'humidity',
                          'dli'
                        ],
                        'display_type': 'full'
                      }
                    }},
                  {%- endif -%}
                {%- endfor %}
            columns: 1
            sort:
              method: friendly_name
            show_empty: true
            card_param: cards
            card:
              square: false
              type: grid
              columns: 1

@Olen
Copy link
Owner

Olen commented Jun 14, 2024

This probably belongs under the flower-card.

If someone can verify that the example works, I can add it to the README there.

@marefr
Copy link

marefr commented Jun 14, 2024

See below for verification it works. I should have added earlier that I use a naming scheme for plants and the devices I use for measuring (Mi Flora), so the example provided earlier requires plants named plant.plant_001... plant.plant_XYZ and devices named sensor.mi_flora_001... sensor.mi_flora_XYZ. The key is using the same identifier of some kind (001) for plant and sensor that has the battery and the example should be able to be tailored for your plants and sensors.

IMG_4607
IMG_4608
IMG_4609

@Olen
Copy link
Owner

Olen commented Jun 14, 2024

Would you be able to simplify the config to show it with just one card (e.g. without the auto-entities)?

That way I can add examples for both a single card, and for auto-entites (unless auto-entities is a prerequisite for the battery-template to work).

@marefr
Copy link

marefr commented Jun 14, 2024

With one card you statically configure it so that's normally not a problem. A single card with static config:

type: custom:flower-card
entity: plant.plant_001
battery_sensor: sensor.mi_flora_001_battery
show_bars:
  - moisture
  - conductivity
  - temperature
  - illuminance
  - humidity
  - dli

@Olen
Copy link
Owner

Olen commented Jun 14, 2024

No, with a template for battery. Just to get any escaped characters right

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

3 participants