Hello everyone. New to Home Assistant here, but trying to learn rapidly.
I have an issue where I am trying to do math on electricity usage based on a varying tariff. This part is done and working great. However, the output from these sensors is a string with data that I need to strip out before doing math. Not an issue here either… but, in order to convert the string to an integer, I need to remove the decimal place. Otherwise, it doesn’t convert to an integer.
Ok, so I updated some of the code to get the result to change (making it easier to see the string data) using your suggestion. My output from this is now .2. But, I still have to strip that decimal place to convert it to an integer…
You don’t have to strip the decimal, if you do then there’s something else. As you can see from my example, I passed a string with a decimal and here’s the output:
Interesting… maybe I am doing the math wrong then? I get the simple value of .2 and .01 as an output state from the two sensors. When I don’t convert them to an int, and just do the math with the below code, this is what I get:
If I convert to an integer, I have to strip the decimal place to do the math. Otherwise, the math just puts the two results next to eachother “0.20” and “0.01”
Wow I actually have a reason now to use live chat, LOL. I though it was the most worthless feature on this forum upgrade, but I guess there is a use for it after all
This is how we resolved it in live chat. The problem is each of those strings needed converted to float so you can add them, he was concatenating them because they were strings, then trying to strip it down to a number from there.
I use float(‘sensor…’, 0) instead of ‘sensor…’ | float just to avoid math errors if it’s unavailable, it’ll default to 0. After being bit by this numerous times it’s how I always do floats now. Everyone has there own way, I’m sure, this is mine