@@ -14,8 +14,6 @@ if [ -n "${HASSIO_TOKEN:-}" ]; then
1414 DEBUG=" $( bashio::config ' debug' ) " ; export DEBUG
1515fi
1616
17- PRESENCE_BINARY_SENSOR=Unknown
18-
1917# Set log level to debug
2018bashio::config.true debug && bashio::log.level debug
2119
@@ -70,7 +68,6 @@ send_key() {
7068 break
7169 else
7270 bashio::log.error " tesla-control could not send the pubkey; make sure the car is awake and sufficiently close to the bluetooth device. Retrying in $SEND_CMD_RETRY_DELAY "
73- bashio::log.error " Retrying in $SEND_CMD_RETRY_DELAY "
7471 sleep $SEND_CMD_RETRY_DELAY
7572 fi
7673 done
@@ -80,27 +77,26 @@ listen_to_ble() {
8077 PRESENCE_TIMEOUT=5
8178 bashio::log.info " Listening to BLE for presence"
8279 set +e
80+ if [ $? -eq 0 ]; then
81+ bashio::log.green " $BLE_MAC presence detected"
82+ mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u " $MQTT_USER " -P " $MQTT_PWD " -t tesla_ble/bin
83+ ry_sensor/presence -m ON
84+ else
85+ bashio::log.yellow " $BLE_MAC presence not detected or issue in command, retrying now"
86+ mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u " $MQTT_USER " -P " $MQTT_PWD " -t tesla_ble/bin
87+ ary_sensor/presence -m OFF
88+ fi
89+
8390 bluetoothctl --timeout $PRESENCE_TIMEOUT scan on | grep $BLE_MAC
8491 EXIT_STATUS=$?
8592 set -e
86- if [ $? -eq 0 ]; then
87- bashio::log.info " $BLE_MAC presence detected"
88- if [[ $PRESENCE_BINARY_SENSOR == " OFF" || $PRESENCE_BINARY_SENSOR == " Unknown" ]]; then
89- bashio::log.info " Updating topic tesla_ble/binary_sensor/presence ON"
90- mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u " $MQTT_USER " -P " $MQTT_PWD " -t tesla_ble/binary_sensor/presence -m ON
91- PRESENCE_BINARY_SENSOR=ON
92- else
93- bashio::log.debug " Topic tesla_ble/binary_sensor/presence already ON"
94- fi
95- else
96- bashio::log.warning " $BLE_MAC presence not detected or issue in command, will retry later"
97- if [[ $PRESENCE_BINARY_SENSOR == " ON" || $PRESENCE_BINARY_SENSOR == " Unknown" ]]; then
98- bashio::log.info " Updating topic tesla_ble/binary_sensor/presence OFF"
99- mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u " $MQTT_USER " -P " $MQTT_PWD " -t tesla_ble/binary_sensor/presence -m OFF
100- PRESENCE_BINARY_SENSOR=OFF
101- else
102- bashio::log.debug " Topic tesla_ble/binary_sensor/presence already OFF"
103- fi
93+ bashio::log.info " $BLE_MAC presence detected"
94+ mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u " $MQTT_USER " -P " $MQTT_PWD " -t tesla_ble/binary_sensor/presence -m ON
95+
96+ bashio::log.warning " $BLE_MAC presence not detected or issue in command, will retry later"
97+ bashio::log.info " Updating topic tesla_ble/binary_sensor/presence OFF"
98+ mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u " $MQTT_USER " -P " $MQTT_PWD " -t tesla_ble/binary_sensor/presence -m OFF
99+ bashio::log.debug " Topic tesla_ble/binary_sensor/presence already OFF"
104100 fi
105101}
106102
0 commit comments