-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwithings-weight-notification.yaml
66 lines (61 loc) · 2.63 KB
/
withings-weight-notification.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
blueprint:
name: Vektendring Notifikasjon
description: >
Sender en notifikasjon ved vektendring med endring siden forrige måling og over den siste måneden.
**Merk:** Denne blueprinten krever at du har en SQL-sensor som henter vekten din fra én måned siden. Se instruksjonene i README-filen for hvordan du setter opp dette.
domain: automation
input:
weight_sensor:
name: Vektsensor
description: Entitets-ID for vektsensoren din.
selector:
entity:
domain: sensor
sql_sensor:
name: SQL-sensor for vekt en måned siden
description: Entitets-ID for SQL-sensoren som henter vekten din fra én måned siden.
selector:
entity:
domain: sensor
notification_service:
name: Notifikasjonstjeneste
description: Navnet på notifikasjonstjenesten din (f.eks. `notify.mobile_app_din_mobil`).
selector:
text:
source_url: https://github.com/dittbrukernavn/blueprints/vektendring_notifikasjon.yaml
trigger:
- platform: state
entity_id: !input weight_sensor
variables:
weight_sensor: !input weight_sensor
sql_sensor: !input sql_sensor
notification_service: !input notification_service
action:
- variables:
current_weight: "{{ states(weight_sensor) | float }}"
previous_weight: "{{ trigger.from_state.state | float(0) }}"
weight_change: "{{ (current_weight - previous_weight) | round(1) }}"
change_word: "{{ 'nedgang' if weight_change < 0 else 'oppgang' }}"
weight_change_abs: "{{ weight_change | abs }}"
month_ago_weight_state: "{{ states(sql_sensor) }}"
month_data_available: "{{ month_ago_weight_state not in ['unknown', 'unavailable', '0'] }}"
- if:
- condition: template
value_template: "{{ month_data_available }}"
then:
- variables:
month_ago_weight: "{{ month_ago_weight_state | float(0) }}"
month_change: "{{ (current_weight - month_ago_weight) | round(1) }}"
month_change_word: "{{ 'nedgang' if month_change < 0 else 'oppgang' }}"
month_change_abs: "{{ month_change | abs }}"
message: >
Din nye vekt er {{ current_weight }} kg. Det er en {{ change_word }} på {{ weight_change_abs }} kg siden sist og en {{ month_change_word }} på {{ month_change_abs }} kg siste måneden.
else:
- variables:
message: >
Din nye vekt er {{ current_weight }} kg. Det er en {{ change_word }} på {{ weight_change_abs }} kg siden sist. Data fra én måned siden er ikke tilgjengelig.
- service: !input notification_service
data:
title: Vektoppdatering
message: "{{ message }}"
mode: single