-
Notifications
You must be signed in to change notification settings - Fork 58
scripts organization #747
-
Hello all.
How can I organize my scripts in subfolders of /pyscript?
I have PyScript 1.6.4 in HA 2025年8月1日 working fine. The initial scripts are all in /pyscript. If I move them to a subfolder under pyscript, say pyscript/scripts or pyscript/folder1 or pyscript/scripts/folder1, and reload pyscript I see in logs that the file is loaded fine. When I invoke it from Developer Tools->Action, I get:
2025年08月19日 14:38:02.651 INFO (MainThread) [custom_components.pyscript.global_ctx] Reloaded /config/pyscript/scripts/list_unique_light_details.py
2025年08月19日 14:38:24.956 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script
2025年08月19日 14:38:24.956 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service
2025年08月19日 14:38:24.957 INFO (MainThread) [custom_components.pyscript.scripts.list_unique_light_details.list_unique_light_details] 📊 Starting to list unique light device details...
2025年08月19日 14:38:24.958 WARNING (MainThread) [custom_components.pyscript.scripts.list_unique_light_details.list_unique_light_details] Light device details cache is empty. Attempting to refresh it now...
2025年08月19日 14:38:24.958 ERROR (MainThread) [custom_components.pyscript.scripts.list_unique_light_details.list_unique_light_details] Exception in <scripts.list_unique_light_details.list_unique_light_details> line 22:
await pyscript.call_service("pyscript.extract_light_entity_and_device_details")
^
NameError: name 'pyscript.call_service' is not defined
If I add an "import pyscript", I get:
2025年08月19日 14:40:42.837 ERROR (MainThread) [custom_components.pyscript.scripts.list_unique_light_details.list_unique_light_details] Exception in <scripts.list_unique_light_details.list_unique_light_details> line 22:
await pyscript.call_service("pyscript.extract_light_entity_and_device_details")
^
AttributeError: module 'pyscript' has no attribute 'call_service'
If I add an "from pyscript import ( call_service )", I get:
2025年08月19日 14:44:10.472 ERROR (MainThread) [custom_components.pyscript.scripts.list_unique_light_details] Exception in </config/pyscript/scripts/list_unique_light_details.py> line 1:
from pyscript import (service)
^
AttributeError: module 'pyscript' has no attribute 'service'
2025年08月19日 14:44:32.847 ERROR (MainThread) [custom_components.pyscript.scripts.list_unique_light_details] Exception in </config/pyscript/scripts/list_unique_light_details.py> line 1:
from pyscript import (call_service)
^
AttributeError: module 'pyscript' has no attribute 'call_service'
Beta Was this translation helpful? Give feedback.
All reactions
pyscript module has no such method as call_service
. the services are called the way described in the documentation https://hacs-pyscript.readthedocs.io/en/stable/reference.html#calling-services
if you want to call pyscript.extract_light_entity_and_device_details
call it using pyscript.extract_light_entity_and_device_details()
Replies: 1 comment 5 replies
-
pyscript module has no such method as call_service
. the services are called the way described in the documentation https://hacs-pyscript.readthedocs.io/en/stable/reference.html#calling-services
if you want to call pyscript.extract_light_entity_and_device_details
call it using pyscript.extract_light_entity_and_device_details()
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you so much for the super prompt answer. Much appreciated.
That worked. I have other problem that showed up, but I can debug myself a bit.
I am curious, why does call_service work when the script is directly in /pyscript?
Beta Was this translation helpful? Give feedback.
All reactions
-
I am curious, why does call_service work when the script is directly in /pyscript?
it doesn't
2025-08-19 17:55:15.746 ERROR (MainThread) [custom_components.pyscript.file._tryouts] Exception in </config/pyscript/_tryouts.py> line 4: from pyscript import call_service ^ AttributeError: module 'pyscript' has no attribute 'call_service'
As the documentation states, these are the ways to call a certain service:
service.call("DOMAIN", "SERVICE", entity_id="DOMAIN.ENTITY", other_param=123) # E.g. service.call("light", "turn_off", entity_id="light.office") # E.g. service.call("pyscript", "extract_light_entity_and_device_details") DOMAIN.SERVICE(entity_id="DOMAIN.ENTITY", other_param=123) # E.g. pyscript.extract_light_entity_and_device_details() DOMAIN.ENTITY.SERVICE(other_param=123) # non-applicable in your call
Beta Was this translation helpful? Give feedback.
All reactions
-
I will use the recommended method. Let me rephrase. Without any import statements, with the script in the base config/pyscript directory and with the pyscript.call_service("extract_light_entity_and_device_details") actually does execute fine and provides the expected output. I don't need that to work, I am just curious.
Beta Was this translation helpful? Give feedback.
All reactions
-
this cannot work.
code:
@service def tryouts(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs): pyscript.call_service('tryouts1') @service def tryouts1(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs): pass
call: pyscript.tryouts
result:
2025-08-19 18:06:05.229 ERROR (MainThread) [custom_components.pyscript.file._tryouts.tryouts] Exception in <file._tryouts.tryouts> line 11: pyscript.call_service('tryouts1') ^ NameError: name 'pyscript.call_service' is not defined
Beta Was this translation helpful? Give feedback.
All reactions
-
You are right. I can no longer reproduce it. I must have had an old version lying around with that code, but I likely hadn't run that particular version. Thanks for your help.
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1