mirror of
https://github.com/Anonym-tsk/smart-domofon.git
synced 2025-12-31 21:59:36 +03:00
76 lines
2.2 KiB
YAML
76 lines
2.2 KiB
YAML
script:
|
|
# Connected intercom or mute resistor
|
|
- id: state_ready
|
|
then:
|
|
- lambda: |-
|
|
if (id(mode_mute) || id(mode_mute_once)) {
|
|
id(relay_mute).turn_on();
|
|
id(relay_phone).turn_off();
|
|
} else {
|
|
id(relay_phone).turn_on();
|
|
id(relay_mute).turn_off();
|
|
}
|
|
id(relay_answer).turn_off();
|
|
id(last_action).publish_state("none");
|
|
|
|
# Connected answer resistor
|
|
- id: state_answer
|
|
then:
|
|
- lambda: |-
|
|
id(relay_answer).turn_on();
|
|
id(relay_phone).turn_off();
|
|
id(relay_mute).turn_off();
|
|
|
|
# Disconnected all
|
|
- id: state_open
|
|
then:
|
|
- lambda: |-
|
|
id(relay_answer).turn_off();
|
|
id(relay_phone).turn_off();
|
|
id(relay_mute).turn_off();
|
|
|
|
# Accept incoming call
|
|
- id: call_accept
|
|
then:
|
|
- logger.log: "Accept call"
|
|
- delay: !lambda "return id(relay_before_answer_delay).state;"
|
|
- script.execute: state_answer
|
|
- delay: !lambda "return id(relay_answer_on_time).state;"
|
|
- script.execute: state_open
|
|
- delay: !lambda "return id(relay_open_on_time).state;"
|
|
- script.execute: state_answer
|
|
- delay: !lambda "return id(relay_after_open_delay).state;"
|
|
- script.execute: state_ready
|
|
- globals.set:
|
|
id: mode_mute_once
|
|
value: 'false'
|
|
|
|
# Reject incoming call
|
|
- id: call_reject
|
|
then:
|
|
- logger.log: "Reject call"
|
|
- delay: !lambda "return id(relay_before_answer_delay).state;"
|
|
- script.execute: state_answer
|
|
- delay: !lambda "return id(relay_answer_on_time).state;"
|
|
- script.execute: state_ready
|
|
- globals.set:
|
|
id: mode_mute_once
|
|
value: 'false'
|
|
|
|
# Call state
|
|
- id: state_call
|
|
then:
|
|
- 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;
|
|
}
|