Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#iain-dev->#main (v0.4.1b-dev ) #141

Merged
merged 76 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
c980b81
Add polling entities
iainbullock Jan 5, 2025
ab09ff6
Merge pull request #139 from tesla-local-control/polling
iainbullock Jan 5, 2025
74c207c
Fix retain / QoS
iainbullock Jan 5, 2025
1d6caba
Move Polling internal to environment
iainbullock Jan 5, 2025
9e2c606
Put polling interval back to MQTT
iainbullock Jan 5, 2025
bf4d0ac
Loop thru VINs
iainbullock Jan 5, 2025
e3a1364
Fix typo
iainbullock Jan 5, 2025
f643f1d
Update variables from MQTT
iainbullock Jan 5, 2025
7c3779d
Fix polling variables
iainbullock Jan 5, 2025
870d7da
Give polling a state topic
iainbullock Jan 5, 2025
034fc79
Test loop for polling
iainbullock Jan 5, 2025
7581bad
Fix the polling globals
iainbullock Jan 5, 2025
b71207e
Use eval and global vars
iainbullock Jan 6, 2025
fc851df
Global variable attempted fix
iainbullock Jan 6, 2025
b2be55d
Abandon using global vars
iainbullock Jan 6, 2025
15ef82b
test g_vars from MQTT
iainbullock Jan 6, 2025
1f6d3ec
MQTT timeout
iainbullock Jan 6, 2025
dc7dd66
Fix comma
iainbullock Jan 6, 2025
ced1aac
Mod param extensions
iainbullock Jan 6, 2025
ff21a16
Read globals without function
iainbullock Jan 6, 2025
9bdc638
Use for instead of while
iainbullock Jan 6, 2025
a4ee4a0
Fix missing )
iainbullock Jan 6, 2025
790cfff
set +e
iainbullock Jan 6, 2025
a39487c
Extend polling logic
iainbullock Jan 7, 2025
78c14a7
Add polling interval modulus logic
iainbullock Jan 7, 2025
6b71e5d
Fix string comparison
iainbullock Jan 7, 2025
3be29aa
Another typo
iainbullock Jan 7, 2025
de3ae90
Is car awake
iainbullock Jan 7, 2025
d2ba733
Update changelog
iainbullock Jan 7, 2025
7f11fb3
Fix indentation
iainbullock Jan 7, 2025
2b1f0d3
Typo fixes
iainbullock Jan 7, 2025
22261c9
Remove quote
iainbullock Jan 7, 2025
10c2c9e
Extra quotes
iainbullock Jan 7, 2025
33014ca
Publish to state topic
iainbullock Jan 7, 2025
7bb71dc
Press the button
iainbullock Jan 7, 2025
d6aad5d
First pass individual buttons
iainbullock Jan 7, 2025
af1c624
List sections
iainbullock Jan 7, 2025
ae78cdc
Test NO_POLL_SECTIONS functionality
iainbullock Jan 7, 2025
3e06793
Missing esac
iainbullock Jan 7, 2025
bb071f9
Update changelog
iainbullock Jan 7, 2025
a52a5cd
First pass dont abort
iainbullock Jan 7, 2025
b3844fe
Simplify errors
iainbullock Jan 7, 2025
292b306
More error simplification
iainbullock Jan 7, 2025
c3ee9e7
Fix Force Update All
iainbullock Jan 7, 2025
4cc752d
Delete config and command messages
iainbullock Jan 7, 2025
da37a49
log_debug
iainbullock Jan 7, 2025
793af8a
Remove obsolete code
iainbullock Jan 7, 2025
f102ad2
Make loop 1 day
iainbullock Jan 8, 2025
a4ead17
Core version message
iainbullock Jan 8, 2025
2b7721c
Add Presence_BC feature
iainbullock Jan 8, 2025
69b8862
Check if awake every 30 secs
iainbullock Jan 8, 2025
62963ba
Reduce log spam
iainbullock Jan 8, 2025
94a21d7
More log spam reduction
iainbullock Jan 8, 2025
c3c1bd4
More MQTT logs but less spam
iainbullock Jan 9, 2025
cf41e39
Add force update to certain sensors
iainbullock Jan 9, 2025
e96c6e0
Fix typo
iainbullock Jan 9, 2025
b458be6
awake asleep true false
iainbullock Jan 9, 2025
c6ddcba
Remove force update not reqd
iainbullock Jan 9, 2025
3a582a9
Create poll_state function
iainbullock Jan 10, 2025
eb11d6d
publish poll_state to MQTT
iainbullock Jan 10, 2025
05d5dae
Poll now triggered by MQTT
iainbullock Jan 10, 2025
9f6cc7b
Reduce log spam
iainbullock Jan 10, 2025
c1560d9
Fix loop count
iainbullock Jan 10, 2025
b1b14de
Check for unclean JSON
iainbullock Jan 10, 2025
5f553ae
Fix unclean Jason v2
iainbullock Jan 10, 2025
345a562
Remove echo
iainbullock Jan 10, 2025
471a2ff
Fix for numeric first char in VIN
iainbullock Jan 10, 2025
bcda0d5
Typo and Changelog
iainbullock Jan 10, 2025
fb204b6
Credit Issue #75
iainbullock Jan 10, 2025
f9970bf
Clean stateJSON not jsonParam
iainbullock Jan 11, 2025
1707b78
Fix shellcheck errors
iainbullock Jan 11, 2025
3210700
Fix shellcheck errors +1
iainbullock Jan 11, 2025
2972f98
Fix shellcheck errors +2
iainbullock Jan 11, 2025
82703eb
Fix shellcheck errors +3
iainbullock Jan 11, 2025
438cd68
SW_VERSION=0.4.2
iainbullock Jan 13, 2025
875ac72
Update CHANGELOG.md
iainbullock Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 0.4.1

- RELEASE NEW Feature: Automatic Polling is now possible for state

- NEW Feature: The following new states / entities are added:
- Sensors: Awake (updated approx every 30 secs from body-controller-state)
- Binary_Sensors: Presence_BC (experimental presence detection updated approx every 30 secs from body_controller_state rather than listening for BLE mac)
- Switches: Polling
- Numbers: Polling Interval
- Buttons: Force Update buttons for individual state categories

- NEW Feature: Environment variable NO_POLL_SECTIONS is provided to disable updating of various state categories during polling. This speeds up state updates, though less state entities are updated by the polling. The entities can still be manually updated by pressing the Force Update button for the relevent state category

- Changes:
- 'Force Data Update' Button is renamed to 'Force Update All'
- Errors which occur whilst reading state will not automatically prevent the next state or state category being read. This will fix an issue reported in #135 below where a user doesn't have a Heated Steering Wheel. This previously prevented any states after this one from being read

- Fixes:
- [ Dev ] Bad variable name #75 (_docker). Many thanks to aneisch and dettofatto who really helped to track down this bug
- parse error: Invalid numeric literal #74 (_docker). Many thanks to jipema who also helped a lot in identifying this issue
- All my sensor entities are "unknown" #131 (_core)
- Any potential to "read state" via bluetooth? #115 (_core)

## 0.3.1

- NEW Feature: The following new states / entities are added:
Expand Down
4 changes: 3 additions & 1 deletion env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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 NO_POLL_SECTIONS=${NO_POLL_SECTIONS:-}

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

[ -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
48 changes: 45 additions & 3 deletions mqtt-discovery-sensors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ function setupChargeStateSensors {
"device_class": "voltage",
"unit_of_measurement": "V",
"suggested_display_precision": "0",
"unique_id": "'${DEVICE_ID}'_charger_voltage"
"enabled_by_default": "false",
"unique_id": "'${DEVICE_ID}'_charger_voltage",
"enabled_by_default": "false"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 36 10 -t homeassistant/sensor/${DEVICE_ID}/charger_voltage/config -l

echo '{
Expand Down Expand Up @@ -310,7 +310,7 @@ function setupChargeStateSensors {
"qos": "'${QOS_LEVEL}'",
"device_class": "temperature",
"unit_of_measurement": "°C",
"suggested_display_precision": "1",
"suggested_display_precision": "1",
"unique_id": "'${DEVICE_ID}'_inside_temp"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 36 10 -t homeassistant/sensor/${DEVICE_ID}/inside_temp/config -l

Expand Down Expand Up @@ -711,6 +711,48 @@ function setupChargeStateSensors {
"unique_id": "'${DEVICE_ID}'_mirror_heater"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 36 10 -t homeassistant/binary_sensor/${DEVICE_ID}/mirror_heater/config -l

echo '{
"state_topic": "'${TOPIC_ROOT}'/binary_sensor/awake",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"platform": "binary_sensor",
"icon": "mdi:sleep-off",
"name": "Awake",
"payload_on": "true",
"payload_off": "false",
"qos": "'${QOS_LEVEL}'",
"unique_id": "'${DEVICE_ID}'_awake"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 36 10 -t homeassistant/binary_sensor/${DEVICE_ID}/awake/config -l

echo '{
"state_topic": "'${TOPIC_ROOT}'/binary_sensor/presence_bc",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"platform": "binary_sensor",
"name": "Presence BC",
"payload_on": "true",
"payload_off": "false",
"qos": "'${QOS_LEVEL}'",
"device_class": "presence",
"icon": "mdi:car-connected",
"enabled_by_default": "false",
"unique_id": "'${DEVICE_ID}'_presence_bc"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 36 10 -t homeassistant/binary_sensor/${DEVICE_ID}/presence_bc/config -l

# Status is only Disengaged for short time, it gets reengaged soon after even with no charger plugged in. Not useful
# echo '{
# "state_topic": "'${TOPIC_ROOT}'/binary_sensor/charge_port_latch",
Expand Down
183 changes: 176 additions & 7 deletions mqtt-discovery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,30 @@ function setupExtendedControls() {
"unique_id": "'${DEVICE_ID}'_steering-wheel-heater"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/switch/${DEVICE_ID}/steering-wheel-heater/config -l

echo '{
"command_topic": "'${TOPIC_ROOT}'/variables/polling",
"state_topic": "'${TOPIC_ROOT}'/variables/polling",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:car-connected",
"name": "State Polling",
"device_class": "switch",
"payload_on": "on",
"payload_off": "off",
"state_on": "on",
"state_off": "off",
"retain": "true",
"unique_id": "'${DEVICE_ID}'_polling",
"entity_category": "diagnostic"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/switch/${DEVICE_ID}/polling/config -l

# Covers

echo '{
Expand Down Expand Up @@ -471,6 +495,29 @@ function setupExtendedControls() {
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEVICE_ID}/climate-temp/config -l
fi

echo '{
"command_topic": "'${TOPIC_ROOT}'/variables/polling_interval",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:timer-sync",
"min": "30",
"max": "3600",
"step": "30",
"mode": "slider",
"name": "Polling Interval",
"retain": "true",
"unique_id": "'${DEVICE_ID}'_polling_interval",
"entity_category": "diagnostic",
"unit_of_measurement": "secs"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEVICE_ID}/polling_interval/config -l

# Selects

echo '{
Expand Down Expand Up @@ -710,6 +757,7 @@ function setupDiagnostic() {
"entity_category": "diagnostic",
"icon": "mdi:car-info",
"name": "Car state information",
"enabled_by_default": "false",
"payload_press": "body-controller-state",
"qos": "'${QOS_LEVEL}'",
"unique_id": "'${DEVICE_ID}'_body-controller-state"
Expand Down Expand Up @@ -766,12 +814,132 @@ function setupDiagnostic() {
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:database-sync",
"name": "Force Data Update",
"name": "Force Update All",
"entity_category": "diagnostic",
"payload_press": "read-state",
"payload_press": "read-state-all",
"qos": "'${QOS_LEVEL}'",
"unique_id": "'${DEVICE_ID}'_read-state"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEVICE_ID}/read-state/config -l
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEVICE_ID}/read-state-all/config -l

echo '{
"command_topic": "'${TOPIC_ROOT}'/config",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:database-sync",
"name": "Force Update Env",
"entity_category": "diagnostic",
"payload_press": "read-state-envcheck",
"qos": "'${QOS_LEVEL}'",
"enabled_by_default": "false",
"unique_id": "'${DEVICE_ID}'_read-state-envcheck"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEVICE_ID}/read-state-envcheck/config -l

echo '{
"command_topic": "'${TOPIC_ROOT}'/config",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:database-sync",
"name": "Force Update Charge",
"entity_category": "diagnostic",
"payload_press": "read-state-charge",
"qos": "'${QOS_LEVEL}'",
"enabled_by_default": "false",
"unique_id": "'${DEVICE_ID}'_read-state-charge"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEVICE_ID}/read-state-charge/config -l

echo '{
"command_topic": "'${TOPIC_ROOT}'/config",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:database-sync",
"name": "Force Update Climate",
"entity_category": "diagnostic",
"payload_press": "read-state-climate",
"qos": "'${QOS_LEVEL}'",
"enabled_by_default": "false",
"unique_id": "'${DEVICE_ID}'_read-state-climate"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEVICE_ID}/read-state-climate/config -l

echo '{
"command_topic": "'${TOPIC_ROOT}'/config",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:database-sync",
"name": "Force Update Tyre",
"entity_category": "diagnostic",
"payload_press": "read-state-tyre",
"qos": "'${QOS_LEVEL}'",
"enabled_by_default": "false",
"unique_id": "'${DEVICE_ID}'_read-state-tyre"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEVICE_ID}/read-state-tyre/config -l

echo '{
"command_topic": "'${TOPIC_ROOT}'/config",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:database-sync",
"name": "Force Update Closure",
"entity_category": "diagnostic",
"payload_press": "read-state-closure",
"qos": "'${QOS_LEVEL}'",
"enabled_by_default": "false",
"unique_id": "'${DEVICE_ID}'_read-state-closure"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEVICE_ID}/read-state-closure/config -l

echo '{
"command_topic": "'${TOPIC_ROOT}'/config",
"device": {
"identifiers": [
"'${DEVICE_ID}'"
],
"manufacturer": "tesla-local-control",
"model": "Tesla_BLE",
"name": "'${DEVICE_NAME}'",
"sw_version": "'${SW_VERSION}'"
},
"icon": "mdi:database-sync",
"name": "Force Update Drive",
"entity_category": "diagnostic",
"payload_press": "read-state-drive",
"qos": "'${QOS_LEVEL}'",
"enabled_by_default": "false",
"unique_id": "'${DEVICE_ID}'_read-state-drive"
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEVICE_ID}/read-state-drive/config -l

log_debug "setupDiagnostic() leaving vin:$vin"

Expand All @@ -794,12 +962,13 @@ setupHADiscoveryAllVINsMain() {
else
log_info "setupHADiscoveryAllVINsMain; HA backend is disable, skipping setup for HA Auto Discovery"
fi

# Discard /config and /command messages
log_notice "setupHADiscoveryAllVINsMain; Discarding unread MQTT messages for command and config topics"
eval $MOSQUITTO_PUB_BASE -t tesla_ble/$vin/config -n
eval $MOSQUITTO_PUB_BASE -t tesla_ble/$vin/command -n
done

# Discard /config messages
topic=tesla_ble/$vin/config
log_notice "setupHADiscoveryAllVINsMain; Discarding any unread MQTT messages for topic:$topic"
eval $MOSQUITTO_SUB_BASE -E -i tesla_ble_mqtt -t $topic
}

###
Expand Down
Loading
Loading