diff --git a/bundles/org.openhab.binding.tado/README.md b/bundles/org.openhab.binding.tado/README.md
index 5cc7a1a1027..69c03afdac7 100644
--- a/bundles/org.openhab.binding.tado/README.md
+++ b/bundles/org.openhab.binding.tado/README.md
@@ -3,7 +3,7 @@
The tado° binding integrates devices from [tado°](https://www.tado.com).
It requires a fully functional tado° installation.
-You can then monitor and control all zone types (Heating, AC, Hot Water) as well as retrieve the HOME/AWAY status of mobile devices.
+You can then monitor and control all zone types (Heating, AC, Hot Water) as well as retrieve the HOME/AWAY status of mobile devices, and setting the HOME/AWAY status of your home.
## `home` Thing (the Bridge)
@@ -24,6 +24,12 @@ Bridge tado:home:demo [ username="mail@example.com", password="secret" ]
Afterwards the discovery will show all zones and mobile devices associated with the user's home.
+### Channels
+
+Name | Type | Description | Read/Write
+-|-|-|-|-
+`homePresence` | String | Current presence value of the tado home. `HOME` and `AWAY` can be set | RW
+
## `zone` Thing
A *zone* is an area/room of your home.
@@ -143,6 +149,7 @@ Bridge tado:home:demo [ username="mail@example.com", password="secret" ] {
## tado.items
```
+Switch TADO_PRESENCE_home "Tado Presence: [MAP(presence.map):%s]" { channel="tado:home:demo:homePresence" }
Number:Temperature HEAT_inside_temperature "Inside Temperature" { channel="tado:zone:demo:heating:currentTemperature" }
Number HEAT_humidity "Humidity" { channel="tado:zone:demo:heating:humidity" }
Number HEAT_heating_power "Heating Power" { channel="tado:zone:demo:heating:heatingPower" }
@@ -179,6 +186,10 @@ Switch Phone_atHome "Phone location [MAP(presence.map)
```
sitemap tado label="Tado"
{
+ Frame label="Status" {
+ Switch item=TADO_PRESENCE_home icon="presence"
+ }
+
Frame label="Heating" {
Text item=HEAT_inside_temperature
Text item=HEAT_humidity
diff --git a/bundles/org.openhab.binding.tado/pom.xml b/bundles/org.openhab.binding.tado/pom.xml
index dc875d448f0..820647def0b 100644
--- a/bundles/org.openhab.binding.tado/pom.xml
+++ b/bundles/org.openhab.binding.tado/pom.xml
@@ -18,7 +18,7 @@
org.openhab.binding.tado
api-client
- 1.3.0
+ 1.4.1
compile
diff --git a/bundles/org.openhab.binding.tado/src/main/api/pom.xml b/bundles/org.openhab.binding.tado/src/main/api/pom.xml
index 6269fb3ab76..db567d4d053 100644
--- a/bundles/org.openhab.binding.tado/src/main/api/pom.xml
+++ b/bundles/org.openhab.binding.tado/src/main/api/pom.xml
@@ -5,7 +5,7 @@
org.openhab.binding.tado
api-client
- 1.3.0
+ 1.4.1
1.8
diff --git a/bundles/org.openhab.binding.tado/src/main/api/tado-api.yaml b/bundles/org.openhab.binding.tado/src/main/api/tado-api.yaml
index 363ab0ca90c..53d21c9579d 100644
--- a/bundles/org.openhab.binding.tado/src/main/api/tado-api.yaml
+++ b/bundles/org.openhab.binding.tado/src/main/api/tado-api.yaml
@@ -73,6 +73,62 @@ paths:
404:
$ref: "#/responses/NotFound"
+ /homes/{home_id}/state:
+ get:
+ operationId: homeState
+ summary: Get state of home
+ tags:
+ - home
+ security:
+ - oauth:
+ - home.details:read
+ description: This will the current presence state of the home (HOME/AWAY).
+ parameters:
+ - $ref: "#/parameters/homeID"
+ responses:
+ 200:
+ description: Home State
+ schema:
+ $ref: "#/definitions/HomeState"
+ 401:
+ $ref: "#/responses/Unauthorized"
+ 403:
+ $ref: "#/responses/AccessDenied"
+ 404:
+ $ref: "#/responses/NotFound"
+
+ /homes/{home_id}/presenceLock:
+ put:
+ operationId: updatePresenceLock
+ summary: Set a presence lock state, i.e., HOME or AWAY
+ tags:
+ - home
+ security:
+ - oauth:
+ - home.operation:write
+ description: This will set the presence mode of the home
+ parameters:
+ - $ref: "#/parameters/homeID"
+ - name: json
+ in: body
+ description: The new presence settings.
+ required: true
+ schema:
+ $ref: "#/definitions/HomePresence"
+ responses:
+ 200:
+ description: Presence mode successfully updated.
+ 400:
+ $ref: "#/responses/BadRequest"
+ 401:
+ $ref: "#/responses/Unauthorized"
+ 403:
+ $ref: "#/responses/AccessDenied"
+ 404:
+ $ref: "#/responses/NotFound"
+ 422:
+ $ref: "#/responses/UnprocessableEntity"
+
/homes/{home_id}/zones:
get:
operationId: listZones
@@ -368,6 +424,37 @@ definitions:
- temperatureUnit
- awayRadiusInMeters
+ HomeState:
+ type: object
+ properties:
+ presence:
+ description: Presence State.
+ $ref: "#/definitions/PresenceState"
+ name:
+ description: User defined name for the home.
+ type: string
+ readOnly: true
+ presenceLocked:
+ description: Not sure what this does..
+ type: boolean
+ readOnly: true
+ showHomePresenceSwitchButton:
+ description: Not sure what this does..
+ type: boolean
+ readOnly: true
+ required:
+ - presence
+ - presenceLocked
+
+ HomePresence:
+ type: object
+ properties:
+ homePresence:
+ description: Presence State.
+ $ref: "#/definitions/PresenceState"
+ required:
+ - homePresence
+
TadoSystemType:
description: The system type of the zone.
type: string
@@ -426,6 +513,13 @@ definitions:
- 'ON'
- 'OFF'
+ PresenceState:
+ type: string
+ description: Enum to represent presence state.
+ enum:
+ - 'HOME'
+ - 'AWAY'
+
GenericZoneSetting:
type: object
discriminator: type
diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/TadoBindingConstants.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/TadoBindingConstants.java
index 3a2cc09e25c..a8d2a312ee9 100644
--- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/TadoBindingConstants.java
+++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/TadoBindingConstants.java
@@ -41,6 +41,8 @@ public class TadoBindingConstants {
FAHRENHEIT
}
+ public static final String CHANNEL_HOME_PRESENCE_MODE = "homePresence";
+
public static final String CHANNEL_ZONE_CURRENT_TEMPERATURE = "currentTemperature";
public static final String CHANNEL_ZONE_HUMIDITY = "humidity";
diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java
index 523211210e3..555d762caa8 100644
--- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java
+++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java
@@ -22,14 +22,19 @@ import org.openhab.binding.tado.internal.api.ApiException;
import org.openhab.binding.tado.internal.api.HomeApiFactory;
import org.openhab.binding.tado.internal.api.client.HomeApi;
import org.openhab.binding.tado.internal.api.model.HomeInfo;
+import org.openhab.binding.tado.internal.api.model.HomePresence;
+import org.openhab.binding.tado.internal.api.model.HomeState;
+import org.openhab.binding.tado.internal.api.model.PresenceState;
import org.openhab.binding.tado.internal.api.model.User;
import org.openhab.binding.tado.internal.config.TadoHomeConfig;
+import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.binding.BaseBridgeHandler;
import org.openhab.core.types.Command;
+import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -126,9 +131,44 @@ public class TadoHomeHandler extends BaseBridgeHandler {
return homeId;
}
+ public HomeState getHomeState() throws IOException, ApiException {
+ HomeApi api = getApi();
+ return api != null ? api.homeState(getHomeId()) : null;
+ }
+
+ public void updateHomeState() {
+ try {
+ updateState(TadoBindingConstants.CHANNEL_HOME_PRESENCE_MODE,
+ getHomeState().getPresence() == PresenceState.HOME ? OnOffType.ON : OnOffType.OFF);
+ } catch (IOException | ApiException e) {
+ logger.debug("Error accessing tado server: {}", e.getMessage(), e);
+ }
+ }
+
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
- // Nothing to do for a bridge
+ String id = channelUID.getId();
+
+ if (command == RefreshType.REFRESH) {
+ updateHomeState();
+ return;
+ }
+
+ switch (id) {
+ case TadoBindingConstants.CHANNEL_HOME_PRESENCE_MODE:
+ HomePresence presence = new HomePresence();
+ presence.setHomePresence(command.toFullString().toUpperCase().equals("ON")
+ || command.toFullString().toUpperCase().equals("HOME") ? PresenceState.HOME
+ : PresenceState.AWAY);
+ try {
+ api.updatePresenceLock(homeId, presence);
+ } catch (IOException | ApiException e) {
+ logger.warn("Error setting home presence: {}", e.getMessage(), e);
+ }
+
+ break;
+
+ }
}
public State getBatteryLowAlarm(long zoneId) {
diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoZoneHandler.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoZoneHandler.java
index 3b01e366e61..7abd80f27f9 100644
--- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoZoneHandler.java
+++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoZoneHandler.java
@@ -218,6 +218,11 @@ public class TadoZoneHandler extends BaseHomeThingHandler {
}
private void updateZoneState(boolean forceUpdate) {
+ TadoHomeHandler home = getHomeHandler();
+ if (home != null) {
+ home.updateHomeState();
+ }
+
// No update during HVAC change debounce
if (!forceUpdate && scheduledHvacChange != null && !scheduledHvacChange.isDone()) {
return;
@@ -258,7 +263,6 @@ public class TadoZoneHandler extends BaseHomeThingHandler {
"Could not connect to server due to " + e.getMessage());
}
- TadoHomeHandler home = getHomeHandler();
if (home != null) {
updateState(TadoBindingConstants.CHANNEL_ZONE_BATTERY_LOW_ALARM, home.getBatteryLowAlarm(getZoneId()));
}
diff --git a/bundles/org.openhab.binding.tado/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.tado/src/main/resources/OH-INF/thing/thing-types.xml
index 90c6da3120f..2b213c992c0 100644
--- a/bundles/org.openhab.binding.tado/src/main/resources/OH-INF/thing/thing-types.xml
+++ b/bundles/org.openhab.binding.tado/src/main/resources/OH-INF/thing/thing-types.xml
@@ -9,6 +9,10 @@
The user's tado home
+
+
+
+
@@ -108,6 +112,12 @@
+
+ Switch
+
+ ON if at home, OFF if away
+
+
Number:Temperature