You’re converting two strings to floats, which since they can’t be interpreted as floats, the float filter is returning zero for each. Zero minus zero is zero.
First, all states are strings, even if they look like something else. Second, you’re not using the state of the entity in your template. You’re using a string: ('sensor.energy_meter_mains_power') | float
You’re trying to convert the string 'sensor.energy_meter_mains_power' to a float, not the state of the sensor.energy_meter_mains_power entity. See the doc page I pointed you to to see how to get the state of an entity using its entity_id.
thanks Phil, I was not aware that values are always stings.
The below is working, but I am getting several decimal places like the below. The round(1) commands are not enough?
You’ve been bit by the “floats don’t have infinite precision” fact. First, you don’t need to round each term of the equation, you can round the sum, which is probably better anyway. But, still, this can happen. What you really need to do is not round, but specify an output format. E.g.: