@@ -25,7 +25,7 @@ function configHADeviceEnvVars() {
2525
2626 TOPIC_ROOT=tesla_ble/${vin}
2727
28- QOS_LEVEL=1
28+ QOS_LEVEL=0
2929
3030 log_debug " DEV_ID=$DEV_ID "
3131 log_debug " DEV_NAME=$DEV_NAME "
@@ -55,23 +55,23 @@ function setupHADevicePanelCardsMain() {
5555 if [ -f $KEYS_DIR /${vin} _pubkey_accepted ]; then
5656 log_debug " setupHADevicePanelCardsMain() found vehicle with pubkey deployed vin:$vin "
5757 setupHADeviceDeployKeyButton $vin
58- setupHADeviceGenerateKeysButton $vin
58+ setupHADeviceReGenerateKeysButton $vin
5959 setupHADeviceControlsCard $vin
60- setupHADeviceScanBLElnButton $vin
60+ setupHADeviceInfoBTadapter $vin
6161 elif [ ! -f $KEYS_DIR /${vin} _private.pem ] && [ ! -f $KEYS_DIR /${vin} _public.pem ]; then
6262
6363 log_debug " setupHADevicePanelCardsMain() found new vehicle, need to generate keys set vin:$vin "
6464 # Show button to Generate Keys
6565 setupHADeviceGenerateKeysButton $vin
66- setupHADeviceScanBLElnButton $vin
66+ setupHADeviceInfoBTadapter $vin
6767
6868 # listen_to_mqtt call setupHADeviceDeployKeyButton once the keys are generated
6969
7070 else
7171 log_debug " setupHADevicePanelCardsMain() found new vehicle, need to deploy public key vin:$vin "
7272 setupHADeviceDeployKeyButton $vin
7373 setupHADeviceGenerateKeysButton $vin
74- setupHADeviceScanBLElnButton $vin
74+ setupHADeviceInfoBTadapter $vin
7575 fi
7676
7777 log_debug " setupHADevicePanelCardsMain() leaving vin:$vin "
@@ -104,7 +104,7 @@ function setupHADeviceControlsCard() {
104104 "payload_press": "wake",
105105 "qos": "' ${QOS_LEVEL} ' ",
106106 "unique_id": "' ${DEV_ID} ' _wake"
107- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /wake/config -l
107+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /wake/config -l
108108
109109 echo ' {
110110 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -121,7 +121,7 @@ function setupHADeviceControlsCard() {
121121 "payload_press": "flash-lights",
122122 "qos": "' ${QOS_LEVEL} ' ",
123123 "unique_id": "' ${DEV_ID} ' _flash-lights"
124- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /flash-lights/config -l
124+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /flash-lights/config -l
125125
126126 echo ' {
127127 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -138,7 +138,7 @@ function setupHADeviceControlsCard() {
138138 "payload_press": "honk",
139139 "qos": "' ${QOS_LEVEL} ' ",
140140 "unique_id": "' ${DEV_ID} ' _honk"
141- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /honk/config -l
141+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /honk/config -l
142142
143143 echo ' {
144144 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -155,7 +155,7 @@ function setupHADeviceControlsCard() {
155155 "payload_press": "lock",
156156 "qos": "' ${QOS_LEVEL} ' ",
157157 "unique_id": "' ${DEV_ID} ' _lock"
158- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /lock/config -l
158+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /lock/config -l
159159
160160 echo ' {
161161 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -172,7 +172,7 @@ function setupHADeviceControlsCard() {
172172 "payload_press": "unlock",
173173 "qos": "' ${QOS_LEVEL} ' ",
174174 "unique_id": "' ${DEV_ID} ' _unlock"
175- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /unlock/config -l
175+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /unlock/config -l
176176
177177 echo ' {
178178 "command_topic": "' ${TOPIC_ROOT} ' /auto-seat-and-climate",
@@ -189,7 +189,7 @@ function setupHADeviceControlsCard() {
189189 "payload_press": "auto-seat-and-climate",
190190 "qos": "' ${QOS_LEVEL} ' ",
191191 "unique_id": "' ${DEV_ID} ' _auto_seat-climate"
192- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /auto-seat-and-climate/config -l
192+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /auto-seat-and-climate/config -l
193193
194194 echo ' {
195195 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -206,7 +206,7 @@ function setupHADeviceControlsCard() {
206206 "payload_press": "climate-off",
207207 "qos": "' ${QOS_LEVEL} ' ",
208208 "unique_id": "' ${DEV_ID} ' _climate-off"
209- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /climate-off/config -l
209+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /climate-off/config -l
210210
211211 echo ' {
212212 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -223,7 +223,7 @@ function setupHADeviceControlsCard() {
223223 "payload_press": "climate-on",
224224 "qos": "' ${QOS_LEVEL} ' ",
225225 "unique_id": "' ${DEV_ID} ' _climate-on"
226- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /climate-on/config -l
226+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /climate-on/config -l
227227
228228 echo ' {
229229 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -240,7 +240,7 @@ function setupHADeviceControlsCard() {
240240 "payload_press": "trunk-open",
241241 "qos": "' ${QOS_LEVEL} ' ",
242242 "unique_id": "' ${DEV_ID} ' _trunk-open"
243- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /trunk-open/config -l
243+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /trunk-open/config -l
244244
245245 echo ' {
246246 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -257,7 +257,7 @@ function setupHADeviceControlsCard() {
257257 "payload_press": "trunk-close",
258258 "qos": "' ${QOS_LEVEL} ' ",
259259 "unique_id": "' ${DEV_ID} ' _trunk-close"
260- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /trunk-close/config -l
260+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /trunk-close/config -l
261261
262262 echo ' {
263263 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -274,7 +274,7 @@ function setupHADeviceControlsCard() {
274274 "payload_press": "frunk-open",
275275 "qos": "' ${QOS_LEVEL} ' ",
276276 "unique_id": "' ${DEV_ID} ' _frunk-open"
277- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /frunk-open/config -l
277+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /frunk-open/config -l
278278
279279 echo ' {
280280 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -291,7 +291,7 @@ function setupHADeviceControlsCard() {
291291 "payload_press": "charging-start",
292292 "qos": "' ${QOS_LEVEL} ' ",
293293 "unique_id": "' ${DEV_ID} ' _charging-start"
294- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /charging-start/config -l
294+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /charging-start/config -l
295295
296296 echo ' {
297297 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -308,7 +308,7 @@ function setupHADeviceControlsCard() {
308308 "payload_press": "charging-stop",
309309 "qos": "' ${QOS_LEVEL} ' ",
310310 "unique_id": "' ${DEV_ID} ' _charging-stop"
311- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /charging-stop/config -l
311+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /charging-stop/config -l
312312
313313 echo ' {
314314 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -325,7 +325,7 @@ function setupHADeviceControlsCard() {
325325 "payload_press": "charge-port-open",
326326 "qos": "' ${QOS_LEVEL} ' ",
327327 "unique_id": "' ${DEV_ID} ' _charge-port-open"
328- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /charge-port-open/config -l
328+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /charge-port-open/config -l
329329
330330 echo ' {
331331 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -342,7 +342,7 @@ function setupHADeviceControlsCard() {
342342 "payload_press": "charge-port-close",
343343 "qos": "' ${QOS_LEVEL} ' ",
344344 "unique_id": "' ${DEV_ID} ' _charge-port-close"
345- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /charge-port-close/config -l
345+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /charge-port-close/config -l
346346
347347 echo ' {
348348 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -359,7 +359,7 @@ function setupHADeviceControlsCard() {
359359 "payload_press": "windows-close",
360360 "qos": "' ${QOS_LEVEL} ' ",
361361 "unique_id": "' ${DEV_ID} ' _windows-close"
362- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /windows-close/config -l
362+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /windows-close/config -l
363363
364364 echo ' {
365365 "command_topic": "' ${TOPIC_ROOT} ' /command",
@@ -376,7 +376,7 @@ function setupHADeviceControlsCard() {
376376 "payload_press": "windows-vent",
377377 "qos": "' ${QOS_LEVEL} ' ",
378378 "unique_id": "' ${DEV_ID} ' _windows-vent"
379- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /windows-vent/config -l
379+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /windows-vent/config -l
380380
381381 echo ' {
382382 "command_topic": "' ${TOPIC_ROOT} ' /charging-set-amps",
@@ -397,7 +397,7 @@ function setupHADeviceControlsCard() {
397397 "unit_of_measurement": "A",
398398 "qos": "' ${QOS_LEVEL} ' ",
399399 "icon": "mdi:current-ac"
400- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/number/${DEV_ID} /charging-set-amps/config -l
400+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEV_ID} /charging-set-amps/config -l
401401
402402 echo ' {
403403 "command_topic": "' ${TOPIC_ROOT} ' /charging-set-amps-override",
@@ -419,7 +419,7 @@ function setupHADeviceControlsCard() {
419419 "qos": "' ${QOS_LEVEL} ' ",
420420 "icon": "mdi:current-ac",
421421 "entity_category": "diagnostic"
422- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/number/${DEV_ID} /charging-set-amps-override/config -l
422+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEV_ID} /charging-set-amps-override/config -l
423423
424424 echo ' {
425425 "command_topic": "' ${TOPIC_ROOT} ' /charging-set-limit",
@@ -440,7 +440,7 @@ function setupHADeviceControlsCard() {
440440 "unit_of_measurement": "%",
441441 "qos": "' ${QOS_LEVEL} ' ",
442442 "icon": "mdi:battery-90"
443- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/number/${DEV_ID} /charging-set-limit/config -l
443+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEV_ID} /charging-set-limit/config -l
444444
445445 echo ' {
446446 "command_topic": "' ${TOPIC_ROOT} ' /climate-set-temp",
@@ -461,7 +461,7 @@ function setupHADeviceControlsCard() {
461461 "unit_of_measurement": "°C",
462462 "qos": "' ${QOS_LEVEL} ' ",
463463 "icon": "mdi:temperature"
464- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/number/${DEV_ID} /climate-temp/config -l
464+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEV_ID} /climate-temp/config -l
465465
466466 echo ' {
467467 "command_topic": "' ${TOPIC_ROOT} ' /steering-wheel-heater",
@@ -478,7 +478,7 @@ function setupHADeviceControlsCard() {
478478 "device_class": "switch",
479479 "qos": "' ${QOS_LEVEL} ' ",
480480 "unique_id": "' ${DEV_ID} ' _steering-wheel-heater"
481- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/switch/${DEV_ID} /steering-wheel-heater/config -l
481+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/switch/${DEV_ID} /steering-wheel-heater/config -l
482482
483483 echo ' {
484484 "command_topic": "' ${TOPIC_ROOT} ' /sentry-mode",
@@ -495,7 +495,7 @@ function setupHADeviceControlsCard() {
495495 "device_class": "switch",
496496 "qos": "' ${QOS_LEVEL} ' ",
497497 "unique_id": "' ${DEV_ID} ' _sentry-mode"
498- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/switch/${DEV_ID} /sentry-mode/config -l
498+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/switch/${DEV_ID} /sentry-mode/config -l
499499
500500 echo ' {
501501 "command_topic": "' ${TOPIC_ROOT} ' /heater-seat-front-left",
@@ -513,7 +513,7 @@ function setupHADeviceControlsCard() {
513513 "qos": "' ${QOS_LEVEL} ' ",
514514 "icon": "mdi:car-seat-heater",
515515 "unique_id": "' ${DEV_ID} ' _heater-seat-front-left"
516- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/select/${DEV_ID} /heater-seat-front-left/config -l
516+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/select/${DEV_ID} /heater-seat-front-left/config -l
517517
518518 echo ' {
519519 "command_topic": "' ${TOPIC_ROOT} ' /heater-seat-front-right",
@@ -531,7 +531,7 @@ function setupHADeviceControlsCard() {
531531 "qos": "' ${QOS_LEVEL} ' ",
532532 "icon": "mdi:car-seat-heater",
533533 "unique_id": "' ${DEV_ID} ' _heater-seat-front-right"
534- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/select/${DEV_ID} /heater-seat-front-right/config -l
534+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/select/${DEV_ID} /heater-seat-front-right/config -l
535535
536536 log_debug " Leaving setupHADeviceControlsCard() vin:$vin "
537537}
@@ -564,12 +564,48 @@ function setupHADeviceGenerateKeysButton() {
564564 "unique_id": "' ${DEV_ID} ' _generate-keys",
565565 "entity_category": "config",
566566 "sw_version": "' ${SW_VERSION} ' "
567- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /generate-keys/config -l
567+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /generate-keys/config -l
568568
569569 log_debug " setupHADeviceGenerateKeysButton() leaving vin:$vin "
570570
571571}
572572
573+ # ##
574+ # #
575+ # Setup Configuration ReGenerate Keys Button
576+ # #
577+ # ##
578+ function setupHADeviceReGenerateKeysButton() {
579+ vin=$1
580+
581+ log_debug " setupHADeviceReGenerateKeysButton() entering vin:$vin "
582+ configHADeviceEnvVars $vin
583+
584+ eval $MOSQUITTO_PUB_BASE -t homeassistant/button/tesla_ble_${vin} /generate-keys/config -n
585+
586+ echo ' {
587+ "command_topic": "' ${TOPIC_ROOT} ' /config",
588+ "device": {
589+ "identifiers": [
590+ "' ${DEV_ID} ' "
591+ ],
592+ "manufacturer": "tesla-local-control",
593+ "model": "Tesla_BLE",
594+ "name": "' ${DEV_NAME} ' "
595+ },
596+ "device_class": "update",
597+ "name": "ReGenerate Keys",
598+ "payload_press": "generate-keys",
599+ "qos": "' ${QOS_LEVEL} ' ",
600+ "unique_id": "' ${DEV_ID} ' _regenerate-keys",
601+ "entity_category": "config",
602+ "sw_version": "' ${SW_VERSION} ' "
603+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /regenerate-keys/config -l
604+
605+ log_debug " setupHADeviceReGenerateKeysButton() leaving vin:$vin "
606+
607+ }
608+
573609# ##
574610# #
575611# Setup Vehicule's Presence Sensor
@@ -595,7 +631,7 @@ function setupHADevicePresenceSensor {
595631 "device_class": "presence",
596632 "name": "Presence",
597633 "unique_id": "' ${DEV_ID} ' _presence"
598- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/binary_sensor/${DEV_ID} /presence/config -l
634+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 36 10 -t homeassistant/binary_sensor/${DEV_ID} /presence/config -l
599635
600636 log_debug " setupHADevicePresenceSensor() leaving vin:$vin "
601637
@@ -629,23 +665,26 @@ function setupHADeviceDeployKeyButton() {
629665 "qos": "' ${QOS_LEVEL} ' ",
630666 "unique_id": "' ${DEV_ID} ' _deploy-key",
631667 "entity_category": "config"
632- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /deploy-key/config -l
668+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /deploy-key/config -l
633669
634670 log_debug " setupHADeviceDeployKeyButton() leaving vin:$vin "
635671
636672}
637673
638674# ##
639675# #
640- # Setup Scan BLE LN Button
676+ # Setup Info Bluetooth Adapter
641677# #
642678# ##
643- function setupHADeviceScanBLElnButton () {
679+ function setupHADeviceInfoBTadapter () {
644680 vin=$1
645681
646- log_debug " setupHADeviceScanBLElnButton () entering vin:$vin "
682+ log_debug " setupHADeviceInfoBTadapter () entering vin:$vin "
647683 configHADeviceEnvVars $vin
648684
685+ # TODO TEPORARILY - To be removed
686+ eval $MOSQUITTO_PUB_BASE -t homeassistant/button/tesla_ble_${vin} /scan-bleln-macaddr/config -n
687+
649688 echo ' {
650689 "command_topic": "' ${TOPIC_ROOT} ' /config",
651690 "device": {
@@ -658,14 +697,14 @@ function setupHADeviceScanBLElnButton() {
658697 "sw_version": "' ${SW_VERSION} ' "
659698 },
660699 "device_class": "update",
661- "name": "Scan Bluetooth",
662- "payload_press": "scan-bleln-macaddr ",
700+ "name": "Info Bluetooth Adapter ",
701+ "payload_press": "info-bt-adapter ",
663702 "qos": "' ${QOS_LEVEL} ' ",
664- "unique_id": "' ${DEV_ID} ' _scan-bleln-macaddr ",
703+ "unique_id": "' ${DEV_ID} ' _info-bt-adapter ",
665704 "entity_category": "diagnostic"
666- }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID} /scan-bleln-macaddr /config -l
705+ }' | sed ' :a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID} /info-bt-adapter /config -l
667706
668- log_debug " setupHADeviceScanBLElnButton () leaving vin:$vin "
707+ log_debug " setupHADeviceInfoBTadapter () leaving vin:$vin "
669708
670709}
671710
0 commit comments