2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ecobee.internal.action;
15 import java.util.Date;
16 import java.util.HashMap;
19 import javax.measure.quantity.Temperature;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.ecobee.internal.dto.thermostat.EventDTO;
24 import org.openhab.binding.ecobee.internal.enums.AckType;
25 import org.openhab.binding.ecobee.internal.enums.FanMode;
26 import org.openhab.binding.ecobee.internal.enums.HoldType;
27 import org.openhab.binding.ecobee.internal.enums.PlugState;
28 import org.openhab.binding.ecobee.internal.enums.VentilatorMode;
29 import org.openhab.binding.ecobee.internal.function.AcknowledgeFunction;
30 import org.openhab.binding.ecobee.internal.function.ControlPlugFunction;
31 import org.openhab.binding.ecobee.internal.function.CreateVacationFunction;
32 import org.openhab.binding.ecobee.internal.function.DeleteVacationFunction;
33 import org.openhab.binding.ecobee.internal.function.ResetPreferencesFunction;
34 import org.openhab.binding.ecobee.internal.function.ResumeProgramFunction;
35 import org.openhab.binding.ecobee.internal.function.SendMessageFunction;
36 import org.openhab.binding.ecobee.internal.function.SetHoldFunction;
37 import org.openhab.binding.ecobee.internal.function.SetOccupiedFunction;
38 import org.openhab.binding.ecobee.internal.function.UpdateSensorFunction;
39 import org.openhab.binding.ecobee.internal.handler.EcobeeThermostatBridgeHandler;
40 import org.openhab.binding.ecobee.internal.handler.EcobeeUtils;
41 import org.openhab.core.automation.annotation.ActionInput;
42 import org.openhab.core.automation.annotation.ActionOutput;
43 import org.openhab.core.automation.annotation.RuleAction;
44 import org.openhab.core.library.types.QuantityType;
45 import org.openhab.core.thing.binding.ThingActions;
46 import org.openhab.core.thing.binding.ThingActionsScope;
47 import org.openhab.core.thing.binding.ThingHandler;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
52 * The {@link EcobeeActions} defines the thing actions for the Ecobee binding.
54 * @author John Cocula - Initial contribution
55 * @author Mark Hilbush - Adapted for OH2/3
56 * @author Connor Petty - Proxy method for invoking actions
58 @ThingActionsScope(name = "ecobee")
60 public class EcobeeActions implements ThingActions {
62 private static final Logger LOGGER = LoggerFactory.getLogger(EcobeeActions.class);
64 private @Nullable EcobeeThermostatBridgeHandler handler;
66 public EcobeeActions() {
67 LOGGER.debug("EcobeeActions: EcobeeActions: Actions service created");
71 public void setThingHandler(@Nullable ThingHandler handler) {
72 if (handler instanceof EcobeeThermostatBridgeHandler bridgeHandler) {
73 this.handler = bridgeHandler;
78 public @Nullable ThingHandler getThingHandler() {
83 * The acknowledge function allows an alert to be acknowledged.
86 * href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/Acknowledge.shtml">Acknowledge
89 @RuleAction(label = "acknowledge an alert", description = "Acknowledges an alert.")
90 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean acknowledge(
91 @ActionInput(name = "ackRef", description = "The acknowledge ref of alert") @Nullable String ackRef,
92 @ActionInput(name = "ackType", description = "The type of acknowledgement. Valid values: accept, decline, defer, unacknowledged") @Nullable String ackType,
93 @ActionInput(name = "remindMeLater", description = "(opt) Whether to remind at a later date, if this is a defer acknowledgement") @Nullable Boolean remindMeLater) {
94 LOGGER.debug("EcobeeActions: Action 'Acknowledge' called");
95 EcobeeThermostatBridgeHandler localHandler = handler;
96 if (localHandler == null) {
97 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
100 AcknowledgeFunction function = new AcknowledgeFunction(localHandler.getThermostatId(), ackRef,
101 AckType.forValue(ackType), remindMeLater);
102 return localHandler.actionPerformFunction(function);
105 public static boolean acknowledge(ThingActions actions, @Nullable String ackRef, @Nullable String ackType,
106 @Nullable Boolean remindMeLater) {
107 return ((EcobeeActions) actions).acknowledge(ackRef, ackType, remindMeLater);
111 * Control the on/off state of a plug by setting a hold on the plug.
113 * @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/ControlPlug.shtml">Control
116 @RuleAction(label = "control a plug", description = "Control the on/off state of a plug by setting a hold on the plug.")
117 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean controlPlug(
118 @ActionInput(name = "plugName", description = "The name of the plug. Ensure each plug has a unique name.") @Nullable String plugName,
119 @ActionInput(name = "plugState", description = "The state to put the plug into. Valid values: on, off, resume.") @Nullable String plugState,
120 @ActionInput(name = "startDateTime", description = "(opt) The start date/time in thermostat time.") @Nullable Date startDateTime,
121 @ActionInput(name = "endDateTime", description = "(opt) The end date/time in thermostat time.") @Nullable Date endDateTime,
122 @ActionInput(name = "holdType", description = "(opt) The hold duration type. Valid values: dateTime, nextTransition, indefinite, holdHours.") @Nullable String holdType,
123 @ActionInput(name = "holdHours", description = "(opt) The number of hours to hold for, used and required if holdType='holdHours'.") @Nullable Number holdHours) {
124 LOGGER.debug("EcobeeActions: Action 'Control Plug' called");
125 EcobeeThermostatBridgeHandler localHandler = handler;
126 if (localHandler == null) {
127 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
130 ControlPlugFunction function = (new ControlPlugFunction(plugName, PlugState.forValue(plugState), startDateTime,
131 endDateTime, (holdType == null) ? null : HoldType.forValue(holdType),
132 (holdHours == null) ? null : Integer.valueOf(holdHours.intValue())));
133 return localHandler.actionPerformFunction(function);
136 public static boolean controlPlug(ThingActions actions, @Nullable String plugName, @Nullable String plugState,
137 @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType,
138 @Nullable Number holdHours) {
139 return ((EcobeeActions) actions).controlPlug(plugName, plugState, startDateTime, endDateTime, holdType,
144 * The create vacation function creates a vacation event on the thermostat.
146 * @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/CreateVacation.shtml">Create
149 @RuleAction(label = "create a vacation", description = "The create vacation function creates a vacation event on the thermostat.")
150 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean createVacation(
151 @ActionInput(name = "name", description = "The vacation event name. It must be unique.") @Nullable String name,
152 @ActionInput(name = "coolHoldTemp", description = "The temperature at which to set the cool vacation hold.") @Nullable QuantityType<Temperature> coolHoldTemp,
153 @ActionInput(name = "heatHoldTemp", description = "The temperature at which to set the heat vacation hold.") @Nullable QuantityType<Temperature> heatHoldTemp,
154 @ActionInput(name = "startDateTime", description = "(opt) The start date/time in thermostat time.") @Nullable Date startDateTime,
155 @ActionInput(name = "endDateTime", description = "(opt) The end date in thermostat time.") @Nullable Date endDateTime,
156 @ActionInput(name = "fan", description = "(opt) The fan mode during the vacation. Values: auto, on Default: auto") @Nullable String fan,
157 @ActionInput(name = "fanMinOnTime", description = "(opt) The minimum number of minutes to run the fan each hour. Range: 0-60, Default: 0") @Nullable Number fanMinOnTime) {
158 LOGGER.debug("EcobeeActions: Action 'Create Vacation' called");
159 EcobeeThermostatBridgeHandler localHandler = handler;
160 if (localHandler == null) {
161 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
164 CreateVacationFunction function = new CreateVacationFunction(name, coolHoldTemp, heatHoldTemp, startDateTime,
165 endDateTime, (fan == null) ? null : FanMode.forValue(fan),
166 (fanMinOnTime == null) ? null : Integer.valueOf(fanMinOnTime.intValue()));
167 return localHandler.actionPerformFunction(function);
170 public static boolean createVacation(ThingActions actions, @Nullable String name,
171 @Nullable QuantityType<Temperature> coolHoldTemp, @Nullable QuantityType<Temperature> heatHoldTemp,
172 @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String fan,
173 @Nullable Number fanMinOnTime) {
174 return ((EcobeeActions) actions).createVacation(name, coolHoldTemp, heatHoldTemp, startDateTime, endDateTime,
179 * The delete vacation function deletes a vacation event from a thermostat.
181 * @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/DeleteVacation.shtml">Delete
184 @RuleAction(label = "delete a vacation", description = "The delete vacation function deletes a vacation event from a thermostat.")
185 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean deleteVacation(
186 @ActionInput(name = "name", description = "The vacation event name to delete.") @Nullable String name) {
187 LOGGER.debug("EcobeeActions: Action 'Delete Vacation' called");
188 EcobeeThermostatBridgeHandler localHandler = handler;
189 if (localHandler == null) {
190 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
193 DeleteVacationFunction function = new DeleteVacationFunction(name);
194 return localHandler.actionPerformFunction(function);
197 public static boolean deleteVacation(ThingActions actions, @Nullable String name) {
198 return ((EcobeeActions) actions).deleteVacation(name);
202 * The reset preferences function sets all of the user configurable settings back to the factory default values.
204 * @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/ResetPreferences.shtml">Reset
207 @RuleAction(label = "reset the preferences", description = "The reset preferences function sets all of the user configurable settings back to the factory default values.")
208 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean resetPreferences() {
209 LOGGER.debug("EcobeeActions: Action 'Reset Preferences' called");
210 EcobeeThermostatBridgeHandler localHandler = handler;
211 if (localHandler == null) {
212 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
215 ResetPreferencesFunction function = new ResetPreferencesFunction();
216 return localHandler.actionPerformFunction(function);
219 public static boolean resetPreferences(ThingActions actions) {
220 return ((EcobeeActions) actions).resetPreferences();
224 * The resume program function removes the currently running event.
226 * @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/ResumeProgram.shtml">Resume
229 @RuleAction(label = "resume the program", description = "Removes the currently running event providing the event is not a mandatory demand response event")
230 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean resumeProgram(
231 @ActionInput(name = "resumeAll", description = "(opt) Should the thermostat be resumed to next event (false) or to its program (true)") @Nullable Boolean resumeAll) {
232 LOGGER.debug("EcobeeActions: Action 'Resume Program' called");
233 EcobeeThermostatBridgeHandler localHandler = handler;
234 if (localHandler == null) {
235 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
238 ResumeProgramFunction function = new ResumeProgramFunction(resumeAll);
239 return localHandler.actionPerformFunction(function);
242 public static boolean resumeProgram(ThingActions actions, @Nullable Boolean resumeAll) {
243 return ((EcobeeActions) actions).resumeProgram(resumeAll);
247 * The send message function allows an alert message to be sent to the thermostat.
249 * @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/SendMessage.shtml">Send
252 @RuleAction(label = "send a message", description = "The send message function allows an alert message to be sent to the thermostat.")
253 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMessage(
254 @ActionInput(name = "text", description = "The message text to send. Text will be truncated to 500 characters if longer") @Nullable String text) {
255 LOGGER.debug("EcobeeActions: Action 'SendMessage' called");
256 EcobeeThermostatBridgeHandler localHandler = handler;
257 if (localHandler == null) {
258 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
261 SendMessageFunction function = new SendMessageFunction(text);
262 return localHandler.actionPerformFunction(function);
265 public static boolean sendMessage(ThingActions actions, @Nullable String text) {
266 return ((EcobeeActions) actions).sendMessage(text);
270 * Set an indefinite hold using the supplied the cool and heat hold temperatures
272 * @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/SetHold.shtml">Set Hold</a>
274 @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified temperatures.")
275 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
276 @ActionInput(name = "coolHoldTemp", description = "The temperature at which to set the cool hold.") @Nullable QuantityType<Temperature> coolHoldTemp,
277 @ActionInput(name = "heatHoldTemp", description = "The temperature at which to set the heat hold.") @Nullable QuantityType<Temperature> heatHoldTemp) {
278 if (coolHoldTemp == null || heatHoldTemp == null) {
279 throw new IllegalArgumentException("hold temperatures cannot be null");
281 Map<String, Object> params = new HashMap<String, Object>();
282 params.put("coolHoldTemp", coolHoldTemp);
283 params.put("heatHoldTemp", heatHoldTemp);
284 return setHold(params, null, null, null, null);
287 public static boolean setHold(ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp,
288 @Nullable QuantityType<Temperature> heatHoldTemp) {
289 return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp);
293 * Set a hold by providing the cool and heat temperatures and the number of hours.
295 @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold for the specified number of hours.")
296 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
297 @ActionInput(name = "coolHoldTemp", description = "The temperature at which to set the cool hold.") @Nullable QuantityType<Temperature> coolHoldTemp,
298 @ActionInput(name = "heatHoldTemp", description = "The temperature at which to set the heat hold.") @Nullable QuantityType<Temperature> heatHoldTemp,
299 @ActionInput(name = "holdHours", description = "The number of hours for the hold.") @Nullable Number holdHours) {
300 if (coolHoldTemp == null || heatHoldTemp == null) {
301 throw new IllegalArgumentException("hold temperatures cannot be null");
303 if (holdHours == null) {
304 throw new IllegalArgumentException("number of hold hours is missing");
306 Map<String, Object> params = new HashMap<String, Object>();
307 params.put("coolHoldTemp", coolHoldTemp);
308 params.put("heatHoldTemp", heatHoldTemp);
309 return setHold(params, HoldType.HOLD_HOURS.toString(), holdHours, null, null);
312 public static boolean setHold(ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp,
313 @Nullable QuantityType<Temperature> heatHoldTemp, @Nullable Number holdHours) {
314 return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdHours);
318 * Set an indefinite hold using the supplied climateRef
320 @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified climate ref.")
321 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
322 @ActionInput(name = "holdClimateRef", description = "The holdClimateRef used to set the hold.") @Nullable String holdClimateRef) {
323 EcobeeThermostatBridgeHandler localHandler = handler;
324 if (localHandler == null) {
325 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
328 if (holdClimateRef == null || !localHandler.isValidClimateRef(holdClimateRef)) {
329 throw new IllegalArgumentException("hold climate ref is missing or invalid");
331 Map<String, Object> params = new HashMap<String, Object>();
332 params.put("holdClimateRef", holdClimateRef);
333 return setHold(params, null, null, null, null);
336 public static boolean setHold(ThingActions actions, @Nullable String holdClimateRef) {
337 return ((EcobeeActions) actions).setHold(holdClimateRef);
341 * Set a hold using the supplied climateRef for the supplied number of hours.
343 @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified climate ref.")
344 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
345 @ActionInput(name = "holdClimateRef", description = "The holdClimateRef used to set the hold.") @Nullable String holdClimateRef,
346 @ActionInput(name = "holdHours", description = "The number of hours for the hold.") @Nullable Number holdHours) {
347 if (holdHours == null) {
348 throw new IllegalArgumentException("number of hold hours is missing");
350 EcobeeThermostatBridgeHandler localHandler = handler;
351 if (localHandler == null) {
352 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
355 if (holdClimateRef == null || !localHandler.isValidClimateRef(holdClimateRef)) {
356 throw new IllegalArgumentException("hold climate ref is missing or invalid");
358 Map<String, Object> params = new HashMap<String, Object>();
359 params.put("holdClimateRef", holdClimateRef);
360 return setHold(params, HoldType.HOLD_HOURS.toString(), holdHours, null, null);
363 public static boolean setHold(ThingActions actions, @Nullable String holdClimateRef, @Nullable Number holdHours) {
364 return ((EcobeeActions) actions).setHold(holdClimateRef, holdHours);
370 @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified temperature or climate ref.")
371 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
372 @ActionInput(name = "coolHoldTemp", description = "(opt) The temperature at which to set the cool hold.") @Nullable QuantityType<Temperature> coolHoldTemp,
373 @ActionInput(name = "heatHoldTemp", description = "(opt) The temperature at which to set the heat hold.") @Nullable QuantityType<Temperature> heatHoldTemp,
374 @ActionInput(name = "holdClimateRef", description = "(opt) The Climate to use as reference for setting the coolHoldTemp, heatHoldTemp and fan settings for this hold. If this value is passed the coolHoldTemp and heatHoldTemp are not required.") @Nullable String holdClimateRef,
375 @ActionInput(name = "startDateTime", description = "(opt) The start date in thermostat time.") @Nullable Date startDateTime,
376 @ActionInput(name = "endDateTime", description = "(opt) The end date in thermostat time.") @Nullable Date endDateTime,
377 @ActionInput(name = "holdType", description = "(opt) The hold duration type. Valid values: dateTime, nextTransition, indefinite, holdHours.") @Nullable String holdType,
378 @ActionInput(name = "holdHours", description = "(opt) The number of hours to hold for, used and required if holdType='holdHours'.") @Nullable Number holdHours) {
379 Map<String, Object> params = new HashMap<String, Object>();
380 if (coolHoldTemp != null) {
381 params.put("coolHoldTemp", coolHoldTemp);
383 if (heatHoldTemp != null) {
384 params.put("heatHoldTemp", heatHoldTemp);
386 if (holdClimateRef != null) {
387 params.put("holdClimateRef", holdClimateRef);
389 return setHold(params, holdType, holdHours, startDateTime, endDateTime);
392 public static boolean setHold(ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp,
393 @Nullable QuantityType<Temperature> heatHoldTemp, @Nullable String holdClimateRef,
394 @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType,
395 @Nullable Number holdHours) {
396 return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdClimateRef, startDateTime, endDateTime,
397 holdType, holdHours);
401 * Set a hold by providing a parameter map
403 @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified event parameters.")
404 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
405 @ActionInput(name = "params", description = "The map of hold parameters.") @Nullable Map<String, Object> params,
406 @ActionInput(name = "holdType", description = "(opt) The hold duration type. Valid values: dateTime, nextTransition, indefinite, holdHours.") @Nullable String holdType,
407 @ActionInput(name = "holdHours", description = "(opt) The number of hours to hold for, used and required if holdType='holdHours'.") @Nullable Number holdHours,
408 @ActionInput(name = "startDateTime", description = "(opt) The start date in thermostat time.") @Nullable Date startDateTime,
409 @ActionInput(name = "endDateTime", description = "(opt) The end date in thermostat time.") @Nullable Date endDateTime) {
410 LOGGER.debug("EcobeeActions: Action 'SetHold' called");
411 if (params == null) {
412 throw new IllegalArgumentException("params cannot be null");
414 EventDTO event = new EventDTO();
415 for (String key : params.keySet()) {
416 Object value = params.get(key);
418 LOGGER.warn("Event field '{}' has null value, ignored.", key);
423 event.isOccupied = ((Boolean) value);
426 event.isCoolOff = ((Boolean) value);
429 event.isHeatOff = ((Boolean) value);
432 event.coolHoldTemp = EcobeeUtils.convertQuantityTypeToEcobeeTemp(value);
435 event.heatHoldTemp = EcobeeUtils.convertQuantityTypeToEcobeeTemp(value);
438 event.fan = FanMode.forValue((String) value).toString();
441 event.vent = VentilatorMode.forValue((String) value).toString();
443 case "ventilatorMinOnTime":
444 event.ventilatorMinOnTime = ((Integer) value);
447 event.isOptional = ((Boolean) value);
449 case "isTemperatureRelative":
450 event.isTemperatureRelative = ((Boolean) value);
452 case "coolRelativeTemp":
453 event.coolRelativeTemp = EcobeeUtils.convertQuantityTypeToEcobeeTemp(value);
455 case "heatRelativeTemp":
456 event.heatRelativeTemp = EcobeeUtils.convertQuantityTypeToEcobeeTemp(value);
458 case "isTemperatureAbsolute":
459 event.isTemperatureAbsolute = ((Boolean) value);
462 event.fanMinOnTime = ((Integer) value);
464 case "holdClimateRef":
465 event.holdClimateRef = ((String) value);
468 LOGGER.warn("Unrecognized event field '{}' with value '{}' ignored.", key, value);
472 EcobeeThermostatBridgeHandler localHandler = handler;
473 if (localHandler == null) {
474 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
477 SetHoldFunction function = new SetHoldFunction(event, (holdType == null) ? null : HoldType.forValue(holdType),
478 (holdHours == null) ? null : holdHours.intValue(), startDateTime, endDateTime);
479 return localHandler.actionPerformFunction(function);
482 public static boolean setHold(ThingActions actions, @Nullable Map<String, Object> params, @Nullable String holdType,
483 @Nullable Number holdHours, @Nullable Date startDateTime, @Nullable Date endDateTime) {
484 return ((EcobeeActions) actions).setHold(params, holdType, holdHours, startDateTime, endDateTime);
488 * The set occupied function may only be used by EMS thermostats. The function switches a thermostat from occupied
489 * mode to unoccupied, or vice versa.
491 * @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/SetOccupied.shtml">Set
494 @RuleAction(label = "switch the thermostat occupancy", description = "The function switches a thermostat from occupied mode to unoccupied, or vice versa (EMS MODELS ONLY).")
495 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setOccupied(
496 @ActionInput(name = "occupied", description = "The climate to use for the temperature, occupied (true) or unoccupied (false).") @Nullable Boolean occupied,
497 @ActionInput(name = "startDateTime", description = "(opt) The start date in thermostat time.") @Nullable Date startDateTime,
498 @ActionInput(name = "endDateTime", description = "(opt) The end date in thermostat time.") @Nullable Date endDateTime,
499 @ActionInput(name = "holdType", description = "(opt) The hold duration type. Valid values: dateTime, nextTransition, indefinite, holdHours.") @Nullable String holdType,
500 @ActionInput(name = "holdHours", description = "(opt) The number of hours to hold for, used and required if holdType='holdHours'.") @Nullable Number holdHours) {
501 LOGGER.debug("EcobeeActions: Action 'Set Occupied' called");
502 EcobeeThermostatBridgeHandler localHandler = handler;
503 if (localHandler == null) {
504 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
507 SetOccupiedFunction function = new SetOccupiedFunction(occupied, startDateTime, endDateTime,
508 (holdType == null) ? null : HoldType.forValue(holdType),
509 (holdHours == null) ? null : Integer.valueOf(holdHours.intValue()));
510 return localHandler.actionPerformFunction(function);
513 public static boolean setOccupied(ThingActions actions, @Nullable Boolean occupied, @Nullable Date startDateTime,
514 @Nullable Date endDateTime, @Nullable String holdType, @Nullable Number holdHours) {
515 return ((EcobeeActions) actions).setOccupied(occupied, startDateTime, endDateTime, holdType, holdHours);
519 * The update sensor function allows the caller to update the name of an ecobee3 remote sensor.
521 * @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/UpdateSensor.shtml">Update
524 @RuleAction(label = "update a remote sensor name", description = "The update sensor function allows the caller to update the name of an ecobee3 remote sensor.")
525 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean updateSensor(
526 @ActionInput(name = "name", description = "The updated name to give the sensor. Has a max length of 32, but shorter is recommended.") @Nullable String name,
527 @ActionInput(name = "deviceId", description = "The deviceId for the sensor, typically this indicates the enclosure and corresponds to the ThermostatRemoteSensor.id field. For example: rs:100") @Nullable String deviceId,
528 @ActionInput(name = "sensorId", description = "The identifier for the sensor within the enclosure. Corresponds to the RemoteSensorCapability.id. For example: 1") @Nullable String sensorId) {
529 LOGGER.debug("EcobeeActions: Action 'UpdateSensor' called");
530 EcobeeThermostatBridgeHandler localHandler = handler;
531 if (localHandler == null) {
532 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
535 UpdateSensorFunction function = new UpdateSensorFunction(name, deviceId, sensorId);
536 return localHandler.actionPerformFunction(function);
539 public static boolean updateSensor(ThingActions actions, @Nullable String name, @Nullable String deviceId,
540 @Nullable String sensorId) {
541 return ((EcobeeActions) actions).updateSensor(name, deviceId, sensorId);
545 * Get the alerts list. Returns a JSON string containing all the alerts.
547 @RuleAction(label = "get the alerts", description = "Get the alerts list.")
548 public @ActionOutput(name = "alerts", type = "java.lang.String") @Nullable String getAlerts() {
549 LOGGER.debug("EcobeeActions: Action 'Get Alerts' called");
550 EcobeeThermostatBridgeHandler localHandler = handler;
551 if (localHandler == null) {
552 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
555 return localHandler.getAlerts();
558 public static @Nullable String getAlerts(ThingActions actions) {
559 return ((EcobeeActions) actions).getAlerts();
563 * Get the events list. Returns a JSON string contains all events.
565 @RuleAction(label = "get the events", description = "Get the events list.")
566 public @ActionOutput(name = "events", type = "java.lang.String") @Nullable String getEvents() {
567 LOGGER.debug("EcobeeActions: Action 'Get Events' called");
568 EcobeeThermostatBridgeHandler localHandler = handler;
569 if (localHandler == null) {
570 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
573 return localHandler.getEvents();
576 public static @Nullable String getEvents(ThingActions actions) {
577 return ((EcobeeActions) actions).getEvents();
581 * Get a list of climates. Returns a JSON string contains all climates.
583 @RuleAction(label = "get the climates", description = "Get a list of climates.")
584 public @ActionOutput(name = "climates", type = "java.lang.String") @Nullable String getClimates() {
585 LOGGER.debug("EcobeeActions: Action 'Get Climates' called");
586 EcobeeThermostatBridgeHandler localHandler = handler;
587 if (localHandler == null) {
588 LOGGER.info("EcobeeActions: Action service ThingHandler is null!");
591 return localHandler.getClimates();
594 public static @Nullable String getClimates(ThingActions actions) {
595 return ((EcobeeActions) actions).getClimates();