Need help with python_scripts

Hi.
You need to read data from the I2C bus and assign the data to the sensor. On the basis of the file x728bat.py (https://github.com/geekworm-com/x728/blob/5f1e744a5b3866a2e1c3a247ddadb692aa010523/x728.sh#L154) wrote the scripts.

#import struct
#import smbus
# import sys
# import time

DEVICE_BUS = 1
DEVICE_ADDRESS = 0x36
#bus = smbus.SMBus(DEVICE_BUS)

#read = bus.read_word_data(DEVICE_ADDRESS, 2)
#swapped = struct.unpack("<H", struct.pack(">H", read))[0]
#voltage = swapped * 1.25 /1000/16

inputAttributesObject = {}
inputState = 0
# inputState = voltage
hass.states.set('sensor.x728_voltage', inputState, inputAttributesObject)

But it doesn't work. If you apply it as it is written, the sensor.x728_voltage is created equal to 0. if you remove any # sensor, sensor.x728_voltage is not created.
What is the problem?

You can’t import anything in the python_script environment. That’s ultimately your problem.

So you also have the Geekworm X728 UPS Hat, did you find a way to get this to work?

I just started my HA on my RPi and this is my first mission.

No, I couldn’t.