Also, note from the documentation that you may want to consider using is_state instead because it will not create an error if the component your sensor uses hasn’t fully loaded at startup. In this case you would use:
I tried your code but not working. As I 've just know may be the Lovelace UI cannot accept to change the icon depend on the state. May be I have to create new sensor template with icon on it and after that use Lovelace to show the sensor.
From your original post I didn’t realize this was in your Lovelace config - yes I would probably make a template sensor with this if the sensor itself doesn’t support icon templates.