Skip to content

Commit

Permalink
Merge pull request #626 from ALERTua/state_active__state_trigger_exam…
Browse files Browse the repository at this point in the history
…ples

state_active and state_trigger examples
  • Loading branch information
craigbarratt authored Sep 16, 2024
2 parents f1b31a5 + 1dc4da7 commit 59b2011
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ docs/_build
.coverage
.vscode
.*.swp
.idea
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Installation
============

Option 1: Home Assistant Community Store (HACS)
--------------
-----------------------------------------------

HACS is an integration in Home Assistant that allows you to
install custom integrations, frontend elements, and add-ons
Expand Down
20 changes: 20 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,16 @@ will be ``None`` if the trigger is not a state trigger, if a different state var
caused the state trigger, or if the state variable that caused the trigger was set for the
first time (so there is no prior value).

.. code:: python
@state_trigger("binary_sensor.motion_detected == 'on'") # trigger on motion detection
@state_active("input_boolean.motion_light_automation == 'on'") # but only if the automation is enabled
def motion_controlled_light(**kwargs):
log.info(f"got motion. turning on the lights")
light.turn_on(entity_id="light.hallway")
@time_active
^^^^^^^^^^^^

Expand Down Expand Up @@ -862,6 +872,16 @@ true if the current time doesn't match any of the "not" (negative) specification
allows multiple arguments with and without ``not``. The condition will be met if the current time
matches any of the positive arguments, and none of the negative arguments.

.. code:: python
@state_trigger("binary_sensor.motion_detected == 'on'") # trigger on motion detection
@state_active("input_boolean.motion_light_automation == 'on'") # but only if the automation is enabled
@time_active("range(8:00, 22:00)") # but only during the day
def motion_controlled_light(**kwargs):
log.info(f"got motion. turning on the lights")
light.turn_on(entity_id="light.hallway")
@webhook_trigger
^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit 59b2011

Please sign in to comment.