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

View File

@@ -59,45 +59,6 @@ globals:
restore_value: yes restore_value: yes
initial_value: 'false' 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: substitutions:
# Ge1mer board # Ge1mer board
board: esp12e board: esp12e
@@ -117,4 +78,5 @@ packages:
switch: !include switch.yaml switch: !include switch.yaml
button: !include button.yaml button: !include button.yaml
light: !include light.yaml light: !include light.yaml
sensor: !include sensor.yaml
binary_sensor: !include binary_sensor.yaml binary_sensor: !include binary_sensor.yaml

View File

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

View File

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

View File

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