Automatically customize configuration.yaml with add-on

Hi!

I managed to develop and run my own custom add-on by following the official tutorial.
When installed and run, my add-on will start a simple webserver on port 8000. I also created a restful sensor within my HA installation, that will periodically fetch data from this server.

I already managed to do so by editing my configuration.yaml:

rest:
  - resource: http://homeassistant.local:8000/calculate
    scan_interval: 3600
    sensor:
      - name: "My Sensor"
        value_template: "{{ value_json[0].size }}"

It feels a bit dirty to manually add this code to global configuration because it is a hard dependency to my add-on: if I add the code and my add-on is inactive, calculation will fail. Or if my add-on is running but someday I forget to add the sensor in configuration.yaml it won’t be available.

What I’m thinking about is a possibility to automatically add the sensor when the add-on is installed/activated and remove it when it is uninstalled/deactivated. Is there any way to do so?

Best regards
pschild