Skip to content

Commit

Permalink
updated to support nested lists
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Oct 28, 2024
1 parent 7afcaa0 commit 50b781f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Easiest way is to run pip as a module (<https://realpython.com/what-is-pip/#usin
- `source ./venv/bin/activate` to go into the virtual environment
- `pip install -r requirements.txt` to refresh latest libs
- `mkdocs serve` to build the documentation
- <http://127.0.0.1:8000/docs>
- <http://127.0.0.1:8000>
- TIP: comment out the `git-committers` and `git-revision-date-localized` sections in `mkdocs.yml` to speed up the build and prevent exceeding the GitHub API calls, but remember to uncomment it before committing

## Deploying manually
Expand Down
29 changes: 16 additions & 13 deletions docs/Configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,31 +168,34 @@ The scheduler can also be used to periodically set values based on another entit

### Conditions

Introduced in **version 3.7**, the Scheduler has been extended to support conditional statements used in the `Command` and/or `Value` fields. Conditions have a strict syntax (see below) and are evaluated every 10 seconds. The condition is only executed when the condition changes from false to true. This is powerful new feature and allows, for example, to set a schedule based on a condition, or to set a value based on a condition.
Introduced in **version 3.7**, the Scheduler has been extended to support conditional statements and formulas that can be used in the `Command` and/or `Value` fields for Timer, On Change and Condition types.

Conditions have a strict syntax (see below) and are evaluated every 10 seconds. The condition is only executed when the condition changes from false to true. This is powerful new feature and allows, for example, to set a schedule based on a condition or set a value based on a condition.

Pay attention to the following rules:

- a condition has to be a logic value `0` or `1`, the condition is `true` only for `1`, an arithmetic result `1` is also interpreted as `true`
schedule command executed for `3 > 2, 3 - 2`
schedule command not executed for `3 < 2`, `3 + 2`
- blanks are not needed, but makes the formula more readable
- EMS-ESP values are accessed `<device>/<entity>` or `<device>/<entity>/value`, `<entity>` may contain prefixes like `<hc2>`.
- checking enum and bool values depends on the user's API setting! Check the right value before setting a schedule
e.g. check output <http://ems-esp.local/api/thermostat> to see if building = "medium", create the rule with `thermostat/building == medium`
also for boolean values check if you have to use `0/1`, `off/on`, `OFF/ON`, or `false/true`
- strings containing special characters have to be written in quotations, e.g. `boiler/pumpmode == "delta-P2"`, to avoid a calculation error on delta minus P2,
other strings can be written with or without quotations
- spaces are not needed, but makes the formula more readable
- EMS-ESP values are accessed `<device>/<entity>` or `<device>/<entity>/value`. The `<entity>` may contain additional prefixes like `<hc2>`.
- The user's Boolean Format (`0/1`, `off/on`, `OFF/ON`, or `false/true`) and Enum Format (value/index) Settings are used when evaluating bool and enums. Check the right value before setting a schedule by querying the API directly. For example go to `http://ems-esp.local/api/thermostat` to see if building is "medium", then create the rule with `thermostat/building == medium`.
- strings containing special characters have to be quoted. e.g. `boiler/pumpmode == "delta-P2"`, to avoid a calculation error on delta minus P2.
- all strings are converted to lowercase
- commands followed by a divider (`/`) have to be set in parenthesis e.g. `(boiler/seltemp)/2`
- condition command is only executed on a change of the condition from `false` to `true`. If the condition stays true, the command is not repeated
- command value can also be a formula
- a command Value can also be a formula
- allowed operations:

- arithmetic: `+` `-` `*` `/` `%`
- prefix: `-` `round` `abs` `int` `exp` `log` `sqrt` `pow`
- functions: `round` `abs` `int` `exp` `log` `sqrt` `pow`
- logic: `==` `!=` `<=` `>=` `<` `>` `&&` `||`
- prefix: `!`
- conditional operations: `<cond1> ? <expr1> : <expr2>` only surrounding a formula, not within a formula (not allowed: `5 + (<cond> ? <expr1> : <expr2>)`, allowed: `<cond> ? 5 + <expr1> : 5 + <expr2>`), cascaded conditions can be used (`<cond1> ? <cond2> ? <expr1> : <expr2> : <cond3> ? <expr3> : <expr4>`)
- on change trigger is always one or more entities `<device>/<entity>`, where device is **not** system. It can have multiple triggers. e.g. `boiler/outdoortemp custom/setpoint` and triggers on change of each value (entities never change the same time (it's a callback) and logical operations here like `&&` makes no sense)
- prefix: `!` (not) and `-` (negation)
- conditional operations: `<cond1> ? <expr1> : <expr2>` only surrounding a formula, not within a formula. Examples:
- (allowed) `<cond> ? 5 + <expr1> : 5 + <expr2>`
- (not allowed) `5 + (<cond> ? <expr1> : <expr2>)` and cascaded conditions `<cond1> ? <cond2> ? <expr1> : <expr2> : <cond3> ? <expr3> : <expr4>`

An On Change trigger is a list of entities following the format `<device>/<entity>`. Note, a `<device>` of "system" is not supported. e.g. `boiler/outdoortemp custom/setpoint`. As entities never change at the same time using logical operations here like `&&` aren't useful.

![Web](_media/screenshot/web_conditions_1.png)

Expand Down
20 changes: 12 additions & 8 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ plugins:
- redirects:
redirect_maps:
- table-reader
- git-revision-date-localized
- git-committers:
repository: emsesp/docs
branch: main
# - git-revision-date-localized
# - git-committers:
# repository: emsesp/docs
# branch: main
# - htmlproofer

# strict: true
Expand Down Expand Up @@ -64,22 +64,26 @@ markdown_extensions:
toc_depth: 3
- pymdownx.tabbed:
alternate_style: true
# - pymdownx.emoji:
# emoji_index: !!python/name:material.extensions.emoji.twemoji
# emoji_generator: !!python/name:material.extensions.emoji.to_svg
- pymdownx.betterem
- pymdownx.caret
- pymdownx.details
- pymdownx.highlight
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
- pymdownx.highlight:
linenums: true
- pymdownx.keys
- pymdownx.mark
- pymdownx.superfences
- pymdownx.snippets
- pymdownx.tilde
- pymdownx.details
- meta
- def_list
- attr_list
- md_in_html
# support pad width = 2, as formatted with prettier
- mdx_truly_sane_lists

extra_css:
- 'assets/css/anchor-fix.css'
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ mkdocs-git-revision-date-localized-plugin>=1.1.0
mkdocs-git-committers-plugin-2
git+https://github.com/cmitu/mkdocs-altlink-plugin.git
lxml
mdx-truly-sane-lists==1.3
mkdocs-material-extensions==1.0.3
pymdown-extensions==9.1

0 comments on commit 50b781f

Please sign in to comment.