Skip to content

Commit

Permalink
switched from homekit to ESH ontology (openhab#946)
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Kreuzer <kai@openhab.org>
  • Loading branch information
kaikreuzer authored and doubled-ca committed Aug 14, 2016
1 parent 42825dd commit 73c5ac4
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 55 deletions.
44 changes: 19 additions & 25 deletions addons/io/org.openhab.io.homekit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ org.openhab.homekit:networkInterface=192.168.0.6
```

## Item Configuration
After setting this global configuration, you will need to tag your openHAB items in order to map them to the HomeKit ontology. For our purposes, you may consider HomeKit accessories to be of two forms: simple and complex.
After setting this global configuration, you will need to tag your openHAB items in order to map them to an ontology. For our purposes, you may consider HomeKit accessories to be of two forms: simple and complex.

A simple accessory will be mapped to a single openHAB item (i.e. a Lighbulb is mapped to a Switch, Dimmer, or Color item). A complex accessory will be made up of multiple openHAB items (i.e. a Thermostat is composed of Heating and Cooling thresholds, a mode, and current temperature). Complex accessories require a tag on a Group indicating the accessory type, as well as tags on the items it composes.

Expand All @@ -34,31 +34,25 @@ A full list of supported accessory types can be found in the table below.
<td><b>description</b></td>
</tr>
<tr>
<td>Lightbulb</td>
<td>Lighting</td>
<td>&nbsp;</td>
<td>Switch, Dimmer, Color</td>
<td>A lightbulb</td>
<td>A lightbulb, either switchable or dimmable</td>
</tr>
<tr>
<td>DimmableLightbulb</td>
<td>&nbsp;</td>
<td>Dimmer, Color</td>
<td>A lightbulb with the ability to set an output level</td>
</tr>
<tr>
<td>Switch</td>
<td>Switchable</td>
<td>&nbsp;</td>
<td>Switch, Dimmer, Color</td>
<td>An accessory that can be turned off and on. While similar to a lightbulb, this will be presented differently in the Siri grammar and iOS apps</td>
</tr>
<tr>
<td>TemperatureSensor</td>
<td>CurrentTemperature</td>
<td>&nbsp;</td>
<td>Number</td>
<td>An accessory that provides a single read-only temperature value. The units default to celsius but can be overridden globally using the useFahrenheitTemperature global property</td>
</tr>
<tr>
<td>HumiditySensor</td>
<td>CurrentHumidity</td>
<td>&nbsp;</td>
<td>Number</td>
<td>An accessory that provides a single read-only value indicating the relative humidity.</td>
Expand All @@ -71,34 +65,34 @@ A full list of supported accessory types can be found in the table below.
</tr>
<tr>
<td>&nbsp;</td>
<td>currentTemperature</td>
<td>CurrentTemperature</td>
<td>Number</td>
<td>The current temperature, using the same unit rules as TemperatureSensor</td>
<td>The current temperature, same as above</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>heatingCoolingMode</td>
<td>homekit:HeatingCoolingMode</td>
<td>String</td>
<td>Indicates the current mode of the device: OFF, AUTO, HEAT, COOL. The string's value must match those defined in the thermostat*Mode properties.</td>
<td>Indicates the current mode of the device: OFF, AUTO, HEAT, COOL. The string's value must match those defined in the thermostat*Mode properties. This is a homekit-specific term and therefore the tags needs to be prefixed with "homekit:"</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>targetTemperature</td>
<td>TargetTemperature</td>
<td>Number</td>
<td>A target temperature that will engage the thermostat's heating and cooling actions as necessary, depending on the heatingCoolingMode</td>
</tr>
</table>

Tags are applied to items using the prefix "homekit:". See the sample below for example items:
See the sample below for example items:

```
Switch KitchenLights "Kitchen Lights" <light> (gKitchen) [ "homekit:Lightbulb" ]
Dimmer BedroomLights "Bedroom Lights" <light> (gBedroom) [ "homekit:DimmableLightbulb" ]
Number BedroomTemperature "Bedroom Temperature" (gBedroom) [ "homekit:TemperatureSensor" ]
Group gDownstairsThermostat "Downstairs Thermostat" (gFF) [ "homekit:Thermostat" ]
Number DownstairsThermostatCurrentTemp "Downstairs Thermostat Current Temperature" (gDownstairsThermostat) [ "homekit:currentTemperature" ]
Number DownstairsThermostatTargetTemperature "Downstairs Thermostat Target Temperature" (gDownstairsThermostat) [ "homekit:targetTemperature" ]
String DownstairsThermostatHeatingCoolingMode "Downstairs Thermostat Heating/Cooling Mode" (gDownstairsThermostat) [ "homekit:heatingCoolingMode" ]
Switch KitchenLights "Kitchen Lights" <light> (gKitchen) [ "Lighting" ]
Dimmer BedroomLights "Bedroom Lights" <light> (gBedroom) [ "Lighting" ]
Number BedroomTemperature "Bedroom Temperature" (gBedroom) [ "CurrentTemperature" ]
Group gDownstairsThermostat "Downstairs Thermostat" (gFF) [ "Thermostat" ]
Number DownstairsThermostatCurrentTemp "Downstairs Thermostat Current Temperature" (gDownstairsThermostat) [ "CurrentTemperature" ]
Number DownstairsThermostatTargetTemperature "Downstairs Thermostat Target Temperature" (gDownstairsThermostat) [ "TargetTemperature" ]
String DownstairsThermostatHeatingCoolingMode "Downstairs Thermostat Heating/Cooling Mode" (gDownstairsThermostat) [ "homekit:HeatingCoolingMode" ]
```

## Additional Notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/
public enum HomekitCharacteristicType {

CURRENT_TEMPERATURE("currentTemperature"),
TARGET_TEMPERATURE("targetTemperature"),
HEATING_COOLING_MODE("heatingCoolingMode");
CURRENT_TEMPERATURE("CurrentTemperature"),
TARGET_TEMPERATURE("TargetTemperature"),
HEATING_COOLING_MODE("homekit:HeatingCoolingMode");

private static final Map<String, HomekitCharacteristicType> tagMap = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

/**
* Enum of the possible device types. The defined tag string can be used
* as a homekit:{tag} tag on an item to enable it for Homekit.
* as a tag on an item to enable it for Homekit.
*
* @author Andy Lintner
*/
public enum HomekitDeviceType {

DIMMABLE_LIGHTBULB("DimmableLightbulb"),
HUMIDITY_SENSOR("HumiditySensor"),
LIGHTBULB("Lightbulb"),
SWITCH("Switch"),
TEMPERATURE_SENSOR("TemperatureSensor"),
DIMMABLE_LIGHTBULB("DimmableLighting"),
HUMIDITY_SENSOR("CurrentHumidity"),
LIGHTBULB("Lighting"),
SWITCH("Switchable"),
TEMPERATURE_SENSOR("CurrentTemperature"),
THERMOSTAT("Thermostat");

private static final Map<String, HomekitDeviceType> tagMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

import org.apache.commons.lang.builder.HashCodeBuilder;
import org.eclipse.smarthome.core.items.Item;
import org.eclipse.smarthome.core.library.items.DimmerItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Wraps an Item with data derived from any homekit: tags defined.
* Wraps an Item with data derived from supported tags defined.
*
* @author Andy Lintner
*/
Expand All @@ -34,15 +35,12 @@ public class HomekitTaggedItem {
public HomekitTaggedItem(Item item) {
this.item = item;
for (String tag : item.getTags()) {
if (tag.startsWith("homekit:")) {
String tagValue = tag.substring("homekit:".length()).trim();
homekitDeviceType = HomekitDeviceType.valueOfTag(tagValue);
if (homekitDeviceType == null) {
homekitCharacteristicType = HomekitCharacteristicType.valueOfTag(tagValue);
if (homekitCharacteristicType == null) {
logger.error("Unrecognized homekit type: " + tagValue);
}
}
if (item instanceof DimmerItem) {
tag = "Dimmable" + tag;
}
homekitDeviceType = HomekitDeviceType.valueOfTag(tag);
if (homekitDeviceType == null) {
homekitCharacteristicType = HomekitCharacteristicType.valueOfTag(tag);
}
}
if (homekitDeviceType != null) {
Expand Down
3 changes: 2 additions & 1 deletion addons/io/org.openhab.io.hueemulation/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Bundle-Vendor: openHAB
Bundle-Version: 2.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ClassPath: .
Import-Package: com.google.gson;version="2.2.4",
Import-Package: com.google.gson,
javax.servlet,
javax.servlet.http,
org.apache.commons.io,
org.apache.commons.lang,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.core.events,
org.eclipse.smarthome.core.items,
Expand Down
16 changes: 10 additions & 6 deletions addons/io/org.openhab.io.hueemulation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@
Hue Emulation exposes openHAB items as Hue devices to other Hue HTTP API compatible applications like an Amazon Echo.

##Features:

* UPNP automatic discovery
* Support ON/OFF and Percent/Decimal item types
* Can expose any type of item, not just lights
* Pairing (security) can be enabled/disabled in real time using the configuration service (under services in the PaperUI for example)

##Configuration:

Pairing can be turned on and off:

```
org.openhab.hueemulation:pairingEnabled=false
```

##Device Taging
To expose an item on the service apply any Apple HomeKit style tag to it. The item label will be used as the Hue Device name.
To expose an item on the service apply a supported tag (which are "Lighting", "Switchable", "TargetTemperature") to it. The item label will be used as the Hue device name.

```
Switch TestSwitch1 "Kitchen Switch" [ "Switchable" ]
Switch TestSwitch2 "Bathroom" [ "Lighting" ]
Dimmer TestDimmer3 "Hallway" [ "Lighting" ]
Number TestNumber4 "Temperature Set Point" [ "TargetTemperature" ]
```
Switch TestSwitch1 "Kitchen Switch" ["homekit:Switch"]
Switch TestSwitch2 "Bathroom" ["homekit:Lightbulb"]
Dimmer TestDimmer3 "Hallway" ["homekit:DimmableLightbulb"]
Number TestNumber4 "Cool Set Point" ["homekit:coolingThreshold"]
```
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
import org.eclipse.smarthome.config.core.ConfigConstants;
import org.eclipse.smarthome.core.events.EventPublisher;
import org.eclipse.smarthome.core.items.Item;
Expand Down Expand Up @@ -67,7 +68,6 @@ public class HueEmulationServlet extends HttpServlet {
private Logger logger = LoggerFactory.getLogger(HueEmulationServlet.class);
private static final String CONFIG_PAIRING_ENABLED = "pairingEnabled";
private static final String PATH = "/api";
private static final String HOMEKIT_PREFIX = "homekit:";
private static final String METHOD_POST = "POST";
private static final String METHOD_PUT = "PUT";
private static final String APPLICATION_XML = "application/xml";
Expand All @@ -80,6 +80,8 @@ public class HueEmulationServlet extends HttpServlet {
private static final File UDN_FILE = new File(
ConfigConstants.getUserDataFolder() + File.separator + "hueemulation" + File.separator + "udn");

private static final String[] SUPPORTED_TAGS = new String[] { "Switchable", "Lighting", "TargetTemperature" };

/**
* This parses "/api/{username}/{lights}/{id}/{state}"
*/
Expand Down Expand Up @@ -424,9 +426,9 @@ public Map<String, String> getHueDeviceNames() {
}

/**
* Converts an VoiceItem to a HueDevice
* Converts an Item to a HueDevice
*
* @param voiceItem
* @param item
* @return
* HueDevice
*/
Expand All @@ -452,7 +454,7 @@ private Collection<Item> getTaggedItems() {
Collection<Item> items = new LinkedList<Item>();
for (Item item : itemRegistry.getItems()) {
for (String tag : item.getTags()) {
if (tag.startsWith(HOMEKIT_PREFIX)) {
if (ArrayUtils.contains(SUPPORTED_TAGS, tag)) {
items.add(item);
break;
}
Expand Down

0 comments on commit 73c5ac4

Please sign in to comment.