@@ -3,82 +3,18 @@ Pyscript: Python Scripting for Home Assistant
33
44|GitHub Release | |License | |hacs | |Project Maintenance |
55
6- Overview
7- --------
8-
9- This HACS custom integration allows you to write Python functions and
10- scripts that can implement a wide range of automation, logic and
11- triggers. State variables are bound to Python variables and services are
12- callable as Python functions, so it’s easy and concise to implement
13- logic.
14-
15- Functions you write can be configured to be called as a service or run
16- upon time, state-change or event triggers. Functions can also call any
17- service, fire events and set state variables. Functions can sleep or
18- wait for additional changes in state variables or events, without
19- slowing or affecting other operations. You can think of these functions
20- as small programs that run in parallel, independently of each other, and
21- they could be active for extended periods of time.
22-
23- State, event and time triggers are specified by Python function
24- decorators (the “@” lines immediately before each function definition).
25- A state trigger can be any Python expression using state variables - the
26- trigger is evaluated only when a state variable it references changes,
27- and the trigger occurs when the expression is true or non-zero. A time
28- trigger could be a single event (eg: date and time), a repetitive event
29- (eg: at a particular time each day or weekday, daily relative to sunrise
30- or sunset or any regular time period within an optional range) or using
31- cron syntax (where events occur periodically based on a concise
32- specification of ranges of minutes, hours, days of week, days of month
33- and months). An event trigger specifies the event type, and an optional
34- Python trigger test based on the event data that runs the Python
35- function if true.
36-
37- Pyscript implements a Python interpreter using the ast parser output, in
38- a fully async manner. That allows several of the “magic” features to be
39- implemented in a seamless Pythonic manner, such as binding of variables
40- to states and functions to services. Pyscript supports imports, although
41- by default the valid import list is restricted for security reasons
42- (there is a configuration option ``allow_all_imports `` to allow all
43- imports). Pyscript supports all language features except generators and
44- ``yield ``. Pyscript provides a handful of additional built-in functions
45- that connect to HASS features, like logging, accessing state variables
46- as strings (if you need to compute their names dynamically), sleeping
47- and waiting for triggers.
48-
49- Pyscript also provides a kernel that interfaces with the Jupyter
50- front-ends (eg, notebook, console and lab). That allows you to develop
51- and test pyscript code interactively. Plus you can interact with much of
52- HASS by looking at state variables, calling services etc, in a similar
53- way to `HASS
54- CLI <https://github.com/home-assistant-ecosystem/home-assistant-cli> `__,
55- although the CLI provides status on many other parts of HASS.
56-
57- For more information about the Jupyter kernel, see the
58- `README <https://github.com/craigbarratt/hass-pyscript-jupyter/blob/master/README.md >`__.
59- There is also a `Jupyter notebook
60- tutorial <https://nbviewer.jupyter.org/github/craigbarratt/hass-pyscript-jupyter/blob/master/pyscript_tutorial.ipynb> `__,
61- which can be downloaded and run interactively in Jupyter notebook
62- connected to your live HASS with pyscript.
63-
64- Pyscript provides functionality that complements the existing
65- automations, templates and triggers. Pyscript is most similar to
66- `AppDaemon <https://appdaemon.readthedocs.io/en/latest/ >`__, and some
67- similarities and differences are discussed in this `Wiki
68- page <https://github.com/custom-components/pyscript/wiki/Comparing-Pyscript-to-AppDaemon> `__.
69- Pyscript with Jupyter makes it extremely easy to learn, use and debug.
70- Pyscripts presents a simplified and more integrated binding for Python
71- scripting than `Python
72- Scripts <https://www.home-assistant.io/integrations/python_script> `__,
73- which requires a lot more expertise and scaffolding using direct access
74- to Home Assistant internals.
6+ This HACS custom integration for Home Assistant allows you to write Python functions
7+ and scripts that can implement a wide range of automation, logic and triggers.
8+ State variables are bound to Python variables and services are callable as Python
9+ functions, so it’s easy and concise to implement logic.
7510
7611Contents
7712~~~~~~~~
7813
7914.. toctree ::
8015 :maxdepth: 3
8116
17+ overview
8218 installation
8319 configuration
8420 tutorial
0 commit comments