The syntax for float is float(default). So, if there is an invalid numeric state (such as unavailable) from the sensor, you won’t get an error. But, you will get invalid data.
What is your preference is the question I guess.
As far as a value lower than one, that will take an if statement.
Or, something like that. Understand that I am “working” so I can’t validate that as I don’t have access to HA on my work computer. So, I could not test it.
But, is that really what you want? If less than 1, output 1, else output calculation? I haven’t tried to decipher what you are doing. Just looking at it syntactically.
this is a script measuring COP for a Heat Pump converted from an air conditioner. And it works properly. But the annoying thing is that when the Heat Pump is not working, it keeps counting and comes up with values like 0.988467823485477 kW and 160 kW, which may confirm the correctness of the calculations, but they are unnecessary. The question was only created for cosmetic purposes.
Thank you for your help