Skip to content

Support use of entities in “max” and “min” properties#184

Open
mreysei wants to merge 7 commits intocustom-cards:masterfrom
mreysei:master
Open

Support use of entities in “max” and “min” properties#184
mreysei wants to merge 7 commits intocustom-cards:masterfrom
mreysei:master

Conversation

@mreysei
Copy link
Copy Markdown

@mreysei mreysei commented Sep 27, 2024

Name Type Default Description
max number or string 100 Defines maximum value of the bar using a number or a entity.
min number or string 0 Defines minimum value of the bar using a number or a entity.

And this is the working example using an entity and a number

type: custom:bar-card
positions:
  icon: inside
entities:
  - entity: sensor.maiku_salud
    name: Salud
    icon: mdi:heart
    color: '#a72741'
    unit_of_measurement: HP
    decimal: 0
    max: sensor.maiku_max_salud
  - entity: sensor.maiku_experiencia
    name: Experiencia
    icon: mdi:progress-star-four-points
    color: '#359441'
    unit_of_measurement: XP
    decimal: 0
    max: sensor.maiku_siguiente_nivel
  - entity: sensor.maiku_mana
    name: Maná
    icon: mdi:flask
    color: '#4693DB'
    unit_of_measurement: MP
    decimal: 0
    max: sensor.maiku_max_mana
  - entity: sensor.steps_daily
    name: Pasos de hoy
    icon: mdi:walk
    color: '#8646db'
    unit_of_measurement: pasos
    decimal: 0
    max: 10000

Result of such component
image

If this PR does not merge because this project is not maintained, you can add a "Custom repository" in HACS with my repository link:
https://github.com/mreysei/bar-card

@mreysei mreysei changed the title Can use an entity in max or min parameter Support use of entities in “max” and “min” properties Sep 27, 2024
@julll190
Copy link
Copy Markdown

Hi!
Please could you do the same thing to use entities in properties "from" and "to" inside the severity option, and maybe also in the "target" property? That is the only thing I miss.
Thank you in advance!

@mreysei
Copy link
Copy Markdown
Author

mreysei commented Oct 23, 2024

Hi @julll190, I'll give it a try.

@HenrikHills
Copy link
Copy Markdown

whenever I try to use your card I get "custom element doesn't exist: bar-card", any ideas?
I have added /hacsfiles/bar-card/bar-card.js as a js-module in resources (i guess this is added automatically when i add it through HACS) ...
It does work if i replace the content in "/homeassistant/www/community/bar-card/bar-card.js" with what you have here: github.com/mreysei/bar-card/blob/master/dist/bar-card.js
But when i try to use a sensor as max-value it doesnt show progress on the bar:

type: custom:bar-card
entities:
  - entity: sensor.billader_session_energy
    max: sensor.billader_estimert_levert_3_fase
    min: 0
    color: "#959d90"
positions:
  icon: "off"
  name: "off"
  value: "off"
height: 10px
entity_row: true

and sensor.billader_estimert_levert_3_fase is a int-number ( 24 ) in this case ...

@mreysei
Copy link
Copy Markdown
Author

mreysei commented Nov 1, 2024

@HenrikHills probably it is because I created a new beta version that doesn't works haha I deleted it
Try to change version to 1.3.0, now works?

@HenrikHills
Copy link
Copy Markdown

@HenrikHills probably it is because I created a new beta version that doesn't works haha I deleted it Try to change version to 1.3.0, now works?

haha okay, yeah that worked perfectly, nice thanks!!

foXaCe added a commit to foXaCe/bar-card that referenced this pull request Oct 22, 2025
This implements the functionality requested in PR custom-cards#184 for using entity
references in severity thresholds, extending beyond the existing min/max/target
entity support.

Features Added:
- Severity from/to properties now support entity references
- Dynamic severity thresholds that update based on entity state changes
- Automatic detection of entity state changes in severity sections

Changes:
- Updated _computeSeverityColor() to resolve entity values for from/to
- Updated _computeSeverityVisibility() to resolve entity values for from/to
- Updated _computeSeverityIcon() to resolve entity values for from/to
- Enhanced hasConfigOrEntitiesChanged() to detect severity entity changes

Example Usage:
```yaml
type: custom:bar-card
entities:
  - entity: sensor.temperature
    min: 0
    max: sensor.max_temperature  # Entity reference
    severity:
      - from: 0
        to: sensor.warning_threshold  # Entity reference
        color: green
      - from: sensor.warning_threshold  # Entity reference
        to: sensor.critical_threshold  # Entity reference
        color: orange
      - from: sensor.critical_threshold  # Entity reference
        to: 100
        color: red
```

This completes the full entity support for all numeric properties:
- min/max (already supported)
- target (already supported)
- severity from/to (new in this commit)
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

Successfully merging this pull request may close these issues.

3 participants