118 lines
3.1 KiB
Nix
118 lines
3.1 KiB
Nix
{
|
|
services.home-assistant.extraComponents = [
|
|
"nuki"
|
|
];
|
|
|
|
services.home-assistant.config = {
|
|
"automation house_door" = {
|
|
alias = "house_door";
|
|
mode = "restart";
|
|
hide_entity = true;
|
|
trigger = {
|
|
platform = "state";
|
|
entity_id = [
|
|
"person.dominik"
|
|
];
|
|
from = "not_home";
|
|
to = "home";
|
|
};
|
|
action = [
|
|
{
|
|
service = "lock.unlock";
|
|
target = {
|
|
entity_id = "lock.house_door";
|
|
};
|
|
}
|
|
{
|
|
delay = "00:05:00";
|
|
}
|
|
{
|
|
service = "lock.lock";
|
|
target = {
|
|
entity_id = "lock.house_door";
|
|
};
|
|
}
|
|
];
|
|
};
|
|
"automation house_door_ring" = {
|
|
alias = "house_door_ring";
|
|
trigger = {
|
|
platform = "event";
|
|
event_type = "nuki_event";
|
|
event_data = {
|
|
type = "ring";
|
|
};
|
|
};
|
|
action = [
|
|
{
|
|
choose = [
|
|
{
|
|
conditions = [ "{{ state.house_door == \"unlocked\" }}" ];
|
|
sequence = [
|
|
{
|
|
service = "lock.lock";
|
|
target = {
|
|
entity_id = "lock.house_door";
|
|
};
|
|
}
|
|
];
|
|
}
|
|
];
|
|
}
|
|
];
|
|
};
|
|
binary_sensor = [
|
|
{
|
|
platform = "template";
|
|
sensors = {
|
|
lock_critical_battery = {
|
|
value_template = ''
|
|
{% set domains = ['lock'] %}
|
|
{% set ns = namespace(crit=battery_critical, entities=[]) %}
|
|
{% for domain in domains %}
|
|
{% set batt_critical = states[domain] | selectattr('attributes.battery_critical','defined') | map(attribute='attributes.battery_critical') | reject('equalto', 'unknown') | reject('equalto', 'None') | map('int') | reject('equalto', 0) | list %}
|
|
{% if batt_critical|length > 0 %}
|
|
{% set ns.battery_critical = true %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
{{ ns.battery_critical }}
|
|
'';
|
|
friendly_name = "A lock has critical battery";
|
|
device_class = "problem";
|
|
};
|
|
};
|
|
}
|
|
];
|
|
alert = {
|
|
battery_critical = {
|
|
name = "Lock has low battery!";
|
|
message = ''
|
|
{%- set domains = ['lock'] -%}
|
|
Lock battery is critical:
|
|
{%- for domain in domains -%}
|
|
{%- for item in states[domain] -%}
|
|
{%- if item.attributes.battery_critical is defined -%}
|
|
{% if item.attributes.battery_critical %}
|
|
- {{ item.attributes.friendly_name }}
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- endfor -%}
|
|
'';
|
|
entity_id = "binary_sensor.lock_critical_battery";
|
|
state = "on";
|
|
repeat = [
|
|
5
|
|
60
|
|
360
|
|
];
|
|
skip_first = true;
|
|
can_acknowledge = true;
|
|
notifiers = [
|
|
"NotificationGroup"
|
|
];
|
|
};
|
|
};
|
|
};
|
|
}
|