-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
home-assistant.yaml
189 lines (189 loc) · 7.01 KB
/
home-assistant.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
################################################################################# Example Home Assistant config
mqtt:
button:
- name: "Car Restart"
command_topic: "car-assistant/commands"
payload_press: "restart"
qos: 0
retain: false
entity_category: "diagnostic"
device_class: "restart"
sensor:
- name: "Car Temperture"
state_topic: "car-assistant/temperature"
unit_of_measurement: "°C"
icon: mdi:thermometer
- name: "Car Humidity"
state_topic: "car-assistant/humidity"
unit_of_measurement: "%"
icon: mdi:water-percent
- name: "Car Pressure"
state_topic: "car-assistant/pressure"
unit_of_measurement: "hPa"
icon: mdi:gauge
- name: "Car Light Level"
state_topic: "car-assistant/lux"
unit_of_measurement: "lux"
icon: mdi:weather-sunny
- name: "Car ESP CPU Temperature"
state_topic: "car-assistant/cpu-temperature"
unit_of_measurement: "°C"
icon: mdi:thermometer
- name: "Car ESP CPU Frequency"
state_topic: "car-assistant/cpu-frequency"
unit_of_measurement: "MHz"
icon: mdi:chip
- name: "Car ESP Free RAM"
state_topic: "car-assistant/free-ram"
unit_of_measurement: "B"
icon: mdi:memory
- name: "Car Hall Sensor"
state_topic: "car-assistant/hall"
icon: mdi:magnet
unit_of_measurement: "μT"
- name: "Car Modem Info"
state_topic: "car-assistant/modem-info"
icon: mdi:cellphone
- name: "Car Modem CCID"
state_topic: "car-assistant/ccid"
icon: mdi:cellphone
- name: "Car Modem IMSI"
state_topic: "car-assistant/imsi"
icon: mdi:cellphone
- name: "Car Modem Operator"
state_topic: "car-assistant/operator"
icon: mdi:cellphone
- name: "Car Signal Quality"
state_topic: "car-assistant/signal-quality"
icon: mdi:cellphone
- name: "Car Public IP"
state_topic: "car-assistant/public-ip"
icon: mdi:cellphone
- name: "Car Battery Percentage"
state_topic: "car-assistant/battery-percentage"
unit_of_measurement: "%"
icon: mdi:battery
- name: "Car Battery Voltage"
state_topic: "car-assistant/battery-voltage"
unit_of_measurement: "V"
icon: mdi:battery
- name: "Car Battery Status"
state_topic: "car-assistant/battery-status"
icon: mdi:battery
- name: "Car Location Type"
state_topic: "car-assistant/location-type"
icon: mdi:map-marker
- name: "Car Latitude"
state_topic: "car-assistant/latitude"
icon: mdi:map-marker
- name: "Car Longitude"
state_topic: "car-assistant/longitude"
icon: mdi:map-marker
- name: "Car Speed"
state_topic: "car-assistant/speed"
unit_of_measurement: "km/h"
icon: mdi:speedometer
- name: "Car Altitude"
state_topic: "car-assistant/altitude"
unit_of_measurement: "m"
icon: mdi:map-marker
- name: "Car Location Accuracy"
state_topic: "car-assistant/location-accuracy"
unit_of_measurement: "m"
icon: mdi:map-marker
- name: "Car ESP Uptime"
state_topic: "car-assistant/uptime"
unit_of_measurement: "s"
icon: mdi:timer-refresh
- name: "Car Assistant Version"
state_topic: "car-assistant/version"
icon: mdi:list-status
binary_sensor:
- name: "Car Motion Sensor"
state_topic: "car-assistant/pir"
icon: mdi:run
payload_on: "1"
payload_off: "0"
device_class: motion
device_tracker:
- name: "Car"
icon: mdi:car
state_topic: "car-assistant/location"
json_attributes_topic: "car-assistant/json-location"
json_attributes_template: "{{ value_json | tojson }}"
################################################################################# Example Home Assistant automation for updating the device tracker
id: "car_assistant_update_location"
alias: "Car Assistant: Update location"
description: "Updates the device tracker with the latest location & zone data from the car"
mode: single
trigger:
- platform: state
entity_id:
- sensor.car_latitude
- platform: state
entity_id:
- sensor.car_longitude
- platform: state
entity_id:
- sensor.car_location_accuracy
- platform: state
entity_id:
- sensor.car_battery_percentage
- platform: state
entity_id:
- sensor.car_speed
condition: []
action:
- service: mqtt.publish
data:
retain: true
topic: car-assistant/json-location
payload_template: >-
{"longitude": "{{ states('sensor.car_longitude') | float }}", "latitude": "{{ states('sensor.car_latitude') | float }}", "gps_accuracy": "{{states('sensor.car_location_accuracy') | int }}", "altitude": "{{states('sensor.car_altitude') | int }}", "battery_level": "{{states('sensor.car_battery_percentage') | int }}", "speed": "{{states('sensor.car_speed') | int }}"}
- service: mqtt.publish
data:
retain: true
topic: car-assistant/location
payload: >
{% set device_longitude = states('sensor.car_longitude') | float %}
{% set device_latitude = states('sensor.car_latitude') | float %}
{% set locations = states.zone | selectattr('attributes.radius', 'defined') | map(attribute='entity_id') | list %}
{% set regex = '^.+\\.(.+)$' %} {# regular expression to match the second part of the entity_id #}
{% set result = namespace(results = none) %}
{% for location in locations %}
{% set zone_entity_id = location.lower().replace(' ', '_') %}
{% set zone_latitude = state_attr(zone_entity_id, 'latitude') %}
{% set zone_longitude = state_attr(zone_entity_id, 'longitude') %}
{% set zone_radius = state_attr(zone_entity_id, 'radius') %}
{% set lat_diff = device_latitude - zone_latitude %}
{% set lon_diff = device_longitude - zone_longitude %}
{% set distance = ((lat_diff ** 2 + lon_diff ** 2) ** 0.5) * 111139 %} {# distance in meters #}
{% set match = location | regex_findall_index(regex) %} {# find the match with the regular expression #}
{% if distance <= zone_radius %}
{% set zone_friendly_name = state_attr(zone_entity_id, 'friendly_name') %}
{% set result.results = zone_friendly_name %}
{% if result.results == 'House' %}
{{ 'Home' }}
{% else %}
{{ result.results }}
{% endif %}
{% endif %}
{% endfor %}
{% if result.results is none %}
{{ 'not_home' }}
{% endif %}
################################################################################# Example Home Assistant automation for restarting Car Assistant
id: "car_assistant_auto_reboot"
alias: "Car Assistant: Auto Reboot"
description: "Automatically reboots the ESP32 & modem every 6 hours"
mode: single
trigger:
- platform: time_pattern
hours: /1
condition: []
action:
- service: button.press
data: {}
target:
entity_id: button.car_restart
#################################################################################