Pyscript - new integration for easy and powerful Python scripting

I reached this integration looking for a way to dynamically create sensors based on a variable attribute… any idea if I could pull this off with pyscript?

I have a sensor that comes with an attribute that is an array of N elements, i.e.

[
{ name: "John Doe", age: 34, height: 177 },
{ name: "Joanne Doe", age: 37, height: 165 }
]

I would like to have one sensor created for each of those N elements, so for the above example, I’d have a sensor named John Doe with state 34 and an attribute height: 177, and equivalently for Joanne Doe, and for any other that may come on the initial attribute…

Any advice or hint?

Thank you!!

Has anyone had luck getting autocomplete working for the Jupyter notebook in PyCharm?

Hi, did you ever manage to get this working? I’m also trying to get autocomplete working in PyCharm, but no luck so far.

I ended up just using this project as I never had any luck

Its not great since you have to have commented out working imports and fake imports but better than nothing

I am hoping to automatically reload an integration that has become ‘unavailable’. It looks like the easiest way to do that is to call

homeassistant.reload_config_entry( config_entry_id( entity_id ) )

However, with in my pyscript, I get:

NameError: name ‘config_entry_id’ is not defined

I tried prefixing config_entry_id with homeassistant, but that just results in:

NameError: name ‘homeassistant.config_entry_id’ is not defined

Any help appreicated!

For reference:

https://community.home-assistant.io/t/how-to-automatically-reload-integration-on-a-schedule/571065/19

Found a better solution to solve the autocomplete issue without having to change imports when on the server

try:
    # IDE imports
    from pyscript.modules.services.notifications.models import NotificationData, AndroidParameters, IOSParameters, \
        AndroidChronometer, AndroidProgressNotification, NotificationAction, ActionableNotificationData, \
        AndroidTTSConfiguration
    from pyscript.modules.services.notifications.device_manager import DeviceManager
    from pyscript.modules.services.notifications.enums import AndroidImportance, AndroidVisibility, \
        IOSInterruptionLevel, IOSPresentationOption, AndroidTTSMediaStream
    from pyscript.pyscript_mock import *
except (ImportError, AttributeError) as exception:
    # PyScript imports
    from services.notifications.models import NotificationData, AndroidParameters, IOSParameters, AndroidChronometer, \
        AndroidProgressNotification, NotificationAction, ActionableNotificationData, AndroidTTSConfiguration
    from services.notifications.device_manager import DeviceManager
    from services.notifications.enums import AndroidImportance, AndroidVisibility, IOSInterruptionLevel, \
        IOSPresentationOption, AndroidTTSMediaStream


class NotificationManager:
    """Manages Home Assistant mobile app notifications."""

Hi there,

I’m writing a script that needs to import either lightgbm or scikit-learn. Former is preferred.

I first tried adding lightgbm to requirements.txt, but got this error in the logs:

2025-09-12 23:09:50.246 ERROR (SyncWorker_3) [homeassistant.util.package] Unable to install package lightgbm: × Failed to build `lightgbm==4.6.0`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `scikit_build_core.build.build_wheel` failed (exit status: 1)
      [stderr]
      2025-09-12 23:09:50,162 - scikit_build_core - INFO - RUN:
      /tmp/.tmphLEqcO/builds-v0/.tmpp1MQQh/lib/python3.13/site-packages/cmake/data/bin/cmake
      -E capabilities
      2025-09-12 23:09:50,162 - scikit_build_core - WARNING - Permissions
      Error getting CMake's version
      Traceback (most recent call last):
        File "<string>", line 11, in <module>
          wheel_filename =
      backend.build_wheel("/tmp/.tmphLEqcO/builds-v0/.tmpmeEcVF", {}, None)
        File
      "/tmp/.tmphLEqcO/builds-v0/.tmpp1MQQh/lib/python3.13/site-packages/scikit_build_core/build/__init__.py",
      line 33, in build_wheel
          return _build_wheel_impl(
                 ~~~~~~~~~~~~~~~~~^
              wheel_directory,
              ^^^^^^^^^^^^^^^^
          ...<2 lines>...
              editable=False,
              ^^^^^^^^^^^^^^^
          ).wheel_filename
          ^
        File
      "/tmp/.tmphLEqcO/builds-v0/.tmpp1MQQh/lib/python3.13/site-packages/scikit_build_core/build/wheel.py",
      line 176, in _build_wheel_impl
          return _build_wheel_impl_impl(
              wheel_directory,
          ...<5 lines>...
              pyproject=pyproject,
          )
        File
      "/tmp/.tmphLEqcO/builds-v0/.tmpp1MQQh/lib/python3.13/site-packages/scikit_build_core/build/wheel.py",
      line 248, in _build_wheel_impl_impl
          cmake = CMake.default_search(version=settings.cmake.version,
      env=os.environ)
        File
      "/tmp/.tmphLEqcO/builds-v0/.tmpp1MQQh/lib/python3.13/site-packages/scikit_build_core/cmake.py",
      line 67, in default_search
          raise CMakeNotFoundError(msg)
      scikit_build_core.errors.CMakeNotFoundError: Could not find CMake with
      version >=3.28
      hint: This usually indicates a problem with the package or the build
      environment.

I then tried using scikit-learn instead, and got the following error:

2025-09-12 23:18:59.197 ERROR (SyncWorker_0) [homeassistant.util.package] Unable to install package scikit-learn: × Failed to build `scikit-learn==1.7.2`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `mesonpy.build_wheel` failed (exit status: 1)
      [stderr]
      Traceback (most recent call last):
        File "<string>", line 11, in <module>
          wheel_filename =
      backend.build_wheel("/tmp/.tmpgsJJJY/builds-v0/.tmpfKJsBv", {}, None)
        File
      "/tmp/.tmpgsJJJY/builds-v0/.tmpT0aAkN/lib/python3.13/site-packages/mesonpy/__init__.py",
      line 1144, in wrapper
          return func(*args, **kwargs)
        File
      "/tmp/.tmpgsJJJY/builds-v0/.tmpT0aAkN/lib/python3.13/site-packages/mesonpy/__init__.py",
      line 1197, in build_wheel
          with _project(config_settings) as project:
               ~~~~~~~~^^^^^^^^^^^^^^^^^
        File "/usr/local/lib/python3.13/contextlib.py", line 141, in __enter__
          return next(self.gen)
        File
      "/tmp/.tmpgsJJJY/builds-v0/.tmpT0aAkN/lib/python3.13/site-packages/mesonpy/__init__.py",
      line 1063, in _project
          yield Project(source_dir, build_dir, meson_args, editable_verbose)
                ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File
      "/tmp/.tmpgsJJJY/builds-v0/.tmpT0aAkN/lib/python3.13/site-packages/mesonpy/__init__.py",
      line 673, in __init__
          self._meson = _get_meson_command(pyproject_config.get('meson'))
                        ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File
      "/tmp/.tmpgsJJJY/builds-v0/.tmpT0aAkN/lib/python3.13/site-packages/mesonpy/__init__.py",
      line 1100, in _get_meson_command
          r = subprocess.run(cmd + ['--version'], text=True,
      capture_output=True)
        File "/usr/local/lib/python3.13/subprocess.py", line 554, in run
          with Popen(*popenargs, **kwargs) as process:
               ~~~~~^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/local/lib/python3.13/subprocess.py", line 1039, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
          ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                              pass_fds, cwd, env,
                              ^^^^^^^^^^^^^^^^^^^
          ...<5 lines>...
                              gid, gids, uid, umask,
                              ^^^^^^^^^^^^^^^^^^^^^^
                              start_new_session, process_group)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/local/lib/python3.13/subprocess.py", line 1972, in
      _execute_child
          raise child_exception_type(errno_num, err_msg, err_filename)
      PermissionError: [Errno 13] Permission denied: 'meson'
      hint: This usually indicates a problem with the package or the build
      environment.

Any idea what I’m doing wrong here?

Thanks!

This topic has come up before, but I started using VS Code for pyscript development especially now with Co-Pilot, it is so much better compared to developing in a Jupyter notebook. I did get the remote hass kernel configured and running in VS Code, however, what is really missing is IntelliSense autocompletion for e.g. entities, functions, etc. coming from the hass kernel. Jupyter Notebook supports that, but unfortunately there does not seem to be a solution for VS Code, yet? Does anyone have any pointers?

This is what you’re looking for: GitHub - dmamelin/pyscript_autocomplete

Update - auto complete is now part of pyscript, see PR 771. It’s not released yet, but you can try it by running the head version from github.

1 Like

New HA user here. Not sure if this is the correct place to post and sorry if I break any ‘rules’.
I am writing a scheduler to turn on my EV charge plug based on cheapest energy tariff timings. I have the scheduled slots calculated and their time ON/OFF are stored and used as input to task.wait_until() as follows…

    start_dt = datetime.fromisoformat(m["start"]) 
    end_dt = datetime.fromisoformat(m["end"]) 

    task.wait_until(time_trigger=start_dt.strftime("%Y-%m-%d %H:%M:%S"))
    service.call("switch", "turn_on", entity_id=CHARGER)

    task.wait_until(time_trigger=end_dt.strftime("%Y-%m-%d %H:%M:%S"))
    service.call("switch", "turn_off", entity_id=CHARGER)

My problem is that the error log gives

2025-12-29 16:27:45.440 WARNING (MainThread) [custom_components.pyscript.trigger] Can't parse 2025-12-30 04:30:00 in time_trigger check

I have tried all I can think of to format the time but to no avail! What am I doing wrong = probably something stupid? Any suggestions gratefully accepted.
In the meantime I have written a subroutine which calculates the time interval from now till the schedule time and then uses time.sleep() but I am not sure if this is good practice?

Thanks in advance…

The date-time format is ISO: yyyy/mm/dd hh:mm:ss. So try replacing “-” with “/” in your strftime calls.

Thanks @craigb
As you noted the docs (for @time_trigger which task.wait_until point you to) say

Several of the time specifications use a datetime format, which is ISO: yyyy/mm/dd hh:mm:ss

So I changed to this format but still got the error…

2025-12-30 17:25:29.219 WARNING (MainThread) [custom_components.pyscript.trigger] Can't parse 2025/12/31 22:30:00 in time_trigger check

I have fiddled around with this for another couple of hours but no luck. So unless you or anyone else has any brilliant ideas I will have to stick to my alternative solution of calculating the time difference and using time.sleep()

Thanks for your input