Create an entity for a python script

I made a python script that gets some numerical data from a website.
I would like to create an entity with attributes filled with python output.
Is it possibile ?

Right now I was thinking to put in cron the script and write the output in a file JSON, then create 7 different sensors file to fetch the data from the file.

There is a better solution ?

Thanks

hass.states.set(entity_id, 'state', attributes)

where attributes is a dictionary of attributes.

This of course is assuming you are talking about the python_script integration. If you are talking about a random python script that you made… You might want to consider different ways of getting the information into home assistant. There’s many integration options that probably do what your python script does.

Thanks @petro,
indeed, is a random python script! :slightly_smiling_face:
I will look and the python_script integration but if you have other suggestions, they are welcome!

I think you can use the command_line sensor.

1 Like

If you import anything, python_script component won’t work for you. That environment is very limited.

pyscript can probably do that…

pyscript didn’t exist when this thread was created…

you’re right!