Merge branch 'main' of https://github.com/michaelwoods/onstar2mqtt
This commit is contained in:
commit
f7ab765650
4
.github/dependabot.yml
vendored
4
.github/dependabot.yml
vendored
@ -4,8 +4,8 @@ updates:
|
|||||||
- package-ecosystem: "github-actions"
|
- package-ecosystem: "github-actions"
|
||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "monthly"
|
||||||
- package-ecosystem: "npm"
|
- package-ecosystem: "npm"
|
||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "monthly"
|
||||||
|
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -16,7 +16,7 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [12.x]
|
node-version: [18.x]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the repo
|
- name: Check out the repo
|
||||||
@ -53,7 +53,7 @@ jobs:
|
|||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
- name: Push to DockerHub
|
- name: Push to DockerHub
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -32,7 +32,7 @@ jobs:
|
|||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
- name: Push to DockerHub
|
- name: Push to DockerHub
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
push: true
|
push: true
|
||||||
|
71
HA-MQTT.md
71
HA-MQTT.md
@ -1,5 +1,42 @@
|
|||||||
Sample configs for MQTT Home Assistant integration.
|
Sample configs for MQTT Home Assistant integration.
|
||||||
|
|
||||||
|
### Commands
|
||||||
|
|
||||||
|
#### example script yaml:
|
||||||
|
```yaml
|
||||||
|
alias: Car - Start Vehicle
|
||||||
|
sequence:
|
||||||
|
- service: mqtt.publish
|
||||||
|
data:
|
||||||
|
topic: homeassistant/YOUR_CAR_VIN/command
|
||||||
|
payload: '{"command": "startVehicle"}'
|
||||||
|
mode: single
|
||||||
|
icon: 'mdi:car-electric'
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Triger precondition via calendar
|
||||||
|
````yaml
|
||||||
|
alias: Car Precondition
|
||||||
|
description: Precondition if group.family is home (ie, at least one person).
|
||||||
|
trigger:
|
||||||
|
- platform: state
|
||||||
|
entity_id: calendar.YOUR_CAL_NAME
|
||||||
|
from: 'off'
|
||||||
|
to: 'on'
|
||||||
|
condition:
|
||||||
|
- condition: state
|
||||||
|
entity_id: group.family
|
||||||
|
state: home
|
||||||
|
- condition: state
|
||||||
|
entity_id: calendar.YOUR_CAL_NAME
|
||||||
|
state: Bolt Start
|
||||||
|
attribute: message
|
||||||
|
action:
|
||||||
|
- service: script.car_start_vehicle
|
||||||
|
data: {}
|
||||||
|
mode: single
|
||||||
|
````
|
||||||
|
|
||||||
### Location
|
### Location
|
||||||
Unfortunately, the MQTT Device tracker uses a home/not_home state and the MQTT Json device tracker does not support
|
Unfortunately, the MQTT Device tracker uses a home/not_home state and the MQTT Json device tracker does not support
|
||||||
the discovery schema so a manual entity configuration is required.
|
the discovery schema so a manual entity configuration is required.
|
||||||
@ -23,23 +60,21 @@ sequence:
|
|||||||
mode: single
|
mode: single
|
||||||
icon: 'mdi:map-marker'
|
icon: 'mdi:map-marker'
|
||||||
```
|
```
|
||||||
|
### Automation:
|
||||||
### Lovelace Dashboard
|
Create an automation to update the location whenever the odometer changes, instead of on a time interval.
|
||||||
Create a new dashboard, or use the cards in your own view. The `mdi:car-electric` icon works well here.
|
```alias: Update EV Location
|
||||||
|
description: ""
|
||||||

|
trigger:
|
||||||
|
- platform: state
|
||||||
#### script yaml:
|
entity_id:
|
||||||
```yaml
|
- sensor.odometer_mi
|
||||||
alias: Car - Start Vehicle
|
condition: []
|
||||||
sequence:
|
action:
|
||||||
- service: mqtt.publish
|
- service: script.locate_bolt_ev
|
||||||
data:
|
data: {}
|
||||||
topic: homeassistant/YOUR_CAR_VIN/command
|
|
||||||
payload: '{"command": "startVehicle"}'
|
|
||||||
mode: single
|
mode: single
|
||||||
icon: 'mdi:car-electric'
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Commands:
|
#### Commands:
|
||||||
[OnStarJS Command Docs](https://github.com/samrum/OnStarJS#commands)
|
[OnStarJS Command Docs](https://github.com/samrum/OnStarJS#commands)
|
||||||
1. `getAccountVehicles`
|
1. `getAccountVehicles`
|
||||||
@ -53,6 +88,12 @@ icon: 'mdi:car-electric'
|
|||||||
9. `cancelChargeOverride`
|
9. `cancelChargeOverride`
|
||||||
10. `getLocation`
|
10. `getLocation`
|
||||||
|
|
||||||
|
|
||||||
|
### Lovelace Dashboard
|
||||||
|
Create a new dashboard, or use the cards in your own view. The `mdi:car-electric` icon works well here.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
#### dashboard yaml:
|
#### dashboard yaml:
|
||||||
```yaml
|
```yaml
|
||||||
views:
|
views:
|
||||||
|
@ -13,7 +13,6 @@ Collect the following information:
|
|||||||
4. MQTT server information: hostname, username, password
|
4. MQTT server information: hostname, username, password
|
||||||
4a. If using TLS, define `MQTT_PORT` and `MQTT_TLS=true`
|
4a. If using TLS, define `MQTT_PORT` and `MQTT_TLS=true`
|
||||||
|
|
||||||
|
|
||||||
### Node.js
|
### Node.js
|
||||||
It's a typical node.js application, that uses .env variables to run. To install and run, follow the steps bellow.
|
It's a typical node.js application, that uses .env variables to run. To install and run, follow the steps bellow.
|
||||||
```
|
```
|
||||||
|
23
src/index.js
23
src/index.js
@ -26,7 +26,9 @@ const onstarConfig = {
|
|||||||
onStarPin: process.env.ONSTAR_PIN || ospin,
|
onStarPin: process.env.ONSTAR_PIN || ospin,
|
||||||
checkRequestStatus: process.env.ONSTAR_SYNC === "true" || true,
|
checkRequestStatus: process.env.ONSTAR_SYNC === "true" || true,
|
||||||
refreshInterval: parseInt(process.env.ONSTAR_REFRESH) || (30 * 60 * 1000), // 30 min
|
refreshInterval: parseInt(process.env.ONSTAR_REFRESH) || (30 * 60 * 1000), // 30 min
|
||||||
allowCommands: _.toLower(_.get(process, 'env.ONSTAR_ALLOW_COMMANDS', 'true')) === 'true'
|
requestPollingIntervalSeconds: parseInt(process.env.ONSTAR_POLL_INTERVAL) || 6, // 6 sec default
|
||||||
|
requestPollingTimeoutSeconds: parseInt(process.env.ONSTAR_POLL_TIMEOUT) || 60, // 60 sec default
|
||||||
|
allowCommands: _.get(process.env, 'ONSTAR_ALLOW_COMMANDS', 'true') === 'true'
|
||||||
};
|
};
|
||||||
logger.info('OnStar Config', {onstarConfig});
|
logger.info('OnStar Config', {onstarConfig});
|
||||||
|
|
||||||
@ -95,9 +97,11 @@ const configureMQTT = async (commands, client, mqttHA) => {
|
|||||||
.then(data => {
|
.then(data => {
|
||||||
// TODO refactor the response handling for commands
|
// TODO refactor the response handling for commands
|
||||||
logger.info('Command completed', { command });
|
logger.info('Command completed', { command });
|
||||||
|
const responseData = _.get(data, 'response.data');
|
||||||
|
if (responseData) {
|
||||||
|
logger.info('Command response data', { responseData });
|
||||||
const location = _.get(data, 'response.data.commandResponse.body.location');
|
const location = _.get(data, 'response.data.commandResponse.body.location');
|
||||||
if (data && location) {
|
if (location) {
|
||||||
logger.info('Command response data', {location});
|
|
||||||
const topic = mqttHA.getStateTopic({ name: command });
|
const topic = mqttHA.getStateTopic({ name: command });
|
||||||
// TODO create device_tracker entity. MQTT device tracker doesn't support lat/lon and mqtt_json
|
// TODO create device_tracker entity. MQTT device tracker doesn't support lat/lon and mqtt_json
|
||||||
// doesn't have discovery
|
// doesn't have discovery
|
||||||
@ -105,6 +109,7 @@ const configureMQTT = async (commands, client, mqttHA) => {
|
|||||||
JSON.stringify({ latitude: location.lat, longitude: location.long }), { retain: true })
|
JSON.stringify({ latitude: location.lat, longitude: location.long }), { retain: true })
|
||||||
.then(() => logger.info('Published location to topic.', { topic }));
|
.then(() => logger.info('Published location to topic.', { topic }));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(err=> logger.error('Command error', {command, err}));
|
.catch(err=> logger.error('Command error', {command, err}));
|
||||||
});
|
});
|
||||||
@ -178,7 +183,17 @@ const configureMQTT = async (commands, client, mqttHA) => {
|
|||||||
|
|
||||||
const main = async () => run()
|
const main = async () => run()
|
||||||
.then(() => logger.info('Updates complete, sleeping.'))
|
.then(() => logger.info('Updates complete, sleeping.'))
|
||||||
.catch(e => logger.error('Error', {error: e}))
|
.catch(e => {
|
||||||
|
if (e instanceof Error) {
|
||||||
|
logger.error('Error', {error: _.pick(e, [
|
||||||
|
'message', 'stack',
|
||||||
|
'response.status', 'response.statusText', 'response.headers', 'response.data',
|
||||||
|
'request.method', 'request.body', 'request.contentType', 'request.headers', 'request.url'
|
||||||
|
])});
|
||||||
|
} else {
|
||||||
|
logger.error('Error', {error: e});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
await main();
|
await main();
|
||||||
setInterval(main, onstarConfig.refreshInterval);
|
setInterval(main, onstarConfig.refreshInterval);
|
||||||
|
Loading…
Reference in New Issue
Block a user