-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteslamate_mqtt_device_creation_script.yaml
888 lines (832 loc) · 34.2 KB
/
teslamate_mqtt_device_creation_script.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
## Teslamate Entity Autodiscovery Scripts
# v1.0.4 - Fix for device_tracker state not updating
#
# Instructions:
# 1. Edit variables on lines 20-24 per your own setup.
# 2. Modify, add, or delete any sensors as necessary.
# 3. Save file into your configuration.yaml, or if you use packages save it
# into the packages folder as a separate yaml file.
# 4. In Home Assistant, go to developer tools and reload scripts.
# 5. In Home Assistant, go to scripts and run "Teslamate - Create Entities".
# 6. (Optional) Create an automation to re-run the script every time the
# software version sensor has a state change. This will keep the software
# version shown in the device details in-sync with the actual version.
script:
teslamate_create:
alias: 'Teslamate - Create Entities'
sequence:
- variables:
## Edit These Variables As Needed ##
discovery_prefix: homeassistant
base_topic: teslamate/cars/1
suggested_area: Garage
manufacturer: Tesla
device_name: Tesla Model 3 #every sensor name and entity ID will begin with this
## Sensor friendly names ##
model_sensor_friendly_name: Model Name
sw_version_sensor_friendly_name: Software Version
trim_badge_sensor_friendly_name: Trim Badge
## Only edit variables below if you know what you are doing ##
# If an override is not desired, replace it by two double quotes: ""
model_override: "" #Default = Model <Model> <Trim>.
sw_version_override: "" #Default = <Version>.
identifiers_override: "" #Default = <base_topic>. Must be a list; e.g. "teslamate/cars/1"
- variables:
entity_prefix: "{{ device_name | slugify(separator='_') }}"
node_id: "{{ base_topic | replace('/','_') | lower }}"
- variables:
model_entity_name: "{{ entity_prefix }}_{{ model_sensor_friendly_name | slugify(separator='_') }}"
sw_version_entity_name: "{{ entity_prefix }}_{{ sw_version_sensor_friendly_name | slugify(separator='_') }}"
trim_badge_entity_name: "{{ entity_prefix }}_{{ trim_badge_sensor_friendly_name | slugify(separator='_') }}"
- if:
- alias: "If the model sensor doesn't exist in home assistant"
condition: template
value_template: "{{ states('sensor.' ~ model_entity_name) == 'unknown' }}"
then:
- alias: "Create the model sensor"
service: mqtt.publish
data:
topic_template: "{{ discovery_prefix }}/sensor/{{ node_id }}/model/config"
retain: true
payload: >
{
"name": "{{ device_name }} {{ model_sensor_friendly_name }}",
"unique_id": "{{ base_topic }}/model",
"state_topic": "{{ base_topic }}/model"
}
- if:
- alias: "If the sw_version sensor doesn't exist in home assistant"
condition: template
value_template: "{{ states('sensor.' ~ sw_version_entity_name) == 'unknown' }}"
then:
- alias: "Create the sw version sensor"
service: mqtt.publish
data:
topic_template: "{{ discovery_prefix }}/sensor/{{ node_id }}/version/config"
retain: true
payload: >
{
"name": "{{ device_name }} {{ sw_version_sensor_friendly_name }}",
"unique_id": "{{ base_topic }}/version",
"state_topic": "{{ base_topic }}/version"
}
- if:
- alias: "If the trim badge sensor doesn't exist in home assistant"
condition: template
value_template: "{{ states('sensor.' ~ trim_badge_entity_name) == 'unknown' }}"
then:
- alias: "Create the trim badge sensor"
service: mqtt.publish
data:
topic_template: "{{ discovery_prefix }}/sensor/{{ node_id }}/trim_badging/config"
retain: true
payload: >
{
"name": "{{ device_name }} {{ trim_badge_sensor_friendly_name }}",
"unique_id": "{{ base_topic }}/trim_badging",
"state_topic": "{{ base_topic }}/trim_badging"
}
- alias: "Wait until the trim sensor has data"
wait_template: "{{ states('sensor.' ~ trim_badge_entity_name) != 'unknown' }}"
timeout:
seconds: 5
- alias: "Wait until the model sensor has data"
wait_template: "{{ states('sensor.' ~ model_entity_name) != 'unknown' }}"
timeout:
seconds: 5
- alias: "Wait until the sw version sensor has data"
wait_template: "{{ states('sensor.' ~ sw_version_entity_name) != 'unknown' }}"
timeout:
seconds: 5
- variables:
model: >
{% if model_override|length %}
{{ model_override }}
{% else %}
Model {{ states('sensor.' ~ model_entity_name) }} {{ states('sensor.' ~ trim_badge_entity_name) }}
{% endif %}
sw_version: >
{% if sw_version_override|length %}
{{ sw_version_override }}
{% else %}
{{ states('sensor.' ~ sw_version_entity_name) }}
{% endif %}
identifiers: >
{% if identifiers_override|length %}
{{ identifiers_override }}
{% else %}
{{ base_topic }}
{% endif %}
- variables:
device: >
{
"identifiers": ["{{ identifiers }}"],
"name": "{{ device_name }}",
"model": "{{ model }}",
"manufacturer": "{{ manufacturer }}",
"suggested_area": "{{ suggested_area }}",
"sw_version": "{{ sw_version }}"
}
############ UPDATE SENSORS UTILIZED IN THE DEVICE DETAIL FIRST ############
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: model
sensor_name: '{{ model_sensor_friendly_name }}'
icon: mdi:earth
state_topic_suffix: model
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: version
state_topic_suffix: version
sensor_name: '{{ sw_version_sensor_friendly_name }}'
icon: mdi:numeric
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: trim_badging
state_topic_suffix: trim_badging
sensor_name: '{{ trim_badge_sensor_friendly_name }}'
icon: mdi:numeric
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
############ BINARY SENSORS ############
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: charging
sensor_name: Charger
state_topic_suffix: state
device_class: battery_charging
value_template: \"ON\" if value == \"charging\" else \"OFF\"
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: climate
sensor_name: Climate
state_topic_suffix: is_climate_on
device_class: running
icon: mdi:fan
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: plug
sensor_name: Charge Cable Connected
state_topic_suffix: plugged_in
device_class: plug
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: preconditioning
sensor_name: Preconditioning
state_topic_suffix: is_preconditioning
device_class: running
icon: mdi:fan
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: charge_port
sensor_name: Charge Port Door
state_topic_suffix: charge_port_door_open
device_class: door
icon: mdi:ev-plug-tesla
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: doors
sensor_name: Doors
state_topic_suffix: doors_open
device_class: door
icon: mdi:car-door
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: frunk
sensor_name: Frunk
state_topic_suffix: frunk_open
device_class: door
icon: mdi:car
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: health
sensor_name: Health
state_topic_suffix: healthy
device_class: problem
icon: mdi:heart-pulse
payload_off: 'true'
payload_on: 'false'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: locked
sensor_name: Locked
state_topic_suffix: locked
device_class: lock
payload_off: 'true'
payload_on: 'false'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: occupied
sensor_name: Occupied
state_topic_suffix: is_user_present
device_class: occupancy
icon: mdi:account
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: sentry_mode
sensor_name: Sentry Mode
state_topic_suffix: sentry_mode
icon: mdi:cctv
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: trunk
sensor_name: Trunk
state_topic_suffix: trunk_open
device_class: door
icon: mdi:car
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: update
sensor_name: Update Available
state_topic_suffix: update_available
device_class: update
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: binary_sensor
object_id: windows
sensor_name: Windows Open
state_topic_suffix: windows_open
icon: mdi:car-door
device_class: window
payload_off: 'false'
payload_on: 'true'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
############ SENSORS ############
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: charge_energy_added
sensor_name: Charge Energy Added
state_topic_suffix: charge_energy_added
device_class: energy
unit_of_measurement: kWh
value_template: value | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: limit
sensor_name: Charge Limit
state_class: measurement
state_topic_suffix: charge_limit_soc
icon: mdi:battery-charging-90
unit_of_measurement: '%'
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: charger_current
sensor_name: Charger Current
device_class: current
state_topic_suffix: charger_actual_current
unit_of_measurement: A
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: charger_power
sensor_name: Charger Power
device_class: power
state_topic_suffix: charger_power
unit_of_measurement: kW
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: charger_voltage
sensor_name: Charger Voltage
device_class: voltage
state_topic_suffix: charger_voltage
unit_of_measurement: V
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: start_time
sensor_name: Scheduled Charging Start Time
device_class: timestamp
state_topic_suffix: scheduled_charging_start_time
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: since
sensor_name: Last Update
device_class: timestamp
state_topic_suffix: since
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: time_to_charged
sensor_name: Time Until Full Charge
device_class: duration
unit_of_measurement: h
icon: mdi:timer
state_topic_suffix: time_to_full_charge
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: inside_temp
sensor_name: Inside Temperature
device_class: temperature
state_class: measurement
unit_of_measurement: °C
state_topic_suffix: inside_temp
value_template: value | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: outside_temp
sensor_name: Outside Temperature
device_class: temperature
state_class: measurement
unit_of_measurement: °C
state_topic_suffix: outside_temp
value_template: value | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: elevation
sensor_name: Elevation
unit_of_measurement: ft
icon: mdi:image-filter-hdr
state_topic_suffix: elevation
value_template: (value | float(0) * 3.280839) | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: geofence
sensor_name: Geofence
icon: mdi:earth
state_topic_suffix: geofence
value_template: value
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: heading
sensor_name: Heading
icon: mdi:compass
state_topic_suffix: heading
unit_of_measurement: "°"
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: latitude
state_topic_suffix: latitude
sensor_name: Latitude
icon: mdi:crosshairs-gps
unit_of_measurement: "°"
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: longitude
state_topic_suffix: longitude
sensor_name: Longitude
icon: mdi:crosshairs-gps
unit_of_measurement: "°"
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: power
state_topic_suffix: power
sensor_name: Power
device_class: power
unit_of_measurement: kW
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: speed
state_topic_suffix: speed
sensor_name: Speed
unit_of_measurement: mph
icon: mdi:speedometer
value_template: (value | float(0) / 1.609344) | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: battery
state_topic_suffix: battery_level
sensor_name: Battery Level
state_class: measurement
unit_of_measurement: "%"
device_class: battery
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: odometer
state_topic_suffix: odometer
sensor_name: Odometer
state_class: total_increasing
unit_of_measurement: mi
value_template: (value | float(0) / 1.609344) | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: range
state_topic_suffix: rated_battery_range_km
sensor_name: Battery Range
icon: mdi:map-marker-distance
state_class: measurement
unit_of_measurement: mi
value_template: (value | float(0) / 1.609344) | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: state
state_topic_suffix: state
sensor_name: State
icon: mdi:car-connected
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: tire_pressure_front_left
state_topic_suffix: tpms_pressure_fl
sensor_name: Tire Pressure (Front Left)
icon: mdi:car-tire-alert
state_class: measurement
device_class: pressure
unit_of_measurement: psi
value_template: (value | float(0) * 14.503773) | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: tire_pressure_front_right
state_topic_suffix: tpms_pressure_fr
sensor_name: Tire Pressure (Front Right)
icon: mdi:car-tire-alert
state_class: measurement
device_class: pressure
unit_of_measurement: psi
value_template: (value | float(0) * 14.503773) | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: tire_pressure_rear_left
state_topic_suffix: tpms_pressure_rl
sensor_name: Tire Pressure (Rear Left)
icon: mdi:car-tire-alert
state_class: measurement
device_class: pressure
unit_of_measurement: psi
value_template: (value | float(0) * 14.503773) | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
- service: script.teslamate_backend
data:
sensor_type: sensor
object_id: tire_pressure_rear_right
state_topic_suffix: tpms_pressure_rr
sensor_name: Tire Pressure (Rear Right)
icon: mdi:car-tire-alert
state_class: measurement
device_class: pressure
unit_of_measurement: psi
value_template: (value | float(0) * 14.503773) | round(1)
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
############ DEVICE TRACKER ############
- service: script.teslamate_backend
data:
sensor_type: device_tracker
object_id: location
state_topic_suffix: geofence
sensor_name: Location
icon: mdi:car
json_attributes_template: '{ \"latitude\": value | float(0), \"longitude\": states(\"sensor.{{ entity_prefix }}_longitude\") | float(0) } | tojson'
json_attributes_topic_suffix: latitude
source_type: gps
value_template: \"home\" if value | lower == \"home\" else \"not_home\"
device: '{{ device }}'
discovery_prefix: "{{ discovery_prefix }}"
base_topic: "{{ base_topic }}"
suggested_area: "{{ suggested_area }}"
manufacturer: "{{ manufacturer }}"
device_name: "{{ device_name }}"
teslamate_backend:
alias: "Teslamate - Backend (Don't call direct)"
mode: queued
sequence:
- choose:
- conditions: >
{{ (device is defined and device|length) | bool }}
sequence:
- service: mqtt.publish
data:
# https://www.home-assistant.io/integrations/mqtt/#discovery-messages
topic_template: "{{ discovery_prefix }}/{{ sensor_type }}/{{ base_topic | replace('/','_') }}/{{ object_id }}/config"
retain: true
payload: >-
{
"name": "{{ device_name }} {{ sensor_name }}",
"unique_id": "{{ base_topic | replace("/","_") }}_{{ sensor_name | replace("/","_") | replace(" ","_") | lower }}/{{ object_id }}",
{% if availability_value_template is defined and availability_value_template|length %}
"availability": [{ "topic": "{{ base_topic }}/{{ availability_topic_suffix }}", "value_template": "{{ '{{' }} {{ availability_value_template }} {{ '}}' }}" }],
{% endif %}
{% if device_class is defined and device_class|length %}
"device_class": "{{ device_class }}",
{% endif %}
"state_topic": "{{ base_topic }}/{{ state_topic_suffix }}",
{% if icon is defined and icon|length %}
"icon": "{{ icon }}",
{% endif %}
{% if state_class is defined and state_class|length %}
"state_class": "{{ state_class }}",
{% endif %}
{% if unit_of_measurement is defined and unit_of_measurement|length %}
"unit_of_measurement": "{{ unit_of_measurement }}",
{% endif %}
{% if value_template is defined and value_template|length %}
"value_template": "{{ '{{' }} {{ value_template }} {{ '}}' }}",
{% endif %}
{% if json_attributes_template is defined and json_attributes_template|length %}
"json_attributes_template": "{{ '{{' }} {{ json_attributes_template }} {{ '}}' }}",
{% endif %}
{% if json_attributes_topic_suffix is defined and json_attributes_topic_suffix|length %}
"json_attributes_topic": "{{ base_topic }}/{{ json_attributes_topic_suffix }}",
{% endif %}
{% if command_topic is defined and command_topic|length %}
"command_topic": "{{ command_topic }}",
{% endif %}
{% if payload_on is defined and payload_on|length %}
"payload_on": "{{ payload_on }}",
{% endif %}
{% if payload_off is defined and payload_off|length %}
"payload_off": "{{ payload_off }}",
{% endif %}
"device": {{ device }}
}