About the Scripts category

Want to share your scripts? Do it here!

The Python script was introduced in 0.47. The scripts are exposed as services and could help you to do improve your setup.

Give some feedback if you want!

How can you import python modules in the scripts used by the new python_script component? Seems like it is not allowed, which limits this component in my opinion.

Im trying to pass data to a script in json format, but can’t import the json module to further process the data.

What do I need to modify in the python_script component to allow import and open/write to files? (thinking of just creating a custom module).

Ditto re MQTT MQTT with Python Script component

Overall the python script feature looks interesting, but I’m still trying to get a handle on what’s allowed and what is not. For example, I tried the following and got an error

def a():
  pass

def b():
  pass
  a()

a()
b()

File “house_demo.py”, line 33, in b
NameError: name ‘a’ is not defined.

It seems like I can define a() and use a() from the mainline, but I can’t define and use b() which calls a().

Is there a guide somewhere to help understand what’s allowed and what is not?

Thank you.

Charles

1 Like

Very nice feature.

Feedback:
Would be nice to be able perform some delays in python scipts,

Regards,
Adam

Agreed. Some reasonable method of doing a short delay is often necessary when turning on or off several switches in a sequence (and probably for other things as well). I fully understand the need to restrict what can be done in these scripts, and I realize that long delays should be avoided, but no delay optional at all is a pretty severe limitation for an otherwise very useful HA extension.

2 Likes