In AppDaemon persist self-created sensor

I have a section in my code on startup

self.set_state("sensor.my_weather_symbol", state = "Cloudy")

In the appdaemon logs, am seeing:

> 2020-09-03 08:29:17.727724 WARNING my app: my app: Entity sensor.my_weather_symbol not found in namespace default
> 2020-09-03 08:29:17.728126 INFO AppDaemon: my app: Entity sensor.my_weather_symbol created in namespace: default

Is it possible to have a diy sensor persisted between restarts? It’s no big deal, just that if the entity is added to customize.yaml, e.g:

>   sensor.my_weather_symbol:
>     icon: mdi:weather-partly-snowy-rainy 

The icon gets wiped after restart.
Apologies if this was asked already, can’t find anything in documentation or community.

It will not persist, but you can set the icon and other attributes in the self.set_state() call:

        attributes = {}
        attributes['icon'] = 'mdi:weather-partly-snowy-rainy'
        attributes['another_attribute'] = "my other attribute"
        self.set_state("sensor.my_weather_symbol", state = "Cloudy", attributes=attributes )

This way, the icon will always be there. Remember to include the attributes every time you call self.set_state() as the attributes are also not persistent and will be removed if you just call self.set_state("sensor.my_weather_symbol", state = "Cloudy") without the attributes.

That is a good solution. And using that, the icon can be dynamic depending on the state value. Thanks very much.