Skip to content

Commit

Permalink
v0.2.2 --> main (#123)
Browse files Browse the repository at this point in the history
* [chg] auto Generate Keys to ReGenerateKeys (#89)
* [feat] Info Bluetooth Adapter (#88)
* [feat] Info Bluetooth Adapter (#88) (#90)
* [fix] counter loop condition
* [fix] topic & missing retry values (#92)
* [chg] delete old scan-bleln-macaddr

* [feat] Auto MAC address detection (#86)

* small rewrite logic to detect MAC addr

* [chg] skip menu mgmt (#96)

* [fix] Prevent presence unknown, set qos=1 (#97)

* [fix] Prevent presence unknown, set qos=1

* [CHG] info-bt-adapter; run mgmt.info before show

* [CHG] Presence disable? Set Unknown and Delete

* [CHG] CHANGELOG Update

* [fix] presence unkown at start

* [fix] presence unkown at start

* Update subroutines.sh shfmt

* Update mqtt-discovery.sh shfmt

* [issue 99] Buttons to switches covers merged with PR85 (#105)

* [chg] Add loop to generate JSON enteties based on a paramater list

* Merge with 85

* [chg] run.sh add -e to ash (#95)

* [Feature-Issue #99] Transform buttons to switches & covers; Add Cmds & Icons (#103)

* Group entities

* Update CHANGELOG.md

* Reorder legacies cleaning

* tabs to spaces (shfmt)

* Anticipate clearing MQTT entities

* shfmt

* add newline

* [feat] Transform buttons to switches & covers; Add Commands & Icons

* Make delete_legacies* vin aware

* Add/fix icons; adjust CHANGELOG

* [chg] revert ash -e

* [chg] add back media-ctrl, remove ping

* [chg] changelog add new commands

---------

Co-authored-by: Pierre Belanger <[email protected]>

* [chg] raise tesla-control command timeout (#108)

* [chg] changelog add note on command-timeout (#109)

* [chg] raise tesla-control command timeout

* [chg] changelog add note on command-timeout

* [chg] remove arguments to tesla-control and use env vars

* [fix] body-controller-state (#111)

* [feat] allow to set temperature_unit F|C (#110)

* [fix] body-controller-state (#112) (#118)

Co-authored-by: Pierre Belanger <[email protected]>

* Fix charging set amps log (#116)

* Update mqtt-listen.sh

* Wake in case of command failure (#120)

* parse "context deadline exceeded"
* bump version
* doc
* Fix nested calls

* 121 add max current env setting (#122)

* Add MAX_CURRENT setting

* Add contributor

---------

Co-authored-by: Pierre Belanger <[email protected]>
Co-authored-by: Iain Bullock <[email protected]>
Co-authored-by: g4rb4g3 <[email protected]>
  • Loading branch information
4 people authored Sep 14, 2024
1 parent f1c0f86 commit f9fb4a5
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 24 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.2.2

### Changed

- NEW Feature: Try to wake car if command fails with "Error: context deadline exceeded"
- NEW Feature: Added maximum allowable setting to limit the current slider in HA entities

#### Contributors - Thank you!
- @g4rb4g3 Clear logging on charging current setting

## 0.2.1

### <p>**WARNING WARNING WARNING**<br>
Upgrading from 0.0.10 or previous? DO NOT UPGRADE PRIOR TO READ THE 0.1.0 UPGRADE INSTRUCTIONS.</p>

### Changed

- NEW Feature: Allow to set temperature unit F|C via bool

## 0.2.0

### <p>**WARNING WARNING WARNING**<br>
Expand Down
8 changes: 6 additions & 2 deletions env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# shellcheck shell=dash
#
export SW_VERSION=0.2.0
export SW_VERSION=0.2.2

### LOAD LIBRARIES (FUNCTIONS & ENVIRONMENT ) #################################
echo "[$(date +%H:%M:%S)] loading libproduct.sh"
Expand Down Expand Up @@ -32,6 +32,8 @@ export BLECTL_FILE_INPUT=${BLECTL_FILE_INPUT:-}
export ENABLE_HA_FEATURES=${ENABLE_HA_FEATURES:-true}
export PRESENCE_DETECTION_LOOP_DELAY=${PRESENCE_DETECTION_LOOP_DELAY:-120}
export PRESENCE_DETECTION_TTL=${PRESENCE_DETECTION_TTL:-240}
export TEMPERATURE_UNIT_FAHRENHEIT=${TEMPERATURE_UNIT_FAHRENHEIT:-false}
export MAX_CURRENT=${MAX_CURRENT:-48}

export BLE_LN_REGEX='S[0-9A-Fa-f]{16}C'
export BLTCTL_COMMAND_DEVICES=false
Expand All @@ -49,7 +51,9 @@ log_info "Configuration Options are:
MQTT_USERNAME=$MQTT_USERNAME
PRESENCE_DETECTION_LOOP_DELAY=$PRESENCE_DETECTION_LOOP_DELAY
PRESENCE_DETECTION_TTL=$PRESENCE_DETECTION_TTL
VIN_LIST=$VIN_LIST"
TEMPERATURE_UNIT_FAHRENHEIT=$TEMPERATURE_UNIT_FAHRENHEIT
VIN_LIST=$VIN_LIST
MAX_CURRENT=$MAX_CURRENT"

[ -n "$ENABLE_HA_FEATURES" ] && log_info " ENABLE_HA_FEATURES=$ENABLE_HA_FEATURES"
[ -n "$BLECTL_FILE_INPUT" ] && log_info " BLECTL_FILE_INPUT=$BLECTL_FILE_INPUT"
Expand Down
67 changes: 46 additions & 21 deletions mqtt-discovery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function setupExtendedControls() {
},
"icon": "mdi:current-ac",
"min": "0",
"max": "48",
"max": "'${MAX_CURRENT}'",
"mode": "slider",
"name": "Charging Current",
"qos": "'${QOS_LEVEL}'",
Expand All @@ -367,7 +367,7 @@ function setupExtendedControls() {
},
"icon": "mdi:current-ac",
"min": "0",
"max": "48",
"max": "'${MAX_CURRENT}'",
"mode": "slider",
"name": "Charging Current single",
"qos": "'${QOS_LEVEL}'",
Expand Down Expand Up @@ -397,25 +397,50 @@ function setupExtendedControls() {
"unit_of_measurement": "%"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEVICE_ID}/charging-set-limit/config -l

echo '{
"command_topic": "'${TOPIC_ROOT}'/climate-set-temp",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:thermometer",
"name": "Climate Temp",
"min": "5",
"max": "40",
"mode": "slider",
"qos": "'${QOS_LEVEL}'",
"unique_id": "'${DEVICE_ID}'_climate-set-temp"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEVICE_ID}/climate-temp/config -l
if [ $TEMPERATURE_UNIT_FAHRENHEIT = "true" ]; then

echo '{
"command_topic": "'${TOPIC_ROOT}'/climate-set-temp",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:thermometer",
"name": "Climate Temp",
"min": "57",
"max": "83",
"mode": "slider",
"qos": "'${QOS_LEVEL}'",
"unique_id": "'${DEVICE_ID}'_climate-set-temp",
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEVICE_ID}/climate-temp/config -l

else

echo '{
"command_topic": "'${TOPIC_ROOT}'/climate-set-temp",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:thermometer",
"name": "Climate Temp",
"min": "15",
"max": "28",
"mode": "slider",
"qos": "'${QOS_LEVEL}'",
"unique_id": "'${DEVICE_ID}'_climate-set-temp"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEVICE_ID}/climate-temp/config -l
fi

# Select

Expand Down
2 changes: 1 addition & 1 deletion mqtt-listen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ listen_to_mqtt() {
if [ $msg -gt 4 ]; then
teslaCtrlSendCommand $vin "charging-set-amps $msg" "Set charging Amps to $msg"
else
teslaCtrlSendCommand $vin "charging-set-amps $msg" "Set charging Amps to 5A then to $msg"
teslaCtrlSendCommand $vin "charging-set-amps $msg" "4A or less requested, calling charging-set-amps $msg twice"
sleep 1
teslaCtrlSendCommand $vin "charging-set-amps $msg" "Set charging Amps to $msg"
fi
Expand Down
34 changes: 34 additions & 0 deletions tesla-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,23 @@
##
###
teslaCtrlSendCommand() {
# Process in case of nested call (autowake)
if [ $# -eq 4 ]; then
log_debug "teslaCtrlSendCommand; Nested call: in. Set callMode and copy internal variables"
vin_previous=$vin
command_previous=$command
commandDescription_previous=$commandDescription
callMode="nested"
else
log_debug "teslaCtrlSendCommand; Standard call: in."
callMode="standard"
fi
# Set internal variables
vin=$1
command=$2
commandDescription=$3

# Prepare for calling tesla-control
export TESLA_VIN=$vin
export TESLA_KEY_FILE=$KEYS_DIR/${vin}_private.pem
export TESLA_KEY_NAME=$KEYS_DIR/${vin}_private.pem
Expand All @@ -31,12 +44,33 @@ teslaCtrlSendCommand() {
if [ $EXIT_STATUS -eq 0 ]; then
log_debug "teslaCtrlSendCommand; $teslaCtrlOut"
log_info "Command $command was successfully delivered to vin:$vin"
# Finalize in case of nested call (autowake)
if [[ "$callMode" == "nested" ]]; then
log_debug "teslaCtrlSendCommand; Nested call: out. Set callMode back to standard and revert internal variables"
vin=$vin_previous
command=$command_previous
commandDescription=$commandDescription_previous
callMode="standard"
else
log_debug "teslaCtrlSendCommand; Standard call: out."
fi
return 0
else
if [[ "$teslaCtrlOut" == *"car could not execute command"* ]]; then
log_warning "teslaCtrlSendCommand; $teslaCtrlOut"
log_warning "Skipping command $command to vin:$vin"
return 10
elif [[ "$teslaCtrlOut" == *"context deadline exceeded"* ]]; then
# TODO check that this situation appears only once (or few)
# to avoid getting into a loop if we cannot wake the car
# if this happens the "else" will never be triggered and the command will never exit
# it would be possible to parse the return code of teslaCtrlSendCommand to check that wake succeeded
log_debug "teslaCtrlSendCommand; txt deadline exc. - IN"
log_warning "teslaCtrlSendCommand; $teslaCtrlOut"
log_warning "Vehicle might be asleep"
log_notice "Trying to wake up car then launch the command again"
teslaCtrlSendCommand $vin "-domain vcsec wake" "Wake up vehicule" "internal"
log_debug "teslaCtrlSendCommand; txt deadline exc. - OUT"
else
log_error "tesla-control send command:$command to vin:$vin failed exit status $EXIT_STATUS."
log_error "teslaCtrlSendCommand; $teslaCtrlOut"
Expand Down

0 comments on commit f9fb4a5

Please sign in to comment.