-
Notifications
You must be signed in to change notification settings - Fork 10
/
sensors.yaml
101 lines (99 loc) · 3.75 KB
/
sensors.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
99
100
101
#
# Sensor Tracks the name of home WiFi Access Point (AP)
#
# This uses the unifi integration to query the unifi APs for their state.
#
- platform: template
sensors:
home_ap_user1:
entity_id: device_tracker.iphone
value_template: >-
{% set ap_mac_map = {
'DinningInWall': '78:8A:20:00:00:00',
'DownstairsAP': 'FC:EC:DA:00:00:00',
'GardenAP': 'FC:EC:DA:01:00:00'
} -%}
{%- set tracker = 'device_tracker.user1_phone' %}
{%- set ns = namespace(ap='unknown') %}
{%- if not is_state( tracker ) %}
{%- set ns.ap = 'away' %}
{%- else %}
{%- set mac = state_attr( tracker , 'ap_mac').upper() %}
{%- for ap, ap_mac in ap_mac_map.items() %}
{%- if ap_mac == mac %}
{%- set ns.ap = ap -%}
{%- endif %}
{%- endfor %}
{%- endif %}
{{ ns.ap }}
#
# Sensor produces Weasley Clock states
#
# home, garden, school, work, intransit, mortalperil, lost, error
#
# home/school/work/lost/intransit/lost is determined by life360 location
# garden is based on which of the home WiFi access points is being used
# mortalperil is triggered by life360 detecting speeds over 75
# error is triggered if the life360 device_tracker returns None type
#
- platform: template
sensors:
weasley_clock_user1:
entity_id:
- sensor.home_ap_user1
- proximity.user1
- device_tracker.life360_user1
icon_template: >-
{% set icon = 'mdi:clock-outline' %}
{% set s = 'sensor.weasley_clock_user1' %}
{% if states(s) == 'school' %}
{% set icon = 'mdi:school' %}
{% elif states(s) == 'home' %}
{% set icon = 'mdi:home' %}
{% elif states(s) == 'barn' %}
{% set icon = 'mdi:barn' %}
{% elif states(s) == 'lost' %}
{% set icon = 'mdi:map-marker-question' %}
{% elif states(s) == 'intransit' %}
{% set icon = 'mdi:train-car' %}
{% elif states(s) == 'work' %}
{% set icon = 'mdi:briefcase' %}
{% elif states(s) == 'garden' %}
{% set icon = 'mdi:flower' %}
{% elif states(s) == 'mortalperil' %}
{% set icon = 'mdi:speedometer' %}
{% elif states(s) == 'quidditch' %}
{% set icon = 'mdi:broom' %}
{% endif %}
{{ icon }}
value_template: >-
{%- set home_ap_sensor = 'sensor.home_ap_user1' %}
{%- set tracker = 'device_tracker.life360_user1' %}
{%- set ns = namespace(wc='lost') %}
{%- set state = states( tracker ) %}
{%- if not state %}
{%- set ns.wc = 'error' %}
{%- elif state == 'home' %}
{%- set home_ap = states( home_ap_sensor ) %}
{%- if home_ap == 'GardenAP' %}
{%- set ns.wc = 'garden' -%}
{%- else %}
{%- set ns.wc = 'home' -%}
{%- endif %}
{%- elif state == 'moving' or state == 'driving' %}
{%- set ns.wc = 'intransit' %}
{%- set speed = state_attr( tracker, 'speed') %}
{%- if speed and speed > 75 %}
{%- set ns.wc = 'mortalperil' %}
{%- endif %}
{%- else %}
{%- set place = state.lower() %}
{%- if place == 'your local high school' or place == 'your local middle school'%}
{%- set ns.wc = 'school' %}
{%- elif place == 'work' %}
{%- set ns.wc = 'work' %}
{%- else %}
{%- set ns.wc = 'lost' %}
{%- endif %}
{%- endif -%}
{{ ns.wc }}