]> git.giorgioravera.it Git - homeassistant.git/commitdiff
Added NFC management (preliminary)
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Fri, 6 May 2022 11:42:33 +0000 (13:42 +0200)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Fri, 6 May 2022 11:42:33 +0000 (13:42 +0200)
automations/nfc.yaml [new file with mode: 0644]

diff --git a/automations/nfc.yaml b/automations/nfc.yaml
new file mode 100644 (file)
index 0000000..1c35e01
--- /dev/null
@@ -0,0 +1,64 @@
+######################################################################
+# NFC: Notification
+######################################################################
+
+- id: nfc_scan_notification
+  alias: "NFC Notifica Scansione"
+  mode: single
+  max_exceeded: silent
+  variables:
+    allowed_devices:
+      !secret giorgio_smartphone_nfc:
+        name: "Giorgio"
+      !secret laura_smartphone_nfc:
+        name: "Laura"
+    allowed_tags:
+      !secret nfc_1:
+        name: "NFC_1"
+
+  trigger:
+    platform: event
+    event_type: tag_scanned
+
+  action:
+    - variables:
+        detected_tag: "{{ trigger.event.data.tag_id }}"
+        detected_device: "{{ trigger.event.data.device_id }}"
+
+    - choose:
+      - conditions:
+          - "{{ detected_tag in allowed_tags }}"
+          - "{{ detected_device in allowed_devices }}"
+        sequence:
+        - service: script.notify_text
+          data_template:
+            title: "Home Assistant - Lettura NFC"
+            message: "Letto tag NFC {{ allowed_tags[detected_tag].name }} dal dispositivo {{ allowed_devices[detected_device].name }}."
+            disable_telegram: true
+
+      - conditions:
+          - "{{ detected_tag in allowed_tags }}"
+          - "{{ detected_device not in allowed_devices }}"
+        sequence:
+        - service: script.notify_text
+          data_template:
+            title: "Home Assistant - Lettura NFC"
+            message: "Letto tag NFC {{ allowed_tags[detected_tag].name }} da dispositivo non valido ({{ detected_device }})."
+            disable_telegram: true
+
+      - conditions:
+          - "{{ detected_tag not in allowed_tags }}"
+          - "{{ detected_device in allowed_devices }}"
+        sequence:
+        - service: script.notify_text
+          data_template:
+            title: "Home Assistant - Lettura NFC"
+            message: "Letto tag NFC non riconosciuto ({{ detected_tag }}) dal dispositivo {{ allowed_devices[detected_device].name }}."
+            disable_telegram: true
+
+      default:
+        - service: script.notify_text
+          data_template:
+            title: "Home Assistant - Lettura NFC"
+            message: "Letto tag NFC non valido ({{ detected_tag }}) da dispositivo non valido ({{ detected_device }})."
+            disable_telegram: true