I have an energy sensor to track my EV charging and want to create a template sensor that multiplies the kwh value of the sensor by the price-per-kwh value of an energy tarriff sensor. The resulting sensor is giving a value of ‘Unavailable’. I’m not a pro at this. Can anyone spot my error in the below yaml?
Avoid using states.sensor.temperature.state , instead use states('sensor.temperature') . It is strongly advised to use the states() , is_state() , state_attr() and is_state_attr() as much as possible, to avoid errors and error message when the entity isn’t ready yet (e.g., during Home Assistant startup).
And, before doing maths on sensors states, get them to float, you will do maths between floats and you will get floats at the end.
And don’t forget the default value for float filter => float(value, default)
Thanks so much for the detailed reply. Your changes seem to have fixed the ‘Unavailable’ problem. I’m now seeing a 0.0 GBP value but given that the energy sensor state is 53 (referring to kwh this week) it should have a value now. If relevant the dev console calls the value “state_class: total_increasing” - does that change the way I need to work with it?
And if anyone is interested I used the excellent ‘powercalc’ integration (in HACS) to create the energy sensor entity used in this cost sensor since my EV charger has no HA integration.