Work great! But I didn’t understand the different between condition: and condition_on: condition_off: . For what condition_on and condition_off ?
@mill7 : Alert2 documentation on condition alerts has an explanation. Briefly, an alert fires only while condition is true. The _on and _off variants allow separate control of logic for on/off if you want it (eg you could use a condition to turn on and allow turn off only manually). By the way, let me know if you come across parts of the documentation that aren’t as clear as they could be.
-J
About the documentation, I’m sure it’s all there and every option is explained, but for me, for example, to put it all together correctly I just lack examples of use cases that solve a single problem. For example, I made an alert that monitors the sensors and if there is an exceeded threshold, there is a notification. Data on the sensor name, threshold and unit of measurement (just for the message) are set in the jinja file. Alerts work the code is short and clear. But as I understand there are two problems:
- it is probably necessary to remove condition_on: and condition_off: and put just condition ?
- I would like that if the sensor will send many messages that the problem disappeared and again appeared I need to use throttle_fires_per_mins and I don’t understand how I can make if I received 2 messages per 3 minute that the problem is gone and I get 3 messages about the same so that there is a pause for 30 minutes ?
- generator_name: more_than
generator: >-
{%- from 'alert2_thresholds_more_than.jinja' import thresholds -%}
{{ thresholds.keys() | list }}
domain: more_than
name: "{{ genEntityId.split('.')[1] }}"
condition_on: >-
{%- from 'alert2_thresholds_more_than.jinja' import thresholds -%}
{%- set threshold_info = thresholds[genEntityId] -%}
{{ (states(genEntityId) | float(default=threshold_info.value)) > threshold_info.value }}
condition_off: >-
{%- from 'alert2_thresholds_more_than.jinja' import thresholds -%}
{%- set threshold_info = thresholds[genEntityId] -%}
{{ (states(genEntityId) | float(default=threshold_info.value)) <= threshold_info.value }}
title: >-
{%- from 'alert2_thresholds_more_than.jinja' import thresholds -%}
{%- set threshold_info = thresholds[genEntityId] -%}
{{- (states(genEntityId) | float(default=threshold_info.value)) > threshold_info.value
and "⚠️ Тревога! "
or "✅" -}}
{{ state_attr(genEntityId, 'friendly_name') | default('—') }}
({{ area_name(genEntityId) | default('—') }})
— сейчас {{ states(genEntityId) }}{{ threshold_info.unit }} (порог срабатывания больше чем:{{ threshold_info.value }}{{ threshold_info.unit }})
friendly_name: "{{ state_attr(genEntityId, 'friendly_name') }}({{ area_name(genEntityId) | default('—') }})"
message: "⠀"
done_message: >-
{%- from 'time_delta.jinja' import format_timedelta -%}
{%- set alert_entity = 'alert2.more_than_' ~ genEntityId.split('.')[1] -%}
Показатель вернулся в норму, теперь он ниже или равен порогу! {{ format_timedelta(state_attr(alert_entity, 'last_on_time')) }}
reminder_message: >-
{%- from 'time_delta.jinja' import format_timedelta -%}
{%- set alert_entity = 'alert2.more_than_' ~ genEntityId.split('.')[1] -%}
Значение больше порога сохраняется {{ format_timedelta(state_attr(alert_entity, 'last_on_time')) }}
I see such errors in the logs, although I have everything working notifications come, what is it connected with and where to look for the problem ?
Уровень: ПРЕДУПРЕЖДЕНИЕ
Эта ошибка возникла в пользовательской интеграции.
Регистратор: custom_components.alert2.entities
Источник: custom_components/alert2/entities.py:1280
интеграция: Alert2 (документация, проблемы)
Зафиксировано первый раз: 20:19:14 (5 случаев)
Зафиксировано последний раз: 22:02:27
- alert2.satel_window_satel_vhodnaia_dver notifying [‘notiscript’]: ⠀
- alert2.satel_window_satel_vhodnaia_dver notifying [‘notiscript’]: Прошло: 3 секунды
- alert2.alert2_global_exception notifying [‘notiscript’]: An HA task (possibly unrelated to Alert2) died to due to an unhandled exception: <class ‘Exception’>: network error:(2001) 2001. full context: {‘message’: ‘Task exception was never retrieved’, ‘exception’: Exception(‘network error:(2001) 2001’), ‘future’: <Task finished name=‘Task-85746’ coro=<ScriptEntity._async_run() done, defined at /usr/src/homeassistant/homeassistant/components/script/init.py:689> exception=Exception(‘network error:(2001) 2001’)>}
Уровень: ПРЕДУПРЕЖДЕНИЕ
Эта ошибка возникла в пользовательской интеграции.
Регистратор: custom_components.alert2.entities
Источник: custom_components/alert2/entities.py:1385
интеграция: Alert2 (документация, проблемы)
Зафиксировано первый раз: 22:02:27 (1 случай)
Зафиксировано последний раз: 22:02:27Activity alert2.alert2_global_exception fired
hey @redstone99 ,
thanks for this integration.
I installed it today and I tried to configure it so I get alerted whenever my NAS disk is getting full.
I used the Alert2 UI card to setup an alert which has the following YAML representation:
alert2:
alerts:
- domain: computing
name: storage_full2
friendly_name: TNAS Disk full
message: "test message"
condition: "{{ states('sensor.tnas_root_disk_usage')|float > 80 }}"
The “render result” of the condition is “true”.
However I don’t see this alert being firing in the Alert2 Overview card… what am I missing?
Ps: I’m using Alert2 v1.11.3
thanks
Hi @f18m,
I’m not sure what that could be. How about if you set the condition to always be true:
condition: on
Does the alert fire then? Also, do you see any indications of warnings/errors in the logs?
@mill7 : It looks like some script died with a network error. Maybe the script called by the notiscript? Alert2 defines a global exception handler that catches when tasks die. You can configure how that behaves.
I don’t totally understand your question re your threshold example. It looks to me like you can combine condition_on and condition_off into one condition field, though you can leave them separate if you want to for some reason.
throttle_fires_per_mins affects notifications. It does not affect whether an alert fires or not.
-J
Hey @redstone99 ,
even if I set “condition: on”… the alert does not fire… in the logs I don’t see anything related to Alert2… I’m not sure at this point what’s the issue…
Hi @f18m ,
If you click on “Alerts” in the overview card to show the Alert2 backend version, do you see the v1.11.3 twice as in the following:
Did you add any configuration to the alert overview card, like setting filter_entity_id, that might be preventing it from showing the alerting entity?
In the logs, there should be a line something like:
2025-05-15 06:28:53.595 INFO (MainThread) [custom_components.alert2] Setting up Alert2````
If you don’t see something like that, then Alert2 isn’t loading when HA starts.
-Josh
How can I get the name of alert2 object in message, reminder_message and done_message ? it would be convenient to have something like {{ this.entity_id }} to always know who sent the alert. I want to record all alarms in my database and I need the exact ID of who sent the alarm.
@mill7 - if you want to track alert activity, one option is to watch for the appropriate Alert2 HA events and update your DB when they occur.
If you’re using a generator, you can use genElem or one of the generator variables to figure out the entity name.
Otherwise, yeah, we’d need to expose this in message templates, which is certainly doable.
-Josh
I don’t really understand this functionality is already there or just might be ?
If it is already there, I would like to see an example.
I would like to use this scheme
- domain: sensor
name: carel_tekushchee_costoianie_alert
friendly_name: "Carel: нежелательное состояние"
condition: "{{ states('sensor.fake_temperature_sensor') | int(default=0) in [ 2, 3, 9, 14, 16, 19] }}"
notifier: notiscript_php
reminder_frequency_mins: 1
message: >-
Сенсор Carel перешёл в недопустимое состояние:
{{ states('sensor.humidifier_states') }} (код {{ states('sensor.carel_tekushchee_costoianie') }})
## alert2_entity={{ this.entity_id }};
main_entity=sensor.carel_tekushchee_costoianie;
error_entity=sensor.humidifier_statse;
error_text={{ states('sensor.humidifier_states') }};
done=-1;
The first part of the message the notiscript_php script sends to me in telegram, and the second part that comes after ## sends to my database and the value of alert2_entity is very important.
Hi - Alert2 does not yet support this in message templates. Someone would have to implement that functionality. In the meantime, in your specific use case, you could explicitly write out the entity id, so say:
message: >-
...
alert2_entity=alert2.sensor_carel_tekushchee_costoianie_alert
...
-Josh
By the way, in case anyone’s in the Boston area, I’ll be at the Home Assistant Community Day Boston meetup on May 24th.
-Josh
I need to read the delay time from a file, but whatever I do it causes an error, how to make such a design work ?
delay_on_secs: >-
{%- from 'alert2_thresholds_more_than_during.jinja' import thresholds -%}
{{ (thresholds[genEntityId].secs)|float }}
and i use it in the generator: block of course although it should be clear by genEntityId.
Hi @mill7,
delay_on_secs does not yet support templates
-Josh
Do you have plans to make delay_on_secs or any other delay to support templates? I really need this functionality.
Can you describe your use case? I’d like to understand it to help figure out what might best meet it.
-J
It’s simple, I make a generator and take all values from a .jinja file, for example this one
{%- set thresholds = {
'sensor.s218_curr_power_in4_1': {
'value': 2,
'minutes': 1
}
} %}
There is only one sensor, but it is clear that there will be many, I want to be notified when a threshold is exceeded and when it lasts for a certain number of minutes. The main goal is to set all thresholds and sensor names only once, except through .jinja file I don’t know how to solve it
if delay_on_secs supported the value from the template the whole construction would look like this
- generator_name: more_than_during
generator: >-
{%- from 'alert2_thresholds_more_than_during.jinja' import thresholds -%}
{{ thresholds.keys() | list }}
domain: more_than_during
name: "{{ genEntityId.split('.')[1] }}"
condition: >-
{%- from 'alert2_thresholds_more_than_during.jinja' import thresholds -%}
{%- set threshold_info = thresholds[genEntityId] -%}
{{ (states(genEntityId) | float(default=threshold_info.value)) > threshold_info.value }}
delay_on_secs: >-
{%- from 'alert2_thresholds_more_than_during.jinja' import thresholds -%}
{{ (thresholds[genEntityId].minutes)|float }}
and another example of use I have in one generator the notification about open windows and doors, but for example in my case windows are opened very rarely and I would like to be notified as soon as it happens, and the door is opened very often and I would like to set delay_on_secs: different for windows and doors, now I have to make a second generator for this and separate these notifications
Thanks for the examples. Looks like delay_on_secs is one of the few params that doesn’t take a template. K, I’ll template-enable it.
J
