README ergänzt, HA-Benachrichtigung optional
This commit is contained in:
parent
fdc2eb6c07
commit
d48080da27
53
README.md
53
README.md
@ -86,6 +86,7 @@ $test_url = "https://example.com/plweb/test.php?";
|
|||||||
|
|
||||||
Die Variable `hawebhook` enthält die URL des Home Assistant-Webhooks, so wie dieser
|
Die Variable `hawebhook` enthält die URL des Home Assistant-Webhooks, so wie dieser
|
||||||
von PlusLifeWeb aus (serverseitig) aufgerufen wird.
|
von PlusLifeWeb aus (serverseitig) aufgerufen wird.
|
||||||
|
Wird die Variable leer gelassen (`""`), so wird die Home Assistant-Benachrichtigung deaktiviert.
|
||||||
|
|
||||||
Die Datenbankkonfiguration ist in `dbconnstring` enthalten. Hier ggf. das Paßwort anpassen.
|
Die Datenbankkonfiguration ist in `dbconnstring` enthalten. Hier ggf. das Paßwort anpassen.
|
||||||
|
|
||||||
@ -93,3 +94,55 @@ Die `test_url` zeigt zum Script test.php der PlusLifeWeb-Installation.
|
|||||||
Diese URL wird, zusammen mit der ID des fertigen Tests, als Benachrichtigung an Home
|
Diese URL wird, zusammen mit der ID des fertigen Tests, als Benachrichtigung an Home
|
||||||
Assistant übertragen.
|
Assistant übertragen.
|
||||||
|
|
||||||
|
### Home Assistant
|
||||||
|
|
||||||
|
Um die Home Assistant (HA)-Benachrichtigung zu nutzen, muß in HA eine Automatisierung
|
||||||
|
eingerichtet werden, die per Webhook-Aufruf aktiviert wird.
|
||||||
|
|
||||||
|
Diese kann beispielsweise so aussehen:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
alias: Webhook PlusLifeWeb
|
||||||
|
triggers:
|
||||||
|
- trigger: webhook
|
||||||
|
allowed_methods:
|
||||||
|
- POST
|
||||||
|
local_only: true
|
||||||
|
webhook_id: plweb
|
||||||
|
actions:
|
||||||
|
- if:
|
||||||
|
- condition: template
|
||||||
|
value_template: "{% if trigger.json.url is defined %}true{% endif %}"
|
||||||
|
then:
|
||||||
|
- action: notify.familie
|
||||||
|
metadata: {}
|
||||||
|
data:
|
||||||
|
message: |-
|
||||||
|
{{ trigger.json.message }}
|
||||||
|
Klicken, um den Test anzusehen.
|
||||||
|
data:
|
||||||
|
clickAction: "{{ trigger.json.url }}"
|
||||||
|
group: plweb
|
||||||
|
title: PlusLifeWeb
|
||||||
|
else:
|
||||||
|
- action: notify.familie
|
||||||
|
metadata: {}
|
||||||
|
data:
|
||||||
|
message: "{{ trigger.json.message }}"
|
||||||
|
title: PlusLifeWeb
|
||||||
|
data:
|
||||||
|
group: plweb
|
||||||
|
mode: single
|
||||||
|
```
|
||||||
|
|
||||||
|
**Wichtig:** Der Wert für `webhook_id` ist quasi das Paßwort für den Webhook - es gibt keine weitere
|
||||||
|
Authentifizierung für den Aufruf des Webhooks. Falls `local_only` auf `false` gesetzt ist, kann der
|
||||||
|
Webhook auch aus dem Internet aufgerufen werden (sofern HA von dort aus erreichbar ist).
|
||||||
|
Die Empfehlung wäre, den Webhook nur im lokalen LAN erreichbar zu machen (`local_only: true`) und eine
|
||||||
|
sichere `webhook_id` zu benutzen.
|
||||||
|
Dies setzt allerdings voraus, daß PlusLifeWeb und der HA-Server im gleichen lokalen LAN stehen.
|
||||||
|
|
||||||
|
Die Benachrichtigung erfolgt im Beispiel an `notify.familie`, eine Benachrichtigungs-Gruppe.
|
||||||
|
Hier muß eine im eigenen HA vorhandene notify-Entität genutzt werden :)
|
||||||
|
|
||||||
|
|
||||||
|
11
config.php
11
config.php
@ -1,7 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$hawebhook = "http://homie:8123/api/webhook/plweb"; // Webhook-URL von Home Assistant
|
# Benachrichtigung via Home Assistant
|
||||||
|
# Hier die Webhook-URL eintragen:
|
||||||
|
$hawebhook = "http://homie:8123/api/webhook/plweb";
|
||||||
|
# Alternativ: Feld leer lassen, um Benachrichtigung zu deaktivieren:
|
||||||
|
# $hawebhook = ""; // HA-Benachrichtigung deaktivieren
|
||||||
|
|
||||||
|
# Datenbank-Verbindung:
|
||||||
$dbconnstring = "host=localhost dbname=plweb user=plweb password=plweb";
|
$dbconnstring = "host=localhost dbname=plweb user=plweb password=plweb";
|
||||||
|
|
||||||
|
# URL zu PlusLifeWeb, wird für die Home Assistant-Benachrichtigung benutzt.
|
||||||
|
# Ans Ende wird die ID des Tests angefügt.
|
||||||
$test_url = "https://sinclair.narnia.lan/plweb/test.php?id=";
|
$test_url = "https://sinclair.narnia.lan/plweb/test.php?id=";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
22
webhook.php
22
webhook.php
@ -42,16 +42,18 @@ switch ($data['event']) {
|
|||||||
function send_notification($msg, $url = null) {
|
function send_notification($msg, $url = null) {
|
||||||
global $hawebhook;
|
global $hawebhook;
|
||||||
|
|
||||||
$post = [ 'message' => $msg ];
|
if ($hawebhook != "") {
|
||||||
if ($url != null) $post['url'] = $url;
|
$post = [ 'message' => $msg ];
|
||||||
|
if ($url != null) $post['url'] = $url;
|
||||||
$ch = curl_init($hawebhook);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
$ch = curl_init($hawebhook);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
$rc = curl_exec($ch);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
|
||||||
curl_close($ch);
|
$rc = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_finished() {
|
function test_finished() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user