call_start_detect_delay fix & action sensor

This commit is contained in:
Nikolay Vasilchuk
2022-09-09 22:38:39 +03:00
parent 13e97c6ad2
commit 1b6fdeb7da
6 changed files with 65 additions and 61 deletions

View File

@@ -97,19 +97,15 @@
После этого плата перезагружается и подключается к вашему WiFi.
Home assistant обычно обнаруживает подключение автоматически. Если не обнаружил, то можно подключить через интеграции. Пароль для интеграции `esphome`
<!--
При принятии или отклонении вызова в Home Assistant отправляются события
`esphome.domofon_call_accept` и `esphome.domofon_call_reject` соответственно,
которые можно использовать в качестве триггеров для автоматизаций:
При принятии или отклонении вызова в Home Assistant обновляется сенсор `Domofon Action`. Возможные значения:
```yaml
trigger:
- platform: event
event_type: esphome.domofon_call_accept
- platform: event
event_type: esphome.domofon_call_reject
```
-->
* `none` значение по-умолчанию
* `open_sw` открыт программно
* `open_hw` открыт аппаратной кнопкой
* `open_auto` открыт автоматически
* `reject_sw` отклонен программно
* `reject_hw` отклонен аппаратной кнопкой
* `reject_auto` отклонен автоматически
## Уведомления в Telegram через Home Assistant

View File

@@ -59,45 +59,6 @@ globals:
restore_value: yes
initial_value: 'false'
sensor:
- platform: template
name: "${board_name} Heap Size"
lambda: "return ESP.getFreeHeap();"
update_interval: 20s
unit_of_measurement: bytes
accuracy_decimals: 0
entity_category: "diagnostic"
- platform: uptime
internal: true
id: uptime_sensor
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
text_sensor:
- platform: template
id: uptime_human
name: "${board_name} Uptime"
icon: mdi:clock-start
entity_category: "diagnostic"
substitutions:
# Ge1mer board
board: esp12e
@@ -117,4 +78,5 @@ packages:
switch: !include switch.yaml
button: !include button.yaml
light: !include light.yaml
sensor: !include sensor.yaml
binary_sensor: !include binary_sensor.yaml

View File

@@ -9,8 +9,8 @@ binary_sensor:
mode: INPUT_PULLUP
inverted: True
filters:
delayed_on: $call_start_detect_delay
delayed_off: $call_end_detect_delay
- delayed_on: $call_start_detect_delay
- delayed_off: $call_end_detect_delay
on_press:
then:
script.execute: state_call
@@ -52,6 +52,7 @@ binary_sensor:
lambda: |-
ESP_LOGD("main", "Single Long Click");
if (id(incoming_call).state) {
id(last_action).publish_state("reject_hw");
id(call_reject).execute();
} else {
id(mode_auto_open) = false;
@@ -69,6 +70,7 @@ binary_sensor:
lambda: |-
ESP_LOGD("main", "Single Short Click");
if (id(incoming_call).state) {
id(last_action).publish_state("open_hw");
id(call_accept).execute();
} else {
if (id(mode_auto_open_once)) {

View File

@@ -10,6 +10,7 @@ button:
then:
lambda: |-
if (id(incoming_call).state) {
id(last_action).publish_state("open_sw");
id(call_accept).execute();
} else {
ESP_LOGD("main", "No incoming call");
@@ -23,6 +24,7 @@ button:
then:
lambda: |-
if (id(incoming_call).state) {
id(last_action).publish_state("reject_sw");
id(call_reject).execute();
} else {
ESP_LOGD("main", "No incoming call");

View File

@@ -11,6 +11,7 @@ script:
id(relay_mute).turn_off();
}
id(relay_answer).turn_off();
id(last_action).publish_state("none");
# Connected answer resistor
- id: state_answer
@@ -43,10 +44,6 @@ script:
- globals.set:
id: mode_mute_once
value: 'false'
# - homeassistant.event:
# event: esphome.domofon_call_accept
# data:
# entity_uid: $mdns_name
# Reject incoming call
- id: call_reject
@@ -59,10 +56,6 @@ script:
- globals.set:
id: mode_mute_once
value: 'false'
# - homeassistant.event:
# event: esphome.domofon_call_reject
# data:
# entity_uid: $mdns_name
# Call state
- id: state_call
@@ -70,10 +63,13 @@ script:
- lambda: |-
ESP_LOGD("main", "Incoming call");
if (id(mode_auto_reject)) {
id(last_action).publish_state("reject_auto");
id(call_reject).execute();
} else if (id(mode_auto_open)) {
id(last_action).publish_state("open_auto");
id(call_accept).execute();
} else if (id(mode_auto_open_once)) {
id(last_action).publish_state("open_auto");
id(call_accept).execute();
id(mode_auto_open_once) = false;
}

View File

@@ -0,0 +1,46 @@
sensor:
- platform: template
name: "${board_name} Heap Size"
lambda: "return ESP.getFreeHeap();"
update_interval: 20s
unit_of_measurement: bytes
accuracy_decimals: 0
entity_category: "diagnostic"
- platform: uptime
internal: true
id: uptime_sensor
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
text_sensor:
- platform: template
id: uptime_human
name: "${board_name} Uptime"
update_interval: never
icon: mdi:clock-start
entity_category: "diagnostic"
- platform: template
id: last_action
name: "${board_name} Action"
update_interval: never
icon: mdi:clock-time-eight-outline
entity_category: "diagnostic"