Hi All,
I’m trying to round my temperature value in a custom button card (see below). Cannot find any clues in the documentation how to do this. Probably javascript Math.round somewhere, but where?
PPee
as a side note, I have no idea where you’re even rounding in your configuration… Is that intentional? Your JS has nothing to do with showing the state.
Hi Petro,
Yes I know how to find js instructions for rounding. The question is how to integrate that into the card config. In the enclosed code it is not integrated yet
first, you’re wrapping your template in quotes, that turns it into a string. Second, states are strings and they need to be numbers. Thrid, you can use the entity attached to the button card. Fourth, you need to add the sigfig rounding.
Thanks again Petro,
Maybe it is something stupid in my card config, but it does not work. I tried all three solution, but no visible change in the card display. Even when I make an intentional typo in the state_display syntax, like Mathhhh.round … , no errors and no change.
Would anyone be able to kindly advise how I can round up tp 1 decimal place the sensor values in the below button card? I have read this thread and tried few options but not much luck. Many Thanks
did you google that exact same question? add javascript, because that is what Button card uses:
btw, you can make your card much simpler to read by using the helpers.localize() function that were introduced in the recent updates. it would at least no longer be required to add the units.
there are also several nifty time functions you can use
Thanks for the tip and guidance, will look into this. I am quite new to HA and not coming from any sort of developer background. Whatever I have already setup on my HA is based on reading forums like this and loads of Google search, and experimenting.
I did Google for this for the last 1-2 days and read posts on how to round-up sensor values on HA, but none worked for me. Having said that, my Google search was not specifically related to Javascript, did not even know that button card is that.
Base/main entity, rounded values - no issue. This can be done with the JS functions highlighted here, or the numeric_precision parameter at the root level of the button card. I normally change the precision in the underlying entity settings, which then carries into the button card (eg. default is 2 decimals, changed precision to 1 decimal place, 1 decimal place is displayed in the button-card).
Custom_fields, rounded value - have tried the options here, but none work. Have also tried changing the entitiy’s default precision level in the entity settings, but the change in precision does not carry into the button-card (eg. default is 2 decimals, changed precision to 1 decimal place, the custom_fields still shows the default 2 decimals).
Checking if this understanding is correct, as am still hoping that there is a solution for custom_fields rounding …!
Edit: I solved the custom_fields issue by creating a template sensor which rounds to 1 decimal place, then using the template sensor entity in the custom_fields, instead of the original entity. Not elegant and inefficient, but it works …!
Thank you so much! This solved my problem perfectly
Before my Cards looked very wired because of the too high precision. Here an example, The row “Wohnzimmer” with the couch icon is with rounding, the row “Küche” with the pot icon is without rounding.