-
Notifications
You must be signed in to change notification settings - Fork 252
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
New display precision in entity is not taken into account... #662
Comments
Same here. I don't think this will be fixed though as the project appears to be abandoned. |
Uh, i didn't notice that... it really seems that project is very old. That's very sad, since this card is one of the best cards in HA... you can do practically everything with it... definitely the most usefull card out there. |
same problem here |
A manual workaround is adding the following to the card configuration: state_display: | |
Uau… |
@Protoncek I use this template with my pressure sensor:
you can change number of decimals by changing 0 in toFixed() to other number . |
Thanks, i found one working command, too: |
@Protoncek
|
Aha… thanks for explanation. So, basically, end effect is the same… |
if you want 0 decimals, then yes, effect should be the same, but if you want the float number with some decimals, I'd stick with .toFixed() [but also: I'm not a programmer, so maybe there's something I don't know about those both ways ;)] |
Same issue in here. All other cards take the new "Display precision" into account, but custom:button-card does not. |
What about this method I found?
Sounds like it just chops the decimals to 1 without doing any rounding so 21.19 would turn into 21.1 instead of 21.2... if so, not what I want. Is that the case? I liked this method simply because it doesn't reference the entity name. Anyhow, one issue the few methods I tried have is that if the entity is deleted/name changed/etc then you get a huge burgundy error that messes up the dashboard. Is there some way to have it fail more "discretely"? |
Actually.. not all... i found another one who doesn't: custom:simple-thermostat. I didn't report a problem for that one (yet)... Alexruffel: thanks, that also works! |
please stop posting you experience the same issue only. Of course you do, everyone does, as this now is the state of the affairs with changed HA Frontend handling not taken into account in an unchanged custom:button-card... It causes many email/notifications without additional value for all followers of this repo. on the rounding: simply check the js instructions you find in the various online tutorials, they all can be used inside button-card, depending on your needs. It's still the best card ever ;-) We might be lucky Romrider would update button-card to implement the new HA Dashboard techniques. Until that moment, we just will have to manage. |
This should be fixed with the latest beta 4.0.0-dev7 |
If you're not seeing the result of numeric_precision it's because of a caching issue probably. Also that doesn't apply to a direct access to the state, you'd have to use the new localize function on the custom_field state access (check the dev branch readme about that). |
Fixed in next version |
## [4.0.0-dev.9](v4.0.0-dev.8...v4.0.0-dev.9) (2023-07-24) ### Bug Fixes * numerical states would not follow HA's format ([72d7c41](72d7c41)), closes [#662](#662)
🎉 This issue has been resolved in version 4.0.0-dev.9 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Hm... new dev version causes that this card doesn't work in browser-mod's popup - i have a popup where i change station on my internet radio. I click on one button, but nothing happens. Going back to 3.5.0 works again. And, this decimals issue is solved only if i set to show state "as is" (show_state:_ true and that's it) . If i set template like this:
then still shows too many decimals. Also, as you said: card-mod styles are totally off... |
It's displayed without, but the state is stored with the 1 decimal after the
co2: >
[[[ return `Co2:
<span style='color: var(--text-color-sensor);'>
${localize(states['sensor.co2_living'])} ppm</span>`; ] or if you defined it, you have to force it for this value specifically (this behaviour will change, it's not going to take into account the main co2: >
[[[ return `Co2:
<span style='color: var(--text-color-sensor);'>
${localize(states['sensor.co2_living'], undefined, 0)} ppm</span>`; ] |
Without the config, there's not much I can do about it 🤷♂️
Expected as you access the raw state value. state_display: |
[[[
return "outside is: " + localize(states['sensor.temperature_outside'])
]]]
The only modification in the code is on Also, we can't have all the shiny new features and expect backwards compatibility forever, there's a tradeoff. 🤷♂️ |
First of all, thank you @RomRider for implementing all these fixes! I use button-card a lot and love it! While waiting on a fix for the precision issue, I found an alternative solution which may help @Protoncek. The rounding was handled within the state_display as shown below:
With your latest revision I can now use this but I wonder whether there is any way to avoid repeating the sensor name. In the example above
The YAML above is for the temp card shown below: |
@alexruffell, for the state of the main entity, no need to use state_display at all. But you can do |
Could you create a new issue for this please, as this is unrelated and I'll forget it's here. Thanks |
Sure...sorry about that... |
Yes, that's expected. localize doesn't use the numeric precision from the card anymore (there was a note I think in some of the release notes).
The third parameter is to set the numeric precision ('card' makes it use the one defined in the card, or you can set any number also). The dev README has been updated with examples ;) |
thanks that works. or, if I try to set a I did read the notes but am confused (cant make it happen..)
could you please post a simple example of how to do that?
is the fixed order of options and
considering that, I dont see how I managed to change the precision, as that 'card' option is set on the 'units'... unless that first 'undefined' is for the state? parameter, and the last 2 are simply left out? testing a second 'card' for the show_units? options yield nothing either... arrgghh what am I not seeing:
edit wait, these dont take 'card' option:
or
work... |
localize doesn't use the cards config (but for numeric_precision specifically). |
Maybe I should do a |
I've just discovered that... wouldn't be a bad idea though, also being able to use a 'card' wide option for those 2 ( so we could set those on card level and apply to all other localized templates? btw the |
well, yes, I suppose that would be what I just suggested above: by default use the card options for those 3 parameters, unless set in the individual template.
and then simply use
If no localize is set, use all defaults.
with the undefined to skip one parameter |
## [4.0.0](v3.5.0...v4.0.0) (2023-07-29) ### ⚠ BREAKING CHANGES * **helpers:** If you were using any of the beta before `4.0.0-dev14`. Please replace all the calls to helper functions with `helpers.xxx` for eg. `helpers.relativeTime(entity.state)` or `helpers.localize(entity)` * **hacs:** Minimum required HA Version is now 2023.7 * **actions:** Requires HA 2023.4 minimum. Support for the new action format (`target` is also be supported), `service_data` should be renamed to `data` (but it still works with the old format) * **icons:** This might break your card-mod setup * this might break some of your color settings ### Features * **action:** `repeat_limit` for `hold_action` ([73c216f](73c216f)), closes [#564](#564) [#555](#555) * **actions:** Support for the new action (assist) and all the future ones ([d9c17a4](d9c17a4)), closes [#711](#711) [#685](#685) * **custom_fields:** Add `do_not_eval` to stop evaluating js templates in an embedded card ([1638cf8](1638cf8)) * **helpers:** all template functions are now available through the `helpers` object ([f22ed69](f22ed69)) * **icons:** replace ha-icon with ha-state-icon to follow new HA's icons per domain automatically ([ab6a3f5](ab6a3f5)) * **templates:** new `relativeTime` function to display a relative time in a template and update it automatically ([965a3d7](965a3d7)), closes [#701](#701) * **templates:** New date and time format helpers ([9b4fb05](9b4fb05)) * **variables:** A variable can depend on another variable based on their name's alphabetical order ([8cddccb](8cddccb)), closes [#656](#656) * Force the `numeric_precision` for states which are numbers ([24d75c2](24d75c2)) * new helper functions for date/time in templates ([2b75993](2b75993)), closes [#701](#701) * Support for localization in templates ([5de2dc9](5de2dc9)) ### Bug Fixes * *_action more-info entity as a template was not evaluated ([02441b2](02441b2)), closes [#734](#734) * `group_expand` now works even if the entity is not a `group.xxx` ([f192ded](f192ded)), closes [#645](#645) * Color are now aligned with HA > 2022.12 ([685d55e](685d55e)), closes [#635](#635) * custom fields would sometime throw unsafeHTML errors ([c67e1d5](c67e1d5)), closes [#725](#725) * ha-icon (if in custom_fields) size was weird ([a448c8e](a448c8e)) * ha-state-icon CSS selector was wrong ([a1bb39a](a1bb39a)) * icon would be cut with card height defined ([19f8393](19f8393)), closes [#731](#731) * localization fix ([02dfab3](02dfab3)), closes [#685](#685) [#693](#693) * lock icon was displaying over more-info dialog ([bf075b0](bf075b0)), closes [#694](#694) * lock would go out of the button ([0b3e4d3](0b3e4d3)) * non string fiels would error with an unsafeHTML error ([d65c347](d65c347)), closes [#725](#725) * numerical states would not follow HA's format ([72d7c41](72d7c41)), closes [#662](#662) * optimize contrast color compute ([35109c3](35109c3)) * relativeTime didn't support to set the first letter uppercase ([f8b9b09](f8b9b09)), closes [#735](#735) * Some cards with child cards wouldn't be clickable ([9f21c58](9f21c58)) * text/icon contrast when using label-card ([01e199b](01e199b)) * variable which were objects were only evaluated once ([e40bda9](e40bda9)) * **templates:** `variables` was `undefined` if none where provided. ([fad332b](fad332b)), closes [#718](#718) * tooltip would show over everything ([1bc8f99](1bc8f99)) * **color:** main config `color` was broken ([b93c996](b93c996)) * **hacs:** minimum HA version 2023.7 ([db3b394](db3b394)) * **templates:** don't use the `numeric_precision` from the card config for `localize` in js templates by default ([2cc384f](2cc384f))
🎉 This issue has been resolved in version 4.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Checklist
Describe the bug
Today HA was updated to 2023.3 and with it a new function was added: possibility to set precision for entities. I have Xiaomi sensors which by default show humidity to one decimal (say: 49.1%) and temperature to two decimals (say: 23.13°C), which is too much. So i changed that into: humidity=zero decimals (=49%), temperature only one decimal (=23.1°C.
In HA, "entities card" shows correctly 49% and 23.1°C, but in "custom:button-card" it still shows original values.
Version of the card
Version: 3.4.2
To Reproduce
This is the configuration I used:
The text was updated successfully, but these errors were encountered: