docs: update klingel
This commit is contained in:
parent
9f43677681
commit
50e859b46a
178
klingel.md
178
klingel.md
|
|
@ -2,7 +2,7 @@
|
||||||
title: Door bell
|
title: Door bell
|
||||||
description:
|
description:
|
||||||
published: 1
|
published: 1
|
||||||
date: 2024-03-03T16:06:03.702Z
|
date: 2024-03-03T16:09:33.767Z
|
||||||
tags:
|
tags:
|
||||||
editor: markdown
|
editor: markdown
|
||||||
dateCreated: 2024-03-02T02:22:57.232Z
|
dateCreated: 2024-03-02T02:22:57.232Z
|
||||||
|
|
@ -54,6 +54,182 @@ https://forum.arduino.cc/t/wlan-klingel-mit-esp8266-fur-fritzbox/589769
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Code
|
||||||
|
|
||||||
|
```
|
||||||
|
//DoorBell.ino
|
||||||
|
#include <Homie.h>
|
||||||
|
|
||||||
|
int readDelay = 50;
|
||||||
|
int buttonPressDelay = 3000;
|
||||||
|
int openingDelay = 3000;
|
||||||
|
int inputPin = D3;
|
||||||
|
int relayPin = D1;
|
||||||
|
int inputValue = 0;
|
||||||
|
bool opened = false;
|
||||||
|
int timeOpened = 0;
|
||||||
|
|
||||||
|
HomieNode doorbellNode("button", "button");
|
||||||
|
HomieNode openerNode("switch", "switch");
|
||||||
|
|
||||||
|
boolean openerHandler(const HomieRange& range, const String& value) {
|
||||||
|
if(value != "true" && value != "false") return false;
|
||||||
|
|
||||||
|
if(value == "true") {
|
||||||
|
digitalWrite(relayPin, HIGH);
|
||||||
|
openerNode.setProperty("on").send("true");
|
||||||
|
Serial.println("Opener started ...");
|
||||||
|
opened = true;
|
||||||
|
timeOpened = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void loopHandler() {
|
||||||
|
inputValue = digitalRead(inputPin);
|
||||||
|
|
||||||
|
digitalWrite(BUILTIN_LED, inputValue);
|
||||||
|
|
||||||
|
if(inputValue == 0) {
|
||||||
|
Serial.println("Doorbell pressed ...");
|
||||||
|
doorbellNode.setProperty("pressed").send("true");
|
||||||
|
delay(buttonPressDelay);
|
||||||
|
doorbellNode.setProperty("pressed").send("false");
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(readDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
pinMode(inputPin, INPUT_PULLUP);
|
||||||
|
pinMode(BUILTIN_LED, OUTPUT);
|
||||||
|
pinMode(relayPin, OUTPUT);
|
||||||
|
|
||||||
|
digitalWrite(relayPin, LOW);
|
||||||
|
|
||||||
|
Homie_setBrand("doorbell");
|
||||||
|
Homie_setFirmware("Doorbell", "1.0.0");
|
||||||
|
|
||||||
|
openerNode.advertise("on").settable(openerHandler);
|
||||||
|
Homie.setLoopFunction(loopHandler);
|
||||||
|
|
||||||
|
Homie.setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
int timeNow = millis();
|
||||||
|
|
||||||
|
if(timeOpened > 0 && (timeNow - timeOpened) > 3000) {
|
||||||
|
Serial.println("Close ...");
|
||||||
|
Serial.println(timeNow);
|
||||||
|
Serial.println(timeOpened);
|
||||||
|
timeOpened = 0;
|
||||||
|
|
||||||
|
digitalWrite(relayPin, LOW);
|
||||||
|
openerNode.setProperty("on").send("false");
|
||||||
|
Serial.println("Opener finished ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
Homie.loop();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Die dazugehörige config.json würde wie folgt aussehen:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"name": "Doorbell",
|
||||||
|
"device_id": "c01",
|
||||||
|
"wifi": {
|
||||||
|
"ssid": "[SSID]",
|
||||||
|
"password": "[PASSWORD]"
|
||||||
|
},
|
||||||
|
"mqtt": {
|
||||||
|
"host": "192.168.178.54",
|
||||||
|
"port": 1883,
|
||||||
|
"base_topic": "doorbell/",
|
||||||
|
"auth": true,
|
||||||
|
"username": "homeassistant",
|
||||||
|
"password": ""
|
||||||
|
},
|
||||||
|
"ota": {
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Zum Thema Homie und Wemos D1 mini werde ich noch einen weiteren Artikel schreiben.
|
||||||
|
|
||||||
|
Anbindung an Home-Assistant
|
||||||
|
```
|
||||||
|
#configuration.yaml
|
||||||
|
mqtt:
|
||||||
|
embedded:
|
||||||
|
binary_sensor:
|
||||||
|
- platform: "mqtt"
|
||||||
|
name: intercom_bell
|
||||||
|
state_topic: "doorbell/c01/button/pressed"
|
||||||
|
payload_on: "true"
|
||||||
|
payload_off: "false"
|
||||||
|
device_class: "sound"
|
||||||
|
retain: true
|
||||||
|
switch:
|
||||||
|
- platform: mqtt
|
||||||
|
name: intercom_opener
|
||||||
|
state_topic: "doorbell/c01/switch/on"
|
||||||
|
command_topic: "doorbell/c01/switch/on/set"
|
||||||
|
payload_on: "true"
|
||||||
|
payload_off: "false"
|
||||||
|
retain: true
|
||||||
|
icon: mdi:lock
|
||||||
|
#customize.yaml
|
||||||
|
binary_sensor.intercom_bell:
|
||||||
|
friendly_name: Klingel
|
||||||
|
switch.intercom_opener:
|
||||||
|
friendly_name: Türöffner
|
||||||
|
```
|
||||||
|
|
||||||
|
Regeln für Telegram
|
||||||
|
```
|
||||||
|
#automation.yaml
|
||||||
|
- alias: 'Telegram Bot: Benachrichtige über klingeln'
|
||||||
|
trigger:
|
||||||
|
platform: state
|
||||||
|
entity_id: binary_sensor.intercom_bell
|
||||||
|
from: 'off'
|
||||||
|
to: 'on'
|
||||||
|
action:
|
||||||
|
- service: telegram_bot.send_message
|
||||||
|
data_template:
|
||||||
|
message: 'Es klingelt an der Tür'
|
||||||
|
disable_notification: true
|
||||||
|
inline_keyboard:
|
||||||
|
- "Tür öffnen:/open_door"
|
||||||
|
|
||||||
|
- alias: 'Telegram Bot: Öffne die Tür'
|
||||||
|
trigger:
|
||||||
|
platform: event
|
||||||
|
event_type: telegram_callback
|
||||||
|
event_data:
|
||||||
|
data: '/open_door'
|
||||||
|
action:
|
||||||
|
- service: telegram_bot.edit_replymarkup
|
||||||
|
data_template:
|
||||||
|
message_id: 'last'
|
||||||
|
chat_id: '{{ trigger.event.data.chat_id }}'
|
||||||
|
inline_keyboard: []
|
||||||
|
- service: telegram_bot.send_message
|
||||||
|
data_template:
|
||||||
|
target: '{{ trigger.event.data.user_id }}'
|
||||||
|
message: 'Die Tür wird geöffnet'
|
||||||
|
disable_notification: true
|
||||||
|
- service: switch.turn_on
|
||||||
|
entity_id: switch.intercom_opener
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue