First to explain what I am trying to do:
I have a KASA power monitoring smart plug that I have connected my AC to. I have learned that it’s not a good idea to abruptly turn off the power while the compressor is still working, and best to turn the plug off when the compressor is off, in another words when power draw is 0 amps. Therefore I want to have a trigger, a helper button most likely to, and then having a wait templete waiting until the amp draw is 0, then executing the next executing the next action to turn off the plug.
The issue:
I run the following code in developer tools template and always get “False”, even though the sensor reads 0.00:
Ensure you have the correct spelling of the sensor’s entity_id and the attribute’s name. If you have misspelled either one, the state_attr() function will report none.
Every entity’s state value is a string (i.e. text). Even if it looks like a number, it’s still handled as a string.
In order to compare one number to another, you must ensure both are truly numbers; you can’t compare a string to a number. That’s why the template uses the int() filter to convert the string to an integer before it compares the result to 0.
The 0 in int(0) is the default value. If int is unable to convert the sensor’s state value to an integer, it will report whatever is set as the default value (in this example the default value has been set to 0).