How to integrate a python script into homeassitant

my intent is to create a card in my homeassistant dashboard that shows the level of my water tank.
For that, I bought an ultrasonic sensor (HC-SR04) and set it up with my raspberry pi 2 model B and wrote the code to return the distance (in CM) from the sensor.

Any help how to do it in homeassistant supervisor.

thanks in advance

Send the values as mqtt messages.

There are mqtt broker addons.

the code is stored in a python file.
can you guide me more on how to do it?

You are welcome to take a look at some Python code I wrote that uses paho mqtt client to send sensor data to an MQTT Broker. The code is in Just search on “mqtt” and “publish”. This code pulls in the mqtt config from a yaml file config.yaml (you can skip the yaml and set it directly inside your Python code if you want to).