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.