### Manual Pyscript Installation (Bash) Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/installation.rst This snippet provides bash commands for manually installing Pyscript. It covers downloading the latest release zip file and extracting it into the Home Assistant custom components directory. An alternative method using git clone is also shown for installing the master version. ```bash cd YOUR_HASS_CONFIG_DIRECTORY # same place as configuration.yaml mkdir -p custom_components/pyscript cd custom_components/pyscript unzip hass-custom-pyscript.zip ``` ```bash mkdir SOME_LOCAL_WORKSPACE cd SOME_LOCAL_WORKSPACE git clone https://github.com/custom-components/pyscript.git mkdir -p YOUR_HASS_CONFIG_DIRECTORY/custom_components cp -pr pyscript/custom_components/pyscript YOUR_HASS_CONFIG_DIRECTORY/custom_components ``` -------------------------------- ### PyScript Setup Triggers Example Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Python code snippet demonstrating how to iterate over pyscript application configurations and set up triggers using a helper function. This code assumes 'pyscript.app_config' is populated. ```python def setup_triggers(room=None, level=None, some_list=None): # # define some trigger functions etc # pass for inst in pyscript.app_config: setup_triggers(**inst) ``` -------------------------------- ### Pyscript YAML Configuration Example Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Provides an example of a `yaml` configuration file for Pyscript, demonstrating settings for applications like `auto_lights` and `motion_light`, as well as global settings. ```yaml pyscript: allow_all_imports: true apps: auto_lights: - room: living level: 60 some_list: - 1 - 20 - room: dining level: 80 some_list: - 1 - 20 motion_light: - sensor: rear_left light: rear_flood - sensor: side_yard light: side_flood - sensor: front_patio light: front_porch global: setting1: 10 setting2: true ``` -------------------------------- ### PyScript Configuration Example Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Example of a PyScript configuration file for the 'service_checker' app, demonstrating how to include service names, URLs, and API keys, with secrets being loaded using '!secret'. ```yaml pyscript: allow_all_imports: true apps: service_checker: - service_name: my_service url: !secret my_secret_url api_key: !secret my_secret_api_key ``` -------------------------------- ### Example Pyscript Configuration File Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst This YAML content represents an example 'pyscript/config.yaml' file, defining global settings and application-specific configurations. It shows how to structure settings when using the include directive. ```yaml allow_all_imports: true apps: my_app1: # any settings for my_app1 go here my_app2: # any settings for my_app2 go here ``` -------------------------------- ### Download pyscript Jupyter Tutorial Notebook Source: https://hacs-pyscript.readthedocs.io/en/stable/tutorial This command downloads the pyscript Jupyter tutorial notebook from GitHub. It requires `wget` to be installed on your system. The output is the notebook file itself. ```bash wget https://github.com/craigbarratt/hass-pyscript-jupyter/raw/master/pyscript_tutorial.ipynb ``` -------------------------------- ### Call the PyScript hello_world Service Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/tutorial.rst Example of how to call the 'pyscript.hello_world' service using Home Assistant's Developer Tools. This demonstrates passing 'action' and 'id' parameters. ```yaml action: pyscript.hello_world data: action: hello id: world ``` -------------------------------- ### Download and Open Jupyter Tutorial for PyScript Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/tutorial.rst Instructions to download and open an interactive Jupyter tutorial for learning PyScript. This requires wget and Jupyter notebook to be installed. ```bash wget https://github.com/craigbarratt/hass-pyscript-jupyter/raw/master/pyscript_tutorial.ipynb jupyter notebook pyscript_tutorial.ipynb ``` -------------------------------- ### Open pyscript Jupyter Tutorial Notebook Source: https://hacs-pyscript.readthedocs.io/en/stable/tutorial This command opens the downloaded pyscript Jupyter tutorial notebook using the Jupyter notebook interface. It requires Jupyter to be installed. The output is the interactive notebook environment. ```bash jupyter notebook pyscript_tutorial.ipynb ``` -------------------------------- ### MQTT Trigger Example: Carport Motion Light Automation Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst This example demonstrates using @mqtt_trigger to monitor Zigbee2MQTT motion detection. When motion is detected on a specific topic and the payload indicates occupancy, it turns on a light for 5 minutes and then turns it off. It also uses @time_active to ensure the automation only runs during specific times. ```python @mqtt_trigger('zigbee2mqtt/motion.carport', "payload_obj['occupancy'] != None") @time_active("range(sunset - 30m, sunrise - 30m)") def carport_motion(): light.turn_on(entity_id="light.carport") task.sleep(300) light.turn_off(entity_id="light.carport") ``` -------------------------------- ### Using Pyscript State Functions for Dynamic Access Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst This Python code showcases the use of Pyscript's built-in state functions for more dynamic interaction with Home Assistant state variables. It includes examples of getting a state variable, checking its existence, getting an attribute, and setting a state variable, providing flexibility for complex scenarios. ```python # Get state variable current_temp = state.get('sensor.livingroom_temperature') # Check if state variable exists if state.exist('binary_sensor.door'): pass # Get attribute current_battery_level = state.getattr('device_tracker.phone', 'battery') # Set state variable state.set('input_text.my_text', 'New value') # Set attribute state.setattr('light.hallway', 'color_temp', 300) ``` -------------------------------- ### Async HTTP GET Request with aiohttp Source: https://hacs-pyscript.readthedocs.io/en/stable/reference This snippet demonstrates how to perform an asynchronous HTTP GET request using the aiohttp library. It fetches the content of a README.md file from a URL and prints the response status and text. Ensure aiohttp is installed. ```python import aiohttp url = "https://raw.githubusercontent.com/custom-components/pyscript/master/README.md" async with aiohttp.ClientSession() as session: async with session.get(url) as resp: print(resp.status) print(resp.text()) ``` -------------------------------- ### Write a Basic PyScript Service: hello_world Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/tutorial.rst Example of a simple PyScript function registered as a service. It logs received actions and IDs, and can optionally turn on a light or fire an event. Requires Home Assistant and PyScript integration. ```python @service def hello_world(action=None, id=None): """hello_world example using pyscript.""" log.info(f"hello world: got action {action} id {id}") if action == "turn_on" and id is not None: light.turn_on(entity_id=id, brightness=255) elif action == "fire" and id is not None: event.fire(id, param1=12, param2=80) ``` -------------------------------- ### PyScript Automation with Unique Task Execution Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/tutorial.rst Improved PyScript example to ensure only one instance of the motion-activated light function runs at a time. It uses @state_trigger and @time_active decorators, similar to the previous example, but implies a mechanism for unique task handling which is not explicitly shown in the provided code. ```python @state_trigger("security.rear_motion == '1' or security.side_motion == '1'") @time_active("range(sunset - 20min, sunrise + 20min)") def motion_light_rear(): ``` -------------------------------- ### Example YAML Configuration for Pyscript Applications Source: https://hacs-pyscript.readthedocs.io/en/stable/reference Illustrates a typical YAML structure for Pyscript configurations, defining global settings and settings for multiple applications like `auto_lights` and `motion_light`. It also shows how to use `!secret` for sensitive information. ```YAML pyscript: allow_all_imports: true apps: auto_lights: - room: living level: 60 some_list: - 1 - 20 - room: dining level: 80 some_list: - 1 - 20 motion_light: - sensor: rear_left light: rear_flood - sensor: side_yard light: side_flood - sensor: front_patio light: front_porch global: setting1: 10 setting2: true service_checker: - service_name: my_service url: !secret my_secret_url api_key: !secret my_secret_api_key ``` -------------------------------- ### Example requirements.txt for Pyscript Packages Source: https://hacs-pyscript.readthedocs.io/en/stable/reference Illustrates the format of a `requirements.txt` file used by Pyscript to specify required Python packages. Each line can list a package name, optionally with a version specifier like `==`. Comments are supported. ```text # this is a comment aiohttp amazing_stuff==3.1 another_package==5.1.2 ``` -------------------------------- ### Python Code to Process Application Configuration Source: https://hacs-pyscript.readthedocs.io/en/stable/reference Provides a Python code snippet demonstrating how to iterate over `pyscript.app_config` to process individual application settings. This example assumes a `setup_triggers` function that accepts keyword arguments derived from the configuration. ```Python def setup_triggers(room=None, level=None, some_list=None): # Define trigger functions or application logic here # Example: print(f"Setting up trigger for room: {room}, level: {level}") pass # Ensure pyscript.app_config is available in this context # if 'pyscript' in locals() and hasattr(pyscript, 'app_config'): # for inst in pyscript.app_config: # setup_triggers(**inst) ``` -------------------------------- ### Pyscript Global Configuration Access (Python) Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Demonstrates how the complete Pyscript YAML configuration is made available in the global `pyscript.config` variable. This example shows the structure for the provided YAML. ```python { "allow_all_imports": True, "apps": { "auto_lights": [ {"room": "living", "level": 60, "some_list": [1, 20]}, {"room": "dining", "level": 80, "some_list": [1, 20]}, ], "motion_light": [ {"sensor": "rear_left", "light": "rear_flood"}, {"sensor": "side_yard", "light": "side_flood"}, {"sensor": "front_patio", "light": "front_porch"}, ], }, "global": { "setting1": 10, "setting2": True, }, } ``` -------------------------------- ### YAML Configuration in Included File for Pyscript Apps Source: https://hacs-pyscript.readthedocs.io/en/stable/reference This is an example of a `pyscript/config.yaml` file that is included by the main configuration. It defines application-specific settings for `my_app1` and `my_app2` under the `apps` key. ```yaml allow_all_imports: true apps: my_app1: # any settings for my_app1 go here my_app2: # any settings for my_app2 go here ``` -------------------------------- ### Event Trigger Example: Monitor Lights Turn On Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst This snippet shows how to use the @event_trigger decorator to monitor when the 'lights.turn_on' service is called. It logs the service data when triggered. This decorator requires the 'EVENT_CALL_SERVICE' event type and specific domain and service conditions. ```python @event_trigger(EVENT_CALL_SERVICE, "domain == 'lights' and service == 'turn_on'") def monitor_light_turn_on_service(service_data=None): log.info(f"lights.turn_on service called with service_data={service_data}") ``` -------------------------------- ### State Trigger Examples with String and Integer Comparisons Source: https://hacs-pyscript.readthedocs.io/en/stable/reference Demonstrates how to use the @state_trigger decorator with string comparisons and integer casting for state variable values. It highlights the importance of casting for numerical inequalities and potential exceptions with invalid integer strings. ```python @state_trigger("domain.light_level == '255' or domain.light2_level == '0'") ``` ```python @state_trigger("int(domain.light_level) == 255 or int(domain.light2_level) == 0") ``` -------------------------------- ### PyScript Automation with State and Time Triggers Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/tutorial.rst Example of a PyScript function that turns on a light when motion is detected and it's dark, then turns it off after a delay. Uses @state_trigger and @time_active decorators. Assumes Home Assistant entities like 'security.rear_motion' and 'light.outside_rear'. ```python @state_trigger("security.rear_motion == '1' or security.side_motion == '1'") @time_active("range(sunset - 20min, sunrise + 15min)") def motion_light_rear(): """Turn on rear light for 5 minutes when there is motion and it's dark""" log.info(f"triggered; turning on the light") light.turn_on(entity_id="light.outside_rear", brightness=255) task.sleep(300) light.turn_off(entity_id="light.outside_rear") ``` -------------------------------- ### Event Trigger Example: Monitor Service Calls Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst This snippet demonstrates how to use the @event_trigger decorator to monitor all Home Assistant service calls. It logs all received keyword arguments, which is useful for inspecting event data. This is a common pattern for debugging and understanding event payloads. ```python from homeassistant.const import EVENT_CALL_SERVICE @event_trigger(EVENT_CALL_SERVICE) def monitor_service_calls(**kwargs): log.info(f"got EVENT_CALL_SERVICE with kwargs={kwargs}") ``` -------------------------------- ### Pyscript 'hello_world' Service Example Source: https://hacs-pyscript.readthedocs.io/en/stable/tutorial A Python script defining a Home Assistant service named 'hello_world' using the pyscript decorator '@service'. It logs incoming service calls and can optionally turn on a light or fire an event based on provided parameters. Dependencies include the `log`, `light`, and `event` modules from pyscript. The function accepts `action` and `id` as keyword arguments. ```python @service def hello_world(action=None, id=None): """hello_world example using pyscript.""" log.info(f"hello world: got action {action} id {id}") if action == "turn_on" and id is not None: light.turn_on(entity_id=id, brightness=255) elif action == "fire" and id is not None: event.fire(id, param1=12, param2=80) ``` -------------------------------- ### Call a Home Assistant Service and Get Response Source: https://hacs-pyscript.readthedocs.io/en/stable/reference Shows how to call a Home Assistant service and retrieve its response by setting `return_response=True`. This feature is available starting from HASS 2023.7. ```python service_response = myservice.flash_light(light_name="front", light_color="red", return_response=True) ``` -------------------------------- ### Get All State Variable Names in Pyscript Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst This Python code demonstrates how to retrieve a list of all state variable names (entity IDs) within Home Assistant using the `state.names()` function. It shows how to get all entity IDs or filter them by a specific domain. ```python # Get all entity IDs all_entity_ids = state.names() # Get entity IDs for a specific domain climate_entity_ids = state.names(domain='climate') ``` -------------------------------- ### Define Python Package Requirements Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Specifies required Python packages for Pyscript. A requirements.txt file in the config/pyscript directory or within app/module directories lists packages, optionally with version specifiers. Pyscript can automatically install missing packages. If a required version differs from the installed one, the requirement is skipped with a warning. ```text # this is a comment aiohttp amazing_stuff==3.1 another_package==5.1.2 ``` -------------------------------- ### Webhook Trigger Example with Custom Arguments in Python Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst This Python example demonstrates a Pyscript function triggered by a webhook. It uses @webhook_trigger with a specific ID and includes extra keyword arguments that are passed to the function. The function logs received payload data and the extra arguments, illustrating how to interact with webhook requests. ```python @webhook_trigger("myid", kwargs={"extra": 10}) def webhook_test(payload, extra): log.info(f"It ran! {payload}, {extra}") ``` -------------------------------- ### Establish TCP Client Connection with asyncio Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst This example demonstrates how to create a TCP client connection and exchange messages using `asyncio.open_connection`. The connection is established at startup, and subsequent messages can be sent and received without blocking the main event loop. This is suitable for line-oriented protocols, with options to read raw bytes. ```python import asyncio Reader, Writer = None, None @time_trigger('startup') def do_client_connection(): global Reader, Writer Reader, Writer = asyncio.open_connection('127.0.0.1', 8956) def client_send(message): if not Writer: raise("Client is not connected") Writer.write(message.encode()) Writer.drain() return Reader.readline().decode() ``` -------------------------------- ### Pyscript Motion-Activated Light with State Check Source: https://hacs-pyscript.readthedocs.io/en/stable/tutorial This Pyscript function further refines the motion-activated light logic by adding a check to see if the light is already on. This avoids unnecessary `turn_on` calls if the light is already in the desired state, optimizing the automation. ```python @state_trigger("security.rear_motion == '1' or security.side_motion == '1'") @time_active("range(sunset - 20min, sunrise + 20min)") def motion_light_rear(): """Turn on rear light for 5 minutes when there is motion and it's dark""" task.unique("motion_light_rear") log.info(f"triggered; turning on the light") if light.outside_rear != "on": light.turn_on(entity_id="light.outside_rear", brightness=255) task.sleep(300) light.turn_off(entity_id="light.outside_rear") ``` -------------------------------- ### Event Trigger Example: Specific Service Call Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst This snippet shows a more refined use of the @event_trigger decorator. After observing the event data from a broader trigger, this example demonstrates how to filter for a specific service call ('lights.turn_on') by using a more precise event trigger condition. It assumes prior knowledge of event data structure. ```python from homeassistant.const import EVENT_CALL_SERVICE # Assuming previous monitoring revealed EVENT_CALL_SERVICE has domain and service parameters. # This example would typically be preceded by a broader log to identify the correct parameters. ``` -------------------------------- ### State Management API Source: https://hacs-pyscript.readthedocs.io/en/stable/reference Provides functions for getting, setting, deleting, and checking the existence of state variables and their attributes. ```APIDOC ## State Management API ### Description Functions for interacting with Home Assistant state variables and their attributes. ### Endpoints #### `state.delete(name)` ##### Description Deletes the given state variable or attribute. ##### Method `STATE` (Internal) ##### Parameters - **name** (string) - Required - The name of the state variable or attribute to delete. #### `state.exist(name)` ##### Description Checks if a state variable or attribute exists. ##### Method `STATE` (Internal) ##### Parameters - **name** (string) - Required - The name of the state variable or attribute to check. ##### Returns - **boolean** - `True` if the state variable or attribute exists, otherwise `False`. #### `state.get(name)` ##### Description Retrieves the value of a state variable. ##### Method `STATE` (Internal) ##### Parameters - **name** (string) - Required - The name of the state variable. Can be in the format `DOMAIN.entity.attr`. ##### Returns - **any** - The value of the state variable or attribute. ##### Throws - `NameError` - If the state variable does not exist. - `AttributeError` - If accessing an attribute that does not exist. #### `state.getattr(name)` ##### Description Retrieves all attributes of a state variable. ##### Method `STATE` (Internal) ##### Parameters - **name** (string or object) - Required - The name of the state variable or the state variable object itself. ##### Returns - **dict** - A dictionary of attribute values for the state variable, or `None` if it doesn't exist. #### `state.names(domain=None)` ##### Description Retrieves a list of all state variable names (entity_ids). ##### Method `STATE` (Internal) ##### Parameters - **domain** (string) - Optional - If specified, returns state variable names only for this domain. ##### Returns - **list** - A list of state variable names. #### `state.persist(entity_id, default_value=None, default_attributes=None)` ##### Description Marks an entity to be persisted across Home Assistant restarts. ##### Method `STATE` (Internal) ##### Parameters - **entity_id** (string) - Required - The entity ID to persist. - **default_value** (any) - Optional - The default value to apply if the entity does not exist. - **default_attributes** (dict) - Optional - Default attributes to apply if the entity has no attributes. #### `state.set(name, value=None, new_attributes=None, **kwargs)` ##### Description Sets the value and/or attributes of a state variable. ##### Method `STATE` (Internal) ##### Parameters - **name** (string) - Required - The name of the state variable. - **value** (any) - Optional - The new value for the state variable. - **new_attributes** (dict) - Optional - A dictionary of attributes to overwrite existing attributes. - **kwargs** - Optional - Keyword arguments for attributes to set without overwriting others. #### `state.setattr(name, value)` ##### Description Sets a specific attribute of a state variable. ##### Method `STATE` (Internal) ##### Parameters - **name** (string) - Required - The name of the state variable attribute in the format `DOMAIN.entity.attr`. - **value** (any) - Required - The new value for the attribute. ``` -------------------------------- ### State Trigger with String Comparison Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Example of using the @state_trigger decorator to compare a state variable's string value. ```python @state_trigger("domain.light_level == '255' or domain.light2_level == '0'") ``` -------------------------------- ### Calling Services with PyScript Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Demonstrates different ways to call Home Assistant services using PyScript. This includes direct method calls, using the `service.call` function, and specifying parameters. It also shows how to handle service responses and blocking calls. ```python service.call("DOMAIN", "SERVICE", entity_id="DOMAIN.ENTITY", other_param=123) DOMAIN.SERVICE(entity_id="DOMAIN.ENTITY", other_param=123) DOMAIN.ENTITY.SERVICE(other_param=123) # Example with input_number service.call("input_number", "set_value", entity_id="input_number.test", value=13) input_number.set_value(entity_id="input_number.test", value=13) input_number.test.set_value(value=13) input_number.test.set_value(13) # Example with return_response service_response = myservice.flash_light(light_name="front", light_color="red", return_response=True) # Example with blocking call myservice.flash_light(light_name="front", light_color="red", blocking=True) # Example calling service with computed domain/name service.call("myservice", "flash_light", light_name="front", light_color="red") ``` -------------------------------- ### State Trigger on Specific Attribute Change Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Example of using the @state_trigger decorator to trigger on a change to a specific attribute of a state variable. ```python @state_trigger("domain.entity.attr") ``` -------------------------------- ### Define Pyscript Service with YAML Description (Python) Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Defines a custom service 'hello_world' using Pyscript. It includes a YAML-based description for the service's name, purpose, fields, and their properties. The service accepts 'action' and 'id' as parameters and performs actions based on their values, such as turning on a light or firing an event. ```python @service def hello_world(action=None, id=None): """yaml name: Service example description: hello_world service example using pyscript. fields: action: description: turn_on turns on the light, fire fires an event example: turn_on required: true selector: select: options: - turn_on - fire id: description: id of light, or name of event to fire example: kitchen.light required: true selector: text: """ log.info(f"hello world: got action {action}") if action == "turn_on" and id is not None: light.turn_on(entity_id=id, brightness=255) elif action == "fire" and id is not None: event.fire(id) ``` -------------------------------- ### Pyscript Motion-Activated Light with Time Trigger Source: https://hacs-pyscript.readthedocs.io/en/stable/tutorial This Pyscript function triggers a light to turn on when motion is detected and it's within a specific time range (dusk to dawn). It logs the event, turns on the light, waits for 5 minutes, and then turns it off. This basic example does not prevent multiple instances from running concurrently. ```python @state_trigger("security.rear_motion == '1' or security.side_motion == '1'") @time_active("range(sunset - 20min, sunrise + 15min)") def motion_light_rear(): """Turn on rear light for 5 minutes when there is motion and it's dark""" log.info(f"triggered; turning on the light") light.turn_on(entity_id="light.outside_rear", brightness=255) task.sleep(300) light.turn_off(entity_id="light.outside_rear") ``` -------------------------------- ### State Trigger on Attribute Change Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Example of using the @state_trigger decorator to trigger on any change to any attribute of a specific entity. This does not monitor the entity's state value. ```python @state_trigger("domain.entity.*") ``` -------------------------------- ### Calling Services via State Variables in Python Source: https://hacs-pyscript.readthedocs.io/en/stable/reference Illustrates how to call Home Assistant services using a shorthand notation directly from state variables. This method is equivalent to using `service.call()` or the more verbose state variable method calls. It's particularly convenient when a service takes the entity ID as its primary parameter and has other parameters that can be passed positionally. ```python service.call("DOMAIN", "SERVICE", entity_id="DOMAIN.ENTITY", other_param=123) DOMAIN.SERVICE(entity_id="DOMAIN.ENTITY", other_param=123) DOMAIN.ENTITY.SERVICE(other_param=123) # Shorthand for services with only one additional parameter DOMAIN.ENTITY.SERVICE(123) # Example with input_number service.call("input_number", "set_value", entity_id="input_number.test", value=13) input_number.set_value(entity_id="input_number.test", value=13) input_number.test.set_value(value=13) input_number.test.set_value(13) ``` -------------------------------- ### State Trigger on Any Change Source: https://hacs-pyscript.readthedocs.io/en/stable/_sources/reference.rst Example of using the @state_trigger decorator to trigger on any change to a state variable's value. This form triggers on creation, deletion, and any value modification. ```python @state_trigger("domain.light_level") ```