2 * Copyright (c) 2010-2022 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.shelly.internal.api1;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.shelly.internal.api1.Shelly1ApiJsonDTO.ShellyStatusSensor.ShellyMotionSettings;
20 import org.openhab.core.thing.CommonTriggerEvents;
22 import com.google.gson.annotations.SerializedName;
25 * The {@link Shelly1ApiJsonDTO} is used for the JSon/GSon mapping
27 * @author Markus Michels - Initial contribution
29 public class Shelly1ApiJsonDTO {
30 public static final String SHELLY_NULL_URL = "null";
31 public static final String SHELLY_URL_DEVINFO = "/shelly";
32 public static final String SHELLY_URL_STATUS = "/status";
33 public static final String SHELLY_URL_SETTINGS = "/settings";
34 public static final String SHELLY_URL_SETTINGS_AP = "/settings/ap";
35 public static final String SHELLY_URL_SETTINGS_STA = "/settings/sta";
36 public static final String SHELLY_URL_SETTINGS_LOGIN = "/settings/sta";
37 public static final String SHELLY_URL_SETTINGS_CLOUD = "/settings/cloud";
38 public static final String SHELLY_URL_LIST_IR = "/ir/list";
39 public static final String SHELLY_URL_SEND_IR = "/ir/emit";
40 public static final String SHELLY_URL_RESTART = "/reboot";
42 public static final String SHELLY_URL_SETTINGS_RELAY = "/settings/relay";
43 public static final String SHELLY_URL_STATUS_RELEAY = "/status/relay";
44 public static final String SHELLY_URL_CONTROL_RELEAY = "/relay";
46 public static final String SHELLY_URL_SETTINGS_EMETER = "/settings/emeter";
47 public static final String SHELLY_URL_STATUS_EMETER = "/emeter";
48 public static final String SHELLY_URL_DATA_EMETER = "/emeter/{0}/em_data.csv";
50 public static final String SHELLY_URL_CONTROL_ROLLER = "/roller";
51 public static final String SHELLY_URL_SETTINGS_ROLLER = "/settings/roller";
53 public static final String SHELLY_URL_SETTINGS_LIGHT = "/settings/light";
54 public static final String SHELLY_URL_STATUS_LIGHT = "/light";
55 public static final String SHELLY_URL_CONTROL_LIGHT = "/light";
57 public static final String SHELLY_URL_SETTINGS_DIMMER = "/settings/light";
60 public static final String SHELLY_WAKEUPT_SENSOR = "SENSOR"; // new sensordata
61 public static final String SHELLY_WAKEUPT_PERIODIC = "PERIODIC"; // periodic wakeup
62 public static final String SHELLY_WAKEUPT_BUTTON = "BUTTON"; // button pressed
63 public static final String SHELLY_WAKEUPT_POWERON = "POWERON"; // device powered up
64 public static final String SHELLY_WAKEUPT_EXT_POWER = "EXT_POWER"; // charger connected
65 public static final String SHELLY_WAKEUPT_UNKNOWN = "UNKNOWN"; // other event
68 // Action URLs according to the device type
70 public static final String SHELLY_EVENTURL_SUFFIX = "_url";
73 public static final String SHELLY_EVENT_BTN_ON = "btn_on";
74 public static final String SHELLY_EVENT_BTN_OFF = "btn_off";
75 public static final String SHELLY_EVENT_OUT_ON = "out_on";
76 public static final String SHELLY_EVENT_OUT_OFF = "out_off";
77 public static final String SHELLY_EVENT_SHORTPUSH = "shortpush";
78 public static final String SHELLY_EVENT_LONGPUSH = "longpush";
80 public static final String SHELLY_EVENT_DOUBLE_SHORTPUSH = "double_shortpush";
81 public static final String SHELLY_EVENT_TRIPLE_SHORTPUSH = "triple_shortpush";
82 public static final String SHELLY_EVENT_SHORT_LONGTPUSH = "shortpush_longpush";
83 public static final String SHELLY_EVENT_LONG_SHORTPUSH = "longpush_shortpush";
86 public static final String SHELLY_EVENT_BTN1_ON = "btn1_on";
87 public static final String SHELLY_EVENT_BTN1_OFF = "btn1_off";
88 public static final String SHELLY_EVENT_BTN2_ON = "btn2_on";
89 public static final String SHELLY_EVENT_BTN2_OFF = "btn2_off";
90 public static final String SHELLY_EVENT_SHORTPUSH1 = "btn1_shortpush";
91 public static final String SHELLY_EVENT_LONGPUSH1 = "btn1_longpush";
92 public static final String SHELLY_EVENT_SHORTPUSH2 = "btn2_shortpush";
93 public static final String SHELLY_EVENT_LONGPUSH2 = "btn2_longpush";
96 public static final String SHELLY_EVENT_ROLLER_OPEN = "roller_open";
97 public static final String SHELLY_EVENT_ROLLER_CLOSE = "roller_close";
98 public static final String SHELLY_EVENT_ROLLER_STOP = "roller_stop";
99 public static final String SHELLY_EVENT_ROLLER_CALIB = "roller_calibrating";
102 public static final String SHELLY_RSTATE_OPEN = "open";
103 public static final String SHELLY_RSTATE_STOP = "stop";
104 public static final String SHELLY_RSTATE_CLOSE = "close";
107 public static final String SHELLY_EVENT_SENSORREPORT = "report";
108 public static final String SHELLY_EVENT_DARK = "dark";
109 public static final String SHELLY_EVENT_TWILIGHT = "twilight";
110 public static final String SHELLY_EVENT_BRIGHT = "bright";
111 public static final String SHELLY_EVENT_FLOOD_DETECTED = "flood_detected";
112 public static final String SHELLY_EVENT_FLOOD_GONE = "flood_gone";
113 public static final String SHELLY_EVENT_VIBRATION = "vibration"; // DW 1.6.5+
114 public static final String SHELLY_EVENT_OPEN = "open"; // DW 1.6.5+
115 public static final String SHELLY_EVENT_CLOSE = "close"; // DW 1.6.5+
116 public static final String SHELLY_EVENT_TEMP_OVER = "temp_over"; // FW 1.7
117 public static final String SHELLY_EVENT_TEMP_UNDER = "temp_under"; // FW 1.7
120 public static final String SHELLY_EVENT_ALARM_MILD = "alarm_mild"; // DW 1.7+
121 public static final String SHELLY_EVENT_ALARM_HEAVY = "alarm_heavy"; // DW 1.7+
122 public static final String SHELLY_EVENT_ALARM_OFF = "alarm_off"; // DW 1.7+
127 public static final double SHELLY_API_INVTEMP = -999.0;
129 public static final String SHELLY_BTNT_MOMENTARY = "momentary";
130 public static final String SHELLY_BTNT_MOM_ON_RELEASE = "momentary_on_release";
131 public static final String SHELLY_BTNT_ONE_BUTTON = "one_button";
132 public static final String SHELLY_BTNT_TWO_BUTTON = "dual_button";
133 public static final String SHELLY_BTNT_TOGGLE = "toggle";
134 public static final String SHELLY_BTNT_EDGE = "edge";
135 public static final String SHELLY_BTNT_DETACHED = "detached";
137 public static final String SHELLY_STATE_LAST = "last";
138 public static final String SHELLY_STATE_STOP = "stop";
140 public static final String SHELLY_INP_MODE_OPENCLOSE = "openclose";
141 public static final String SHELLY_INP_MODE_ONEBUTTON = "onebutton";
143 public static final String SHELLY_OBSTMODE_DISABLED = "disabled";
144 public static final String SHELLY_SAFETYM_WHILEOPENING = "while_opening";
146 public static final String SHELLY_ALWD_TRIGGER_NONE = "none";
147 public static final String SHELLY_ALWD_ROLLER_TURN_OPEN = "open";
148 public static final String SHELLY_ALWD_ROLLER_TURN_CLOSE = "close";
149 public static final String SHELLY_ALWD_ROLLER_TURN_STOP = "stop";
152 public static final String SHELLY_APIERR_UNAUTHORIZED = "Unauthorized";
153 public static final String SHELLY_APIERR_TIMEOUT = "Timeout";
154 public static final String SHELLY_APIERR_NOT_CALIBRATED = "Not calibrated!";
156 // API device types / properties
157 public static final String SHELLY_CLASS_RELAY = "relay"; // Relay: relay mode
158 public static final String SHELLY_CLASS_ROLLER = "roller"; // Relay: roller mode
159 public static final String SHELLY_CLASS_LIGHT = "light"; // Bulb: color mode
160 public static final String SHELLY_CLASS_EMETER = "emeter"; // EM/EM3: emeter
162 public static final String SHELLY_API_ON = "on";
163 public static final String SHELLY_API_OFF = "off";
164 public static final String SHELLY_API_TRUE = "true";
165 public static final String SHELLY_API_FALSE = "false";
167 public static final String SHELLY_API_MODE = "mode";
168 public static final String SHELLY_MODE_RELAY = "relay"; // Relay: relay mode
169 public static final String SHELLY_MODE_ROLLER = "roller"; // Relay: roller mode
170 public static final String SHELLY_MODE_COLOR = "color"; // Bulb/RGBW2: color mode
171 public static final String SHELLY_MODE_WHITE = "white"; // Bulb/RGBW2: white mode
173 public static final String SHELLY_LED_STATUS_DISABLE = "led_status_disable";
174 public static final String SHELLY_LED_POWER_DISABLE = "led_power_disable";
176 public static final String SHELLY_API_STOPR_NORMAL = "normal";
177 public static final String SHELLY_API_STOPR_SAFETYSW = "safety_switch";
178 public static final String SHELLY_API_STOPR_OBSTACLE = "obstacle";
179 public static final String SHELLY_API_STOPR_OVERPOWER = "overpower";
181 public static final String SHELLY_TIMER_AUTOON = "auto_on";
182 public static final String SHELLY_TIMER_AUTOOFF = "auto_off";
183 public static final String SHELLY_TIMER_ACTIVE = "has_timer";
185 public static final String SHELLY_LIGHT_TURN = "turn";
186 public static final String SHELLY_LIGHT_DEFSTATE = "def_state";
187 public static final String SHELLY_LIGHTTIMER = "timer";
189 public static final String SHELLY_COLOR_RED = "red";
190 public static final String SHELLY_COLOR_BLUE = "blue";
191 public static final String SHELLY_COLOR_GREEN = "green";
192 public static final String SHELLY_COLOR_YELLOW = "yellow";
193 public static final String SHELLY_COLOR_WHITE = "white";
194 public static final String SHELLY_COLOR_GAIN = "gain";
195 public static final String SHELLY_COLOR_BRIGHTNESS = "brightness";
196 public static final String SHELLY_COLOR_TEMP = "temp";
197 public static final String SHELLY_COLOR_EFFECT = "effect";
199 public static final int SHELLY_MIN_ROLLER_POS = 0;
200 public static final int SHELLY_MAX_ROLLER_POS = 100;
201 public static final int SHELLY_MIN_BRIGHTNESS = 0;
202 public static final int SHELLY_MAX_BRIGHTNESS = 100;
203 public static final int SHELLY_MIN_GAIN = 0;
204 public static final int SHELLY_MAX_GAIN = 100;
205 public static final int SHELLY_MIN_COLOR = 0;
206 public static final int SHELLY_MAX_COLOR = 255;
207 public static final int SHELLY_DIM_STEPSIZE = 10;
209 // color temperature: 3000 = warm, 4750 = white, 6565 = cold; gain: 0..100
210 public static final int MIN_COLOR_TEMP_BULB = 3000;
211 public static final int MAX_COLOR_TEMP_BULB = 6500;
212 public static final int MIN_COLOR_TEMP_DUO = 2700;
213 public static final int MAX_COLOR_TEMP_DUO = 6500;
214 public static final int COLOR_TEMP_RANGE_BULB = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
215 public static final int COLOR_TEMP_RANGE_DUO = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
216 public static final double MIN_BRIGHTNESS = 0.0;
217 public static final double MAX_BRIGHTNESS = 100.0;
218 public static final double SATURATION_FACTOR = 2.55;
219 public static final double GAIN_FACTOR = SHELLY_MAX_GAIN / 100;
220 public static final double BRIGHTNESS_FACTOR = SHELLY_MAX_BRIGHTNESS / 100;
223 public static final String SHELLY_API_ILLUM_DARK = "dark";
224 public static final String SHELLY_API_ILLUM_TWILIGHT = "twilight";
225 public static final String SHELLY_API_ILLUM_BRIGHT = "bright";
226 public static final String SHELLY_API_DWSTATE_OPEN = "open";
227 public static final String SHELLY_API_DWSTATE_CLOSE = "close";
230 public static final String SHELLY_IR_CODET_STORED = "stored";
231 public static final String SHELLY_IR_CODET_PRONTO = "pronto";
232 public static final String SHELLY_IR_CODET_PRONTO_HEX = "pronto_hex";
235 public static final int SHELLY_MIN_EFFECT = 0;
236 public static final int SHELLY_MAX_EFFECT = 6;
239 public static final String SHELLY_BTNEVENT_1SHORTPUSH = "S";
240 public static final String SHELLY_BTNEVENT_2SHORTPUSH = "SS";
241 public static final String SHELLY_BTNEVENT_3SHORTPUSH = "SSS";
242 public static final String SHELLY_BTNEVENT_LONGPUSH = "L";
243 public static final String SHELLY_BTNEVENT_SHORTLONGPUSH = "SL";
244 public static final String SHELLY_BTNEVENT_LONGSHORTPUSH = "LS";
246 public static final String SHELLY_TEMP_CELSIUS = "C";
247 public static final String SHELLY_TEMP_FAHRENHEIT = "F";
250 public static final int SHELLY_MOTION_SLEEPTIME_OFFSET = 3; // we need to substract and offset
253 public static final int SHELLY_TRV_MIN_TEMP = 5; // < 5: means: lowest (valve fully closed)
254 public static final int SHELLY_TRV_MAX_TEMP = 30; // > 30: means: highest (valve fully open)
256 public static final String SHELLY_TRV_MODE_MANUAL = "manual";
257 public static final String SHELLY_TRV_MODE_AUTO = "automatic";
259 // CoIoT Multicast setting
260 public static final String SHELLY_COIOT_MCAST = "mcast";
262 public static class ShellySettingsDevice {
265 public String hostname;
270 public Integer longid;
272 @SerializedName("num_outputs")
273 public Integer numOutputs;
274 @SerializedName("num_meters")
275 public Integer numMeters;
276 @SerializedName("num_emeters")
277 public Integer numEMeters;
278 @SerializedName("num_rollers")
279 public Integer numRollers;
282 public static class ShellySettingsWiFiAp {
283 public Boolean enabled;
288 public static class ShellySettingsWiFiNetwork {
289 public Boolean enabled;
293 @SerializedName("ipv4_method")
294 public String ipv4Method;
301 public static class ShellySettingsMqtt {
302 public Boolean enable;
303 public String server;
305 @SerializedName("reconnect_timeout_max")
306 public Double reconnectTimeoutMax;
307 @SerializedName("reconnect_timeout_min")
308 public Double reconnectTimeoutMin;
309 @SerializedName("clean_session")
310 public Boolean cleanSession;
311 @SerializedName("keep_alive")
312 public Integer keepAlive;
313 @SerializedName("will_topic")
314 public String willTopic;
315 @SerializedName("will_message")
316 public String willMessage;
317 @SerializedName("max_qos")
318 public Integer maxQOS;
319 public Boolean retain;
320 @SerializedName("update_period")
321 public Integer updatePeriod;
324 public static class ShellySettingsCoiot { // FW 1.6+
325 @SerializedName("update_period")
326 public Integer updatePeriod;
327 public Boolean enabled; // Motion 1.0.7: Coap can be disabled
328 public String peer; // if set the device uses singlecast CoAP, mcast=set back to Multicast
331 public static class ShellyStatusMqtt {
332 public Boolean connected;
335 public static class ShellySettingsSntp {
336 public String server;
337 public Boolean enabled;
340 public static class ShellySettingsLogin {
341 public Boolean enabled;
342 public Boolean unprotected;
343 public String username;
344 public String password;
347 public static class ShellySettingsBuildInfo {
348 @SerializedName("build_id")
349 public String buildId;
350 @SerializedName("build_timestamp")
351 public String buildTimestamp;
352 @SerializedName("build_version")
353 public String buildVersion;
356 public static class ShellyStatusCloud {
357 public Boolean enabled;
358 public Boolean connected;
361 public static class ShellySettingsHwInfo {
362 @SerializedName("hw_revision")
363 public String hwRevision;
364 @SerializedName("batch_id")
365 public Integer batchId;
368 public static class ShellySettingsScheduleRules {
371 public static class ShellySettingsRelay {
373 @SerializedName("default_state")
374 public String defaultState; // Accepted values: off, on, last, switch
375 @SerializedName("btn_type")
376 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
377 @SerializedName("btn1_type") // Shelly 1L
378 public String btnType1;
379 @SerializedName("btn2_type") // Shelly 1L
380 public String btnType2;
381 @SerializedName("has_timer")
382 public Boolean hasTimer; // Whether a timer is currently armed for this channel
383 @SerializedName("auto_on")
384 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
385 @SerializedName("auto_off")
386 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
387 @SerializedName("btn_on_url")
388 public String btnOnUrl; // input is activated
389 @SerializedName("btnOffUrl")
390 public String btnOffUrl; // input is deactivated
391 @SerializedName("out_on_url")
392 public String outOnUrl; // output is activated
393 @SerializedName("out_off_url")
394 public String outOffUrl; // output is deactivated
395 @SerializedName("roller_open_url")
396 public String rollerOpenUrl; // to access when roller reaches open position
397 @SerializedName("roller_close_url")
398 public String rollerCloseUrl; // to access when roller reaches close position
399 @SerializedName("roller_stop_url")
400 public String rollerStopUrl; // to access when roller stopped
401 @SerializedName("longpush_url")
402 public String pushLongUrl; // to access when roller stopped
403 @SerializedName("shortpush_url")
404 public String pushShortUrl; // to access when roller stopped
406 // Status information
408 public Boolean overpower;
409 @SerializedName("is_valid")
410 public Boolean isValid;
413 public static class ShellySettingsDimmer {
414 public String name; // unique name of the device
415 public Boolean ison; // true: output is ON
416 @SerializedName("default_state")
417 public String defaultState; // Accepted values: off, on, last, switch
418 @SerializedName("auto_on")
419 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
420 @SerializedName("auto_off")
421 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
422 @SerializedName("btn1_on_url")
423 public String btn1OnUrl; // URL to access when SW input is activated
424 @SerializedName("btn1_off_url")
425 public String btn1OffUrl; // URL to access when SW input is deactivated
426 @SerializedName("btn2_on_url")
427 public String btn2OnUrl; // URL to access when SW input is activated
428 @SerializedName("btn2_off_url")
429 public String btn2OoffUrl; // URL to access when SW input is deactivated
430 @SerializedName("out_on_url")
431 public String outOnUrl; // URL to access when output is activated
432 @SerializedName("out_off_url")
433 public String outOffUrl; // URL to access when output is deactivated
434 @SerializedName("longpush_url")
435 public String pushLongUrl; // long push button event
436 @SerializedName("shortpush_url")
437 public String pushShortUrl; // short push button event
438 @SerializedName("btn_type")
439 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
440 @SerializedName("btn1_type")
441 public String btnType1; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
442 @SerializedName("btn2_type")
443 public String btnType2; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
444 @SerializedName("swap_inputs")
445 public Integer swapInputs; // 0=no
448 public static class ShellySettingsRoller {
449 public Double maxtime;
450 @SerializedName("maxtime_open")
451 public Double maxtimeOpen;
452 @SerializedName("maxtime_close")
453 public Double maxtimeClose;
454 @SerializedName("default_state")
455 public String defaultState; // see SHELLY_STATE_xxx
457 @SerializedName("swap_inputs")
458 public Boolean swapInputs;
459 @SerializedName("input_mode")
460 public String inputMode; // see SHELLY_INP_MODE_OPENCLOSE
461 @SerializedName("button_type")
462 public String buttonType; // // see SHELLY_BTNT_xxx
463 @SerializedName("btn_Reverse")
464 public Integer btnReverse;
467 @SerializedName("is_valid")
468 public Boolean isValid;
469 @SerializedName("safety_switch")
470 public Boolean safetySwitch;
471 @SerializedName("obstacle_mode")
472 public String obstaclMode; // SHELLY_OBSTMODE_
473 @SerializedName("obstacle_action")
474 public String obstacleAction; // see SHELLY_STATE_xxx
475 @SerializedName("obstacle_power")
476 public Integer obstaclePower;
477 @SerializedName("obstacle_delay")
478 public Integer obstacleDelay;
479 @SerializedName("safety_mode")
480 public String safetyMode; // see SHELLY_SAFETYM_xxx
481 @SerializedName("safety_action")
482 public String safetyAction; // see SHELLY_STATE_xxx
483 @SerializedName("safety_allowed_on_trigger")
484 public String safetyAllowedOnTrigger; // see SHELLY_ALWD_TRIGGER_xxx
485 @SerializedName("off_power")
486 public Integer offPower;
487 public Boolean positioning;
490 public static class ShellySettingsRgbwLight {
492 public Boolean ison; // true: output is ON
493 public Integer brightness;
495 public Integer transition;
496 @SerializedName("default_state")
497 public String defaultState;
498 @SerializedName("auto_on")
499 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
500 @SerializedName("auto_off")
501 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
502 public Boolean schedule;
503 @SerializedName("btn_type")
504 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
505 @SerializedName("btn_reverse")
506 public Integer btnReverse; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
507 @SerializedName("out_on_url")
508 public String outOnUrl; // output is activated
509 @SerializedName("out_off_url")
510 public String outOffUrl; // output is deactivated
513 public static class ShellyFavPos { // FW 1.9.2+ in roller mode
518 public static class ShellyInputState {
519 public Integer input;
523 @SerializedName("event_cnt")
524 public Integer eventCount;
527 public static class ShellySettingsMeter {
528 @SerializedName("is_valid")
529 public Boolean isValid;
531 public Double[] counters = { 0.0, 0.0, 0.0 };
533 public Long timestamp;
536 public static class ShellySettingsEMeter { // ShellyEM meter
537 @SerializedName("is_valid")
538 public Boolean isValid; // Whether the associated meter is functioning properly
539 public Double power; // Instantaneous power, Watts
540 public Double reactive; // Instantaneous reactive power, Watts
541 public Double voltage; // RMS voltage, Volts
542 public Double total; // Total consumed energy, Wh
543 @SerializedName("total_returned")
544 public Double totalReturned; // Total returned energy, Wh
546 public Double pf; // 3EM
547 public Double current; // 3EM
550 public static class ShellySettingsUpdate {
551 public String status;
552 @SerializedName("has_update")
553 public Boolean hasUpdate;
554 @SerializedName("new_version")
555 public String newVersion;
556 @SerializedName("old_version")
557 public String oldVersion;
558 @SerializedName("beta_version")
559 public String betaVersion;
562 public static class ShellySettingsGlobal {
563 // https://shelly-api-docs.shelly.cloud/#shelly1pm-settings
564 public ShellySettingsDevice device = new ShellySettingsDevice();
565 @SerializedName("wifi_ap")
566 public ShellySettingsWiFiAp wifiAp = new ShellySettingsWiFiAp();
567 @SerializedName("wifi_sta")
568 public ShellySettingsWiFiNetwork wifiSta = new ShellySettingsWiFiNetwork();
569 @SerializedName("wifi_sta1")
570 public ShellySettingsWiFiNetwork wifiSta1 = new ShellySettingsWiFiNetwork();
571 @SerializedName("wifirecovery_reboot_enabled")
572 public Boolean wifiRecoveryReboot; // FW 1.10+
573 @SerializedName("ap_roaming")
574 public ShellyApRoaming apRoaming; // FW 1.10+
576 public ShellySettingsMqtt mqtt = new ShellySettingsMqtt();
577 public ShellySettingsSntp sntp = new ShellySettingsSntp();
578 public ShellySettingsCoiot coiot = new ShellySettingsCoiot();
579 public ShellySettingsLogin login = new ShellySettingsLogin();
580 @SerializedName("pin_code")
581 public String pinCode;
582 @SerializedName("coiot_execute_enable")
583 public Boolean coiotExecuteEnable;
585 public Boolean discoverable; // FW 1.6+
587 @SerializedName("build_info")
588 public ShellySettingsBuildInfo buildInfo = new ShellySettingsBuildInfo();
589 public ShellyStatusCloud cloud = new ShellyStatusCloud();
590 @SerializedName("sleep_mode")
591 public ShellySensorSleepMode sleepMode; // FW 1.6
592 @SerializedName("external_power")
593 public Integer externalPower; // H&T FW 1.6, seems to be the same like charger for the Sense
594 @SerializedName("debug_enable") // FW 1.10+
595 public Boolean debugEnable;
597 public String timezone;
600 public Boolean tzautodetect;
603 public ShellySettingsHwInfo hwinfo;
605 @SerializedName("max_power")
606 public Double maxPower;
607 public Boolean calibrated;
608 public Double voltage; // AC voltage for Shelly 2.5
609 @SerializedName("supply_voltage")
610 public Long supplyVoltage; // Shelly 1PM/1L: 0=110V, 1=220V
612 public @Nullable ArrayList<ShellySettingsRelay> relays;
613 public @Nullable ArrayList<ShellySettingsInput> inputs; // ix3
614 public @Nullable ArrayList<ShellySettingsDimmer> dimmers;
615 public @Nullable ArrayList<ShellySettingsRoller> rollers;
616 public @Nullable ArrayList<ShellySettingsRgbwLight> lights;
617 public @Nullable ArrayList<ShellySettingsEMeter> emeters;
618 public @Nullable ArrayList<ShellyThermnostat> thermostats; // TRV
619 @SerializedName("ext_temperature")
620 public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
621 @SerializedName("ext_humidity")
622 public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
624 @SerializedName("temperature_units")
625 public String temperatureUnits = "C"; // Either'C'or'F'
627 @SerializedName("led_status_disable")
628 public Boolean ledStatusDisable; // PlugS only Disable LED indication for network
630 @SerializedName("led_power_disable")
631 public Boolean ledPowerDisable; // PlugS only Disable LED indication for network
633 @SerializedName("light_sensor")
634 public String lightSensor; // Sense: sensor type
635 @SerializedName("rain_sensor")
636 public Boolean rainSensor; // Flood: true=in rain mode
638 // FW 1.5.7: Door Window
639 @SerializedName("dark_treshold")
640 public Integer darkTreshold; // Illumination definition for "dark" in lux
641 @SerializedName("twilight_treshold")
642 public Integer twiLightTreshold; // Illumination definition for "twilight" in lux
643 @SerializedName("dark_url")
644 public String darkUrl; // URL to report to when luminance <= dark_threshold
645 @SerializedName("twilight_url")
646 public String twiLightUrl; // URL reports when luminance > dark_threshold AND luminance <=
647 @SerializedName("close_url")
648 public String closeUrl; // URL reports when DW contact is closed FW 1.6.5+
649 @SerializedName("vibration_url")
650 public String vibrationUrl; // URL reports when DW detects vibration FW 1.6.5+
653 @SerializedName("set_volume")
654 public Integer volume; // Speaker volume for alarm
655 @SerializedName("alarm_off_url")
656 public String alarmOffUrl; // URL reports when alarm went off
657 @SerializedName("alarm_mild_url")
658 public String alarmMidUrl; // URL reports middle alarm
659 @SerializedName("alarm_heavy_url")
660 public String alarmHeavyfUrl; // URL reports heavy alarm
662 // Roller with FW 1.9.2+
663 @SerializedName("favorites_enabled")
664 public Boolean favoritesEnabled = false;
665 public ArrayList<ShellyFavPos> favorites;
668 public ShellyMotionSettings motion;
669 @SerializedName("tamper_sensitivity")
670 public Integer tamperSensitivity;
671 @SerializedName("dark_threshold")
672 public Integer darkThreshold;
673 @SerializedName("twilight_threshold")
674 public Integer twilightThreshold;
676 @SerializedName("sleep_time") // Shelly Motion
677 public Integer sleepTime;
680 public static class ShellySettingsAttributes {
681 @SerializedName("device_type")
682 public String deviceType; // Device model identifier
683 @SerializedName("device_mac")
684 public String deviceMac; // MAC address of the device in hexadecimal
685 @SerializedName("wifi_ap")
686 public String wifiAp; // WiFi access poInteger configuration, see /settings/ap for details
687 @SerializedName("wifi_sta")
688 public String wifiSta; // WiFi client configuration. See /settings/sta for details
689 public String login; // credentials used for HTTP Basic authentication for the REST interface. If
690 // enabled is true clients must include an Authorization: Basic ... HTTP header with valid
691 // credentials when performing TP requests.
692 public String name; // unique name of the device.
693 public String fw; // current FW version
696 public static class ShellyActionsStats {
697 public Integer skipped;
700 public static class ShellySettingsStatus {
701 public String name; // FW 1.8: Symbolic Device name is configurable
703 @SerializedName("wifi_sta")
704 public ShellySettingsWiFiNetwork wifiSta = new ShellySettingsWiFiNetwork();
705 public ShellyStatusCloud cloud = new ShellyStatusCloud();
706 public ShellyStatusMqtt mqtt = new ShellyStatusMqtt();
709 public Integer serial = -1;
710 @SerializedName("has_update")
711 public Boolean hasUpdate;
713 public Boolean discoverable; // FW 1.6+
714 @SerializedName("cfg_changed_cnt")
715 public Integer cfgChangedCount; // FW 1.8
716 @SerializedName("actions_stats")
717 public ShellyActionsStats astats;
718 public Double voltage; // Shelly 2.5
720 public Integer input; // RGBW2 has no JSON array
721 public ArrayList<ShellySettingsRelay> relays;
722 public ArrayList<ShellyRollerStatus> rollers;
723 public ArrayList<ShellyShortLightStatus> dimmers;
724 public ArrayList<ShellyInputState> inputs;
725 public ArrayList<ShellySettingsMeter> meters;
726 public ArrayList<ShellySettingsEMeter> emeters;
727 @SerializedName("ext_temperature")
728 public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
729 @SerializedName("ext_humidity")
730 public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
732 // Internal device temp
733 public ShellySensorTmp tmp = new ShellySensorTmp(); // Shelly 1PM
734 public Double temperature; // Shelly 2.5
735 public Boolean overtemperature;
737 // Shelly Dimmer only
738 public Boolean loaderror;
739 public Boolean overload;
742 public Boolean calibrated;
743 public ArrayList<ShellyThermnostat> thermostats;
745 public ShellySettingsUpdate update = new ShellySettingsUpdate();
747 @SerializedName("ram_total")
748 public Long ramTotal;
749 @SerializedName("ram_free")
751 @SerializedName("fs_size")
753 @SerializedName("fs_free")
757 @SerializedName("sleep_time") // Shelly Motion
758 public Integer sleepTime;
763 public static class ShellySettingsInput {
764 @SerializedName("btn_type")
765 public String btnType;
768 public static class ShellyControlRelay {
769 // https://shelly-api-docs.shelly.cloud/#shelly1-1pm-settings-relay-0
770 @SerializedName("is_valid")
771 public Boolean isValid;
772 @SerializedName("has_timer")
773 public Boolean hasTimer; // Whether a timer is currently armed for this channel
774 @SerializedName("timer_remaining")
775 public Integer timerRemaining; // FW 1.6+
776 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
778 public String turn; // Accepted values are on and off. This will turn ON/OFF the respective output
779 // channel when request is sent .
780 public Integer timer; // A one-shot flip-back timer in seconds.
783 public static class ShellyShortStatusRelay {
784 public String name; // FW 1.8+: Channel could now have a logical name
785 @SerializedName("is_valid")
786 public Boolean isValid;
787 public Boolean ison; // Whether output channel is on or off
788 @SerializedName("has_timer")
789 public Boolean hasTimer; // Whether a timer is currently armed for this channel
790 @SerializedName("timer_remaining")
791 public Integer timerRemaining;
792 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
793 public Double temperature; // Internal device temperature
794 public Boolean overtemperature; // Device over heated
797 public static class ShellyShortLightStatus {
798 public Boolean ison; // Whether output channel is on or off
799 public String mode; // color or white - valid only for Bulb and RGBW2 even Dimmer returns it also
800 public Integer brightness; // brightness: 0.100%
802 @SerializedName("has_timer")
803 public Boolean hasTimer;
806 public static class ShellyStatusRelay {
807 public String name; // FW 1.8: Symbolic channel name is configurable
809 @SerializedName("wifi_sta")
810 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
811 public ShellySettingsCoiot coiot; // Firmware 1.6+
812 public Integer serial;
813 public String mac; // MAC
814 public ArrayList<ShellyShortStatusRelay> relays; // relay status
815 public ArrayList<ShellySettingsMeter> meters; // current meter value
816 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
818 @SerializedName("ext_temperature")
819 public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
820 @SerializedName("ext_humidity")
821 public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
823 public Double temperature; // device temp acc. on the selected temp unit
824 public ShellySensorTmp tmp;
827 public static class ShellyStatusDimmer {
828 @SerializedName("wifi_sta")
829 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
830 public ArrayList<ShellyShortLightStatus> lights; // relay status
831 public ArrayList<ShellySettingsMeter> meters; // current meter value
833 public ShellySensorTmp tmp;
834 public Boolean overtemperature;
836 public Boolean loaderror;
837 public Boolean overload;
840 public static class ShellyRollerStatus {
841 public String name; // FW 1.8: Symbolic name is configurable
843 @SerializedName("roller_pos")
844 public Integer rollerPos; // number Desired position in percent
845 public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
846 // value of maxtime in /settings/roller/N will be used.
847 public String state; // One of stop, open, close
848 public Double power; // Current power consumption in Watts
849 @SerializedName("is_valid")
850 public Boolean isValid; // If the power meter functions properly
851 @SerializedName("safety_switch")
852 public Boolean safetySwitch; // Whether the safety input is currently triggered
853 public Boolean overtemperature;
854 @SerializedName("stop_reason")
855 public String stopReason; // Last cause for stopping: normal, safety_switch, obstacle
856 @SerializedName("last_direction")
857 public String lastDirection; // Last direction of motion, open or close
858 public Boolean calibrating;
859 public Boolean positioning; // true when calibration was performed
860 @SerializedName("current_pos")
861 public Integer currentPos; // current position 0..100, 100=open
864 public static class ShellyOtaCheckResult {
865 public String status;
868 public static class ShellyApRoaming {
869 public Boolean enabled;
870 public Integer threshold;
873 public static class ShellySensorSleepMode {
874 public Integer period;
879 public class ShellyThermnostat {
880 public class ShellyThermTargetTemp {
881 public Boolean enabled;
886 public class ShellyThermTemp {
889 @SerializedName("is_valid")
890 public Boolean isValid;
894 @SerializedName("target_t")
895 public ShellyThermTargetTemp targetTemp;
896 public Boolean schedule;
897 @SerializedName("schedule_profile")
898 public Integer profile;
899 @SerializedName("schedule_profile_names")
900 public String[] profileNames;
901 public ShellyThermTemp tmp;
902 @SerializedName("boost_minutes")
903 public Integer boostMinutes;
906 public static class ShellySensorTmp {
907 public Double value; // Temperature in configured unites
908 public String units; // 'C' or 'F'
909 public Double tC; // temperature in deg C
910 public Double tF; // temperature in deg F
911 @SerializedName("is_valid")
912 public Boolean isValid; // whether the internal sensor is operating properly
915 public static class ShellyStatusSensor {
916 // https://shelly-api-docs.shelly.cloud/#h-amp-t-settings
917 public static class ShellySensorHum {
918 public Double value; // relative humidity in %
921 public static class ShellySensorBat {
922 public Double value; // estimated remaining battery capacity in %
923 public Double voltage; // battery voltage
926 // Door/Window sensor
927 public static class ShellySensorState {
928 @SerializedName("is_valid")
929 public Boolean isValid; // whether the internal sensor is operating properly
930 public String state; // Shelly Door/Window
933 public Boolean motion;
934 public Boolean vibration;
935 @SerializedName("timestamp")
936 public Long motionTimestamp;
937 @SerializedName("active")
938 public Boolean motionActive;
941 public static class ShellySensorLux {
942 @SerializedName("is_valid")
943 public Boolean isValid; // whether the internal sensor is operating properly
946 public String illumination;
949 public static class ShellySensorAccel {
950 public Integer tilt; // Tilt in °
951 public Integer vibration; // Whether vibration is detected
954 public static class ShellyMotionSettings {
955 public Integer sensitivity;
956 @SerializedName("blind_time_minutes")
957 public Integer blindTimeMinutes;
958 @SerializedName("pulse_count")
959 public Integer pulseCount;
960 @SerializedName("operating_mode")
961 public Integer operatingMode;
962 public Boolean enabled;
965 public static class ShellyExtTemperature {
966 public static class ShellyShortTemp {
967 public Double tC; // temperature in deg C
968 public Double tF; // temperature in deg F
971 // Shelly 1/1PM have up to 3 sensors
972 // for whatever reasons it's not an array, but 3 independent elements
974 public ShellyShortTemp sensor1;
976 public ShellyShortTemp sensor2;
978 public ShellyShortTemp sensor3;
981 public static class ShellyExtHumidity {
982 public static class ShellyShortHum {
983 public Double hum; // Humidity reading of sensor 0, percent
986 // Shelly 1/1PM have up to 3 sensors
987 // for whatever reasons it's not an array, but 3 independent elements
989 public ShellyShortHum sensor1;
992 public static class ShellyADC {
993 public Double voltage;
996 public ShellySensorTmp tmp;
997 public ShellySensorHum hum;
998 public ShellySensorLux lux;
999 public ShellySensorAccel accel;
1000 public ShellySensorBat bat;
1001 @SerializedName("sensor")
1002 public ShellySensorState sensor;
1003 public Boolean smoke; // SHelly Smoke
1004 public Boolean flood; // Shelly Flood: true = flood condition detected
1005 @SerializedName("rain_sensor")
1006 public Boolean rainSensor; // Shelly Flood: true=in rain mode
1008 public Boolean motion; // Shelly Sense: true=motion detected
1009 public Boolean charger; // Shelly Sense, TRV: true=charger connected
1011 @SerializedName("act_reasons")
1012 public List<Object> actReasons; // HT/Smoke/Flood: list of reasons which woke up the device
1014 @SerializedName("sensor_error")
1015 public String sensorError; // 1.5.7: Only displayed in case of error
1017 // FW 1.7: Shelly Gas
1018 @SerializedName("gas_sensor")
1019 public ShellyStatusGasSensor gasSensor;
1020 @SerializedName("concentration")
1021 public ShellyStatusGasConcentration concentration;
1022 public ArrayList<ShellyStatusValve> valves;
1025 @SerializedName("connect_retries")
1026 public Integer connectRetries;
1027 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
1029 // Shelly UNI FW 1.9+
1030 public ArrayList<ShellyADC> adcs;
1033 public Boolean calibrated;
1034 public ArrayList<ShellyThermnostat> thermostats;
1037 public static class ShellySettingsSmoke {
1038 @SerializedName("temperature_units")
1039 public String temperatureUnits; // Either 'C' or 'F'
1040 @SerializedName("temperature_threshold")
1041 public Integer temperatureThreshold; // Temperature delta (in configured degree units) which triggers an update
1042 @SerializedName("sleep_mode_period")
1043 public Integer sleepModePeriod; // Periodic update period in hours, between 1 and 24
1047 // "gas_sensor":{"sensor_state":"normal","self_test_state":"not_completed","alarm_state":"none"},
1048 // "concentration":{"ppm":0,"is_valid":true},
1049 public static class ShellyStatusGasSensor {
1050 @SerializedName("sensor_state")
1051 public String sensorState;
1052 @SerializedName("self_test_state")
1053 public String selfTestState;
1054 @SerializedName("alarm_state")
1055 public String alarmState;
1058 public static class ShellyStatusGasConcentration {
1060 @SerializedName("is_valid")
1061 public Boolean isValid;
1064 public static class ShellyStatusValve {
1065 public String state; // closed/opened/not_connected/failure/closing/opening/checking
1068 public static class ShellySettingsLight {
1069 public Integer red; // red brightness, 0..255, applies in mode="color"
1070 public Integer green; // green brightness, 0..255, applies in mode="color"
1071 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1072 public Integer white; // white brightness, 0..255, applies in mode="color"
1073 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1074 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1075 public Integer brightness; // brightness, 0..100, applies in mode="white"
1076 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1077 // Change, 3: Breath,
1078 // 4: Flash, 5: On/Off Gradual, 6: Red/Green Change
1079 @SerializedName("default_state")
1080 public String defaultState; // one of on, off or last
1081 @SerializedName("auto_on")
1082 public Double autoOn; // see above
1083 @SerializedName("auto_off")
1084 public Double autoOff; // see above
1086 public Integer dcpower; // RGW2:Set to true for 24 V power supply, false for 12 V
1090 public Boolean ison;
1093 public static class ShellySettingsNightMode { // FW1.5.7+
1094 public Integer enabled;
1095 @SerializedName("start_time")
1096 public String startTime;
1097 @SerializedName("end_time")
1098 public String endTime;
1099 public Integer brightness;
1102 public static class ShellyStatusLightChannel {
1103 public Boolean ison;
1104 public Double power;
1105 public Boolean overpower;
1106 @SerializedName("has_timer")
1107 public Boolean hasTimer;
1108 @SerializedName("timer_started")
1109 public Integer timerStarted;
1110 @SerializedName("timer_duration")
1111 public Integer timerDuration;
1112 @SerializedName("timer_remaining")
1113 public Integer timerRemaining;
1115 public Integer red; // red brightness, 0..255, applies in mode="color"
1116 public Integer green; // green brightness, 0..255, applies in mode="color"
1117 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1118 public Integer white; // white brightness, 0..255, applies in mode="color"
1119 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1120 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1121 public Integer brightness; // brightness, 0..100, applies in mode="white"
1122 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1123 // Change, 3: Breath,
1126 public static class ShellyStatusLight {
1127 public Boolean ison; // Whether output channel is on or off
1128 public Integer input;
1130 public ArrayList<ShellyStatusLightChannel> lights;
1131 public ArrayList<ShellySettingsMeter> meters;
1134 public static class ShellySenseKeyCode {
1135 String id; // ID of the stored IR code into Shelly Sense.
1136 String name; // Short description or name of the stored IR code.
1139 public static class ShellySendKeyList {
1140 @SerializedName("key_codes")
1141 public ArrayList<ShellySenseKeyCode> keyCodes;
1145 * Shelly Dimmer returns light[]. However, the structure doesn't match the lights[] of a Bulb/RGBW2.
1146 * The tag lights[] will be replaced with dimmers[] so this could be mapped to a different Gson structure.
1147 * The function requires that it's only called when the device is a dimmer - on get settings and get status
1149 * @param json Input Json as received by the API
1150 * @return Modified Json
1152 public static String fixDimmerJson(String json) {
1153 return !json.contains("\"lights\":[") ? json
1154 : json.replaceFirst(java.util.regex.Pattern.quote("\"lights\":["), "\"dimmers\":[");
1158 * Convert Shelly Button events into OH button states
1160 * @param eventType S/SS/SSS or L
1161 * @return OH button states
1163 public static String mapButtonEvent(String eventType) {
1164 // decode different codings
1166 // S/SS/SSS/L: CoAP for Button and xi3
1167 // shortpush/double_shortpush/triple_shortpush/longpush: REST
1168 switch (eventType) {
1170 return CommonTriggerEvents.RELEASED;
1172 case SHELLY_BTNEVENT_1SHORTPUSH:
1173 case SHELLY_EVENT_SHORTPUSH:
1174 return CommonTriggerEvents.SHORT_PRESSED;
1175 case SHELLY_BTNEVENT_2SHORTPUSH:
1176 case SHELLY_EVENT_DOUBLE_SHORTPUSH:
1177 return CommonTriggerEvents.DOUBLE_PRESSED;
1178 case SHELLY_BTNEVENT_3SHORTPUSH:
1179 case SHELLY_EVENT_TRIPLE_SHORTPUSH:
1180 return "TRIPLE_PRESSED";
1182 case SHELLY_BTNEVENT_LONGPUSH:
1183 case SHELLY_EVENT_LONGPUSH:
1184 return CommonTriggerEvents.LONG_PRESSED;
1185 case SHELLY_BTNEVENT_SHORTLONGPUSH:
1186 case SHELLY_EVENT_SHORT_LONGTPUSH:
1187 return "SHORT_LONG_PRESSED";
1188 case SHELLY_BTNEVENT_LONGSHORTPUSH:
1189 case SHELLY_EVENT_LONG_SHORTPUSH:
1190 return "LONG_SHORT_PRESSED";