Skip to content

Add support for cron for when alert active #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ These are the configuration keys:
> minutes: 5
> ```

> **cron**
> Cron expression for when this alert is active
>
> ```
> cron: "* 6 * * 1-5" # only active M-F 6a to 6:59a
> ```

> **notifier** (required)
>
> The name of the `notify.` service that should be used for notifications. The domain should not be included.
Expand Down
15 changes: 14 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,22 @@
vol.Optional('mute', default="False"): str,
vol.Optional('done_message', default=''): str,
vol.Optional('delay', default=0): vol.Any(int, float),

vol.Optional('cron', default="* * * * *"): str,
vol.Optional('app'): APP_NAME,
})

def isfloat(num):
try:
float(num)
return True
except ValueError:
return False

def safefloat(num, defVal):
try:
return float(num)
except ValueError:
return defVal

def seconds_human(seconds):
seconds_in_min = 60
Expand Down Expand Up @@ -104,6 +116,7 @@ def make_alert(config):
@task_unique(alert_entity)
@state_trigger(f'True or {config["condition"]} or {config["mute"]}')
@time_trigger('startup')
@time_active(f'cron({config["cron"]})')
def alert():
try:
alert_count = float(state.get(f'{alert_entity}.count'))
Expand Down