Skip to content

Commit

Permalink
[tesla] Add channels for active routing (openhab#15705)
Browse files Browse the repository at this point in the history
Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
  • Loading branch information
hakan42 authored and austvik committed Mar 27, 2024
1 parent b470d18 commit da32329
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 1 deletion.
18 changes: 17 additions & 1 deletion bundles/org.openhab.binding.tesla/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ Additionally, these advanced channels are available (not all are available on al

| Channel ID | Item Type | Label | Description |
|---------------------------|--------------------------|-------------------------------|------------------------------------------------------------------------------------------------------------------|
| destinationname | String | Route destination | Name of the destination |
| destinationlocation | Location | Route location | Location of the destination |
| distancetoarrival | Number:Length | Distance to arrival | Distance to drive to the destination (in miles) |
| minutestoarrival | Number:Time | Minutes to arrival | Minutes to drive to the destination |
| trafficminutesdelay | Number:Time | Traffic delay | Minutes of delay due to traffic |
| autoparkstate | String | Autopark State | Undocumented / To be defined |
| autoparkstyle | String | Autopark Style | Undocumented / To be defined |
| batterycurrent | Number:ElectricCurrent | Battery Current | Current (Ampere) floating into (+) or out (-) of the battery |
Expand Down Expand Up @@ -200,7 +205,6 @@ demo.Things:
Bridge tesla:account:myaccount "My Tesla Account" [ refreshToken="xxxx" ] {
model3 mycar "My favorite car" [ vin="5YJSA7H25FFP53736"]
}
```

demo.items:

Expand Down Expand Up @@ -263,6 +267,11 @@ Number:Temperature TeslaTemperature {channel="account:model3:myaccou
Number:Temperature TeslaTemperatureCombined {channel="account:model3:myaccount:mycar:combinedtemp"}
Number:Temperature TeslaInsideTemperature {channel="account:model3:myaccount:mycar:insidetemp"}
Number:Temperature TeslaOutsideTemperature {channel="account:model3:myaccount:mycar:outsidetemp"}

String TeslaDestinationName {channel="account:model3:myaccount:mycar:destinationname"}
Location TeslaDestinationLocation {channel="account:model3:myaccount:mycar:destinationlocation"}
Number:Time TeslaMinutesToArrival {channel="account:model3:myaccount:mycar:minutestoarrival", unit="min"}
Number:Length TeslaDistanceToArrival {channel="account:model3:myaccount:mycar:distancetoarrival"}
```

demo.sitemap:
Expand Down Expand Up @@ -339,6 +348,13 @@ sitemap main label="Main"
{
Mapview item=TeslaLocation height=10
}
Frame
{
Default item=TeslaDestinationName
Default item=TeslaMinutesToArrival
Default item=TeslaDistanceToArrival
Mapview item=TeslaDestinationLocation height=10
}
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,48 @@ public class TeslaChannelSelectorProxy {
public enum TeslaChannelSelector {

API("api_version", "api", DecimalType.class, true),
AR_DESTINATION("active_route_destination", "destinationname", StringType.class, false),
AR_LATITUDE("active_route_latitude", "destinationlocation", DecimalType.class, false) {
@Override
public State getState(String s, TeslaChannelSelectorProxy proxy, Map<String, String> properties) {
proxy.latitude = s;
return new PointType(new StringType(proxy.latitude), new StringType(proxy.longitude),
new StringType(proxy.elevation));
}
},
AR_LONGITUDE("active_route_longitude", "destinationlocation", DecimalType.class, false) {
@Override
public State getState(String s, TeslaChannelSelectorProxy proxy, Map<String, String> properties) {
proxy.longitude = s;
return new PointType(new StringType(proxy.latitude), new StringType(proxy.longitude),
new StringType(proxy.elevation));
}
},
AR_DISTANCE_TO_ARRIVAL("active_route_miles_to_arrival", "distancetoarrival", DecimalType.class, false) {
@Override
public State getState(String s, TeslaChannelSelectorProxy proxy, Map<String, String> properties) {
State someState = super.getState(s);
BigDecimal value = ((DecimalType) someState).toBigDecimal();
return new QuantityType<>(value, ImperialUnits.MILE);
}
},
AR_MINUTES_TO_ARRIVAL("active_route_minutes_to_arrival", "minutestoarrival", DecimalType.class, false) {
@Override
public State getState(String s, TeslaChannelSelectorProxy proxy, Map<String, String> properties) {
State someState = super.getState(s);
BigDecimal value = ((DecimalType) someState).toBigDecimal();
return new QuantityType<>(value, Units.MINUTE);
}
},
AR_TRAFFIC_MINUTES_DELAY("active_route_traffic_minutes_delay", "trafficminutesdelay", DecimalType.class,
false) {
@Override
public State getState(String s, TeslaChannelSelectorProxy proxy, Map<String, String> properties) {
State someState = super.getState(s);
BigDecimal value = ((DecimalType) someState).toBigDecimal();
return new QuantityType<>(value, Units.MINUTE);
}
},
AUTO_COND("is_auto_conditioning_on", "autoconditioning", OnOffType.class, false) {
@Override
public State getState(String s, TeslaChannelSelectorProxy proxy, Map<String, String> properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
*/
public class DriveState {

public String active_route_destination;
public double active_route_latitude;
public double active_route_longitude;
public double active_route_miles_to_arrival;
public double active_route_minutes_to_arrival;
public double active_route_traffic_minutes_delay;
public double latitude;
public double longitude;
public double native_latitude;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ thing-type.config.tesla.vehicle.vin.description = VIN of the vehicle

# channel types

channel-type.tesla.destinationname.label = Route Destination
channel-type.tesla.destinationname.description = Name of the destination
channel-type.tesla.destinationlocation.label = Route Location
channel-type.tesla.destinationlocation.description = Location of the destination
channel-type.tesla.distancetoarrival.label = Distance To Arrival
channel-type.tesla.distancetoarrival.description = Distance to drive to the destination (in miles)
channel-type.tesla.minutestoarrival.label = Minutes To Arrival
channel-type.tesla.minutestoarrival.description = Minutes to drive to the destination
channel-type.tesla.trafficminutesdelay.label = Traffic Delay
channel-type.tesla.trafficminutesdelay.description = Delay to arrive at the destination due to traffic

channel-type.tesla.autoconditioning.label = Auto Conditioning
channel-type.tesla.autoconditioning.description = Turns on auto-conditioning (a/c or heating)
channel-type.tesla.autoparkstate.label = Autopark State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">

<channel-type id="destinationname">
<item-type>String</item-type>
<label>Route Destination</label>
<description>Name of the destination</description>
<state readOnly="true"></state>
</channel-type>
<channel-type id="destinationlocation" advanced="false">
<item-type>Location</item-type>
<label>Route Location</label>
<description>Location of the destination</description>
<state readOnly="true"></state>
</channel-type>
<channel-type id="distancetoarrival">
<item-type>Number:Length</item-type>
<label>Distance To Arrival</label>
<description>Distance to drive to the destination (in miles)</description>
<state pattern="%.1f %unit%" readOnly="true"></state>
</channel-type>
<channel-type id="minutestoarrival">
<item-type>Number:Time</item-type>
<label>Minutes To Arrival</label>
<description>Minutes to drive to the destination</description>
<category>Time</category>
<state pattern="%d %unit%" readOnly="true"></state>
</channel-type>
<channel-type id="trafficminutesdelay">
<item-type>Number:Time</item-type>
<label>Traffic Delay</label>
<description>Delay to arrive at the destination due to traffic</description>
<category>Time</category>
<state pattern="%d %unit%" readOnly="true"></state>
</channel-type>

<channel-type id="autoconditioning">
<item-type>Switch</item-type>
<label>Auto Conditioning</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<description>A Tesla Model 3 Vehicle</description>

<channels>
<channel id="destinationname" typeId="destinationname"/>
<channel id="destinationlocation" typeId="destinationlocation"/>
<channel id="distancetoarrival" typeId="distancetoarrival"/>
<channel id="minutestoarrival" typeId="minutestoarrival"/>
<channel id="trafficminutesdelay" typeId="trafficminutesdelay"/>
<channel id="autoconditioning" typeId="autoconditioning"/>
<channel id="autoparkstate" typeId="autoparkstate"/>
<channel id="autoparkstate2" typeId="autoparkstate"/>
Expand Down Expand Up @@ -120,6 +125,10 @@
<channel id="wakeup" typeId="wakeup"/>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<config-description>
<parameter name="vin" type="text" required="true">
<label>Vehicle Identification Number</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<description>A Tesla Model S Vehicle</description>

<channels>
<channel id="destinationname" typeId="destinationname"/>
<channel id="destinationlocation" typeId="destinationlocation"/>
<channel id="distancetoarrival" typeId="distancetoarrival"/>
<channel id="minutestoarrival" typeId="minutestoarrival"/>
<channel id="trafficminutesdelay" typeId="trafficminutesdelay"/>
<channel id="autoconditioning" typeId="autoconditioning"/>
<channel id="autoparkstate" typeId="autoparkstate"/>
<channel id="autoparkstate2" typeId="autoparkstate"/>
Expand Down Expand Up @@ -126,6 +131,10 @@
<channel id="wiperbladeheater" typeId="wiperbladeheater"/>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<config-description>
<parameter name="vin" type="text" required="true">
<label>Vehicle Identification Number</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<description>A Tesla Model X Vehicle</description>

<channels>
<channel id="destinationname" typeId="destinationname"/>
<channel id="destinationlocation" typeId="destinationlocation"/>
<channel id="distancetoarrival" typeId="distancetoarrival"/>
<channel id="minutestoarrival" typeId="minutestoarrival"/>
<channel id="trafficminutesdelay" typeId="trafficminutesdelay"/>
<channel id="autoconditioning" typeId="autoconditioning"/>
<channel id="autoparkstate" typeId="autoparkstate"/>
<channel id="autoparkstate2" typeId="autoparkstate"/>
Expand Down Expand Up @@ -126,6 +131,10 @@
<channel id="wiperbladeheater" typeId="wiperbladeheater"/>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<config-description>
<parameter name="vin" type="text" required="true">
<label>Vehicle Identification Number</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<description>A Tesla Model Y Vehicle</description>

<channels>
<channel id="destinationname" typeId="destinationname"/>
<channel id="destinationlocation" typeId="destinationlocation"/>
<channel id="distancetoarrival" typeId="distancetoarrival"/>
<channel id="minutestoarrival" typeId="minutestoarrival"/>
<channel id="trafficminutesdelay" typeId="trafficminutesdelay"/>
<channel id="allowwakeup" typeId="allowwakeup"/>
<channel id="autoconditioning" typeId="autoconditioning"/>
<channel id="autoparkstate" typeId="autoparkstate"/>
Expand Down Expand Up @@ -122,6 +127,10 @@
<channel id="wakeup" typeId="wakeup"/>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<config-description>
<parameter name="vin" type="text" required="true">
<label>Vehicle Identification Number</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<update:update-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:update="https://openhab.org/schemas/update-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/update-description/v1.0.0 https://openhab.org/schemas/update-description-1.0.0.xsd">

<thing-type uid="tesla:model3">
<instruction-set targetVersion="1">
<add-channel id="destinationname">
<type>tesla:destinationname</type>
</add-channel>
<add-channel id="destinationlocation">
<type>tesla:destinationlocation</type>
</add-channel>
<add-channel id="distancetoarrival">
<type>tesla:distancetoarrival</type>
</add-channel>
<add-channel id="minutestoarrival">
<type>tesla:minutestoarrival</type>
</add-channel>
<add-channel id="trafficminutesdelay">
<type>tesla:trafficminutesdelay</type>
</add-channel>
</instruction-set>
</thing-type>

<thing-type uid="tesla:models">
<instruction-set targetVersion="1">
<add-channel id="destinationname">
<type>tesla:destinationname</type>
</add-channel>
<add-channel id="destinationlocation">
<type>tesla:destinationlocation</type>
</add-channel>
<add-channel id="distancetoarrival">
<type>tesla:distancetoarrival</type>
</add-channel>
<add-channel id="minutestoarrival">
<type>tesla:minutestoarrival</type>
</add-channel>
<add-channel id="trafficminutesdelay">
<type>tesla:trafficminutesdelay</type>
</add-channel>
</instruction-set>
</thing-type>

<thing-type uid="tesla:modelx">
<instruction-set targetVersion="1">
<add-channel id="destinationname">
<type>tesla:destinationname</type>
</add-channel>
<add-channel id="destinationlocation">
<type>tesla:destinationlocation</type>
</add-channel>
<add-channel id="distancetoarrival">
<type>tesla:distancetoarrival</type>
</add-channel>
<add-channel id="minutestoarrival">
<type>tesla:minutestoarrival</type>
</add-channel>
<add-channel id="trafficminutesdelay">
<type>tesla:trafficminutesdelay</type>
</add-channel>
</instruction-set>
</thing-type>

<thing-type uid="tesla:modely">
<instruction-set targetVersion="1">
<add-channel id="destinationname">
<type>tesla:destinationname</type>
</add-channel>
<add-channel id="destinationlocation">
<type>tesla:destinationlocation</type>
</add-channel>
<add-channel id="distancetoarrival">
<type>tesla:distancetoarrival</type>
</add-channel>
<add-channel id="minutestoarrival">
<type>tesla:minutestoarrival</type>
</add-channel>
<add-channel id="trafficminutesdelay">
<type>tesla:trafficminutesdelay</type>
</add-channel>
</instruction-set>
</thing-type>
</update:update-descriptions>

0 comments on commit da32329

Please sign in to comment.