One thing missing from pyscript compared with regular home assistant scripts and automations is access to the capabilities provided by the jinja template extensions such as working with areas and devices. As described in #251, it is possible to provide pyscript access to the template functions. The following code exposes all functions that take the hass object (https://www.home-assistant.io/docs/configuration/templating/).
With the following in modules/template.py and after import template you can call any of these functions like template.device_entities(device_id).
This is pretty generic, easily maintainable, and feels like it should be part of pyscript core. It would eliminate a large part of the need to enable access to hass as a global variable or allowing all imports and makes it more straightforward to port any existing automation to pyscript.
One thing missing from pyscript compared with regular home assistant scripts and automations is access to the capabilities provided by the jinja template extensions such as working with areas and devices. As described in #251, it is possible to provide pyscript access to the template functions. The following code exposes all functions that take the hass object (https://www.home-assistant.io/docs/configuration/templating/).
With the following in
modules/template.py
and afterimport template
you can call any of these functions liketemplate.device_entities(device_id)
.This is pretty generic, easily maintainable, and feels like it should be part of pyscript core. It would eliminate a large part of the need to enable access to hass as a global variable or allowing all imports and makes it more straightforward to port any existing automation to pyscript.