-
Notifications
You must be signed in to change notification settings - Fork 0
/
owntracks_sensor.yaml
98 lines (94 loc) · 3.8 KB
/
owntracks_sensor.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# owntracks_sensor.yaml
#
# Copyright (C) 2022 Daniele Bochicchio, All Rights Reserved
# For updates see https://github.com/dbochicchio/reactor-mqtt-contrib
#
# *** IMPORTANT ***
# Every time you update the files, a restart is needed.
---
templates:
# Owntracks adavanced templates
owntracks_sensor:
type: BinarySensor
capabilities: ["string_sensor", "binary_sensor", "battery_power", "battery_maintenance", "location"]
primary_attribute: string_sensor.value
requires: [topic, prefix, homeRegionName]
description: Owntracks position
events:
# position updates
"owntracks/%prefix%/%topic%":
# string_sensor for location - support for both native MQTT and MQTT-via-HTTP method
"string_sensor.value":
json_payload: true
if_expr: "payload._type == 'location' || payload._type == 'transition'"
expr: >
desc = payload._type == 'location' ? join( ( payload.inregions ?? [] ), ', ') :
(payload._type == 'transition' && payload.event == 'enter') ? payload.data?.description : null,
desc = desc == '' ? null: desc,
desc ?? notHomeRegionName ?? ''
# battery_power for phone battery
"battery_power.level":
json_payload: true
if_expr: "!isNaN(payload.batt)"
expr: "float(payload.batt)/100"
"battery_power.since":
expr: "time()"
# battery_maintenance for phone battery
"battery_maintenance.charging":
json_payload: true
if_expr: "!isNaN(payload.bs)"
expr: "float(payload.bs) != 1"
"battery_maintenance.replace":
expr: "false"
# BinarySensor for home
"binary_sensor.state":
json_payload: true
if_expr: "payload._type == 'location'"
expr: >
( first reg in ( payload.inregions ?? [] ) with lower(reg) == lower(homeRegionName): true ) ?? false
# location details
"location.latitude":
json_payload: true
expr: "isNaN(payload.lat) ? null : float(payload.lat)"
"location.longitude":
json_payload: true
expr: "isNaN(payload.lon) ? null : float(payload.lon)"
"location.elevation":
json_payload: true
expr: "isNaN(payload.alt) ? null : float(payload.alt)"
# lwt
"x_mqtt_device.online":
json_payload: true
# IMPRV: check if this is consistent. every message will update online status
if_expr: "payload._type == 'lwt'"
expr: "payload.tst < time()/1000"
# enter/leave topics
"owntracks/%prefix%/%topic%/event":
# leave BinarySensor for home
"binary_sensor.state":
json_payload: true
if_expr: "payload._type == 'transition' && (payload.event == 'leave' || payload.event == 'enter')"
expr: >
desc = payload.data?.description ?? payload?.desc ?? '',
( payload.event == 'leave' && lower(desc) != lower(homeRegionName) ) ||
( payload.event == 'enter' && lower(desc) == lower(homeRegionName) )
"string_sensor.value":
json_payload: true
if_expr: "payload._type == 'transition'"
expr: >
desc = payload.data?.description ?? payload?.desc ?? '',
(payload._type == 'transition' && payload.event == 'enter') ? desc :
(notHomeRegionName ?? '')
# location details
"location.latitude":
json_payload: true
if_expr: "!isNaN(payload.lat)"
expr: "float(payload.lat)"
"location.longitude":
json_payload: true
if_expr: "!isNaN(payload.lon)"
expr: "float(payload.lon)"
"location.elevation":
json_payload: true
if_expr: "!isNaN(payload.alt)"
expr: "float(payload.alt)"