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.api;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.openhab.binding.shelly.internal.api.ShellyApiJsonDTO.ShellyStatusSensor.ShellyMotionSettings;
19 import org.openhab.core.thing.CommonTriggerEvents;
21 import com.google.gson.annotations.SerializedName;
24 * The {@link ShellyApiJsonDTO} is used for the JSon/GSon mapping
26 * @author Markus Michels - Initial contribution
28 public class ShellyApiJsonDTO {
29 public static final String SHELLY_NULL_URL = "null";
30 public static final String SHELLY_URL_DEVINFO = "/shelly";
31 public static final String SHELLY_URL_STATUS = "/status";
32 public static final String SHELLY_URL_SETTINGS = "/settings";
33 public static final String SHELLY_URL_SETTINGS_AP = "/settings/ap";
34 public static final String SHELLY_URL_SETTINGS_STA = "/settings/sta";
35 public static final String SHELLY_URL_SETTINGS_LOGIN = "/settings/sta";
36 public static final String SHELLY_URL_SETTINGS_CLOUD = "/settings/cloud";
37 public static final String SHELLY_URL_LIST_IR = "/ir/list";
38 public static final String SHELLY_URL_SEND_IR = "/ir/emit";
39 public static final String SHELLY_URL_RESTART = "/reboot";
41 public static final String SHELLY_URL_SETTINGS_RELAY = "/settings/relay";
42 public static final String SHELLY_URL_STATUS_RELEAY = "/status/relay";
43 public static final String SHELLY_URL_CONTROL_RELEAY = "/relay";
45 public static final String SHELLY_URL_SETTINGS_EMETER = "/settings/emeter";
46 public static final String SHELLY_URL_STATUS_EMETER = "/emeter";
47 public static final String SHELLY_URL_DATA_EMETER = "/emeter/{0}/em_data.csv";
49 public static final String SHELLY_URL_CONTROL_ROLLER = "/roller";
50 public static final String SHELLY_URL_SETTINGS_ROLLER = "/settings/roller";
52 public static final String SHELLY_URL_SETTINGS_LIGHT = "/settings/light";
53 public static final String SHELLY_URL_STATUS_LIGHT = "/light";
54 public static final String SHELLY_URL_CONTROL_LIGHT = "/light";
56 public static final String SHELLY_URL_SETTINGS_DIMMER = "/settings/light";
59 public static final String SHELLY_WAKEUPT_SENSOR = "SENSOR"; // new sensordata
60 public static final String SHELLY_WAKEUPT_PERIODIC = "PERIODIC"; // periodic wakeup
61 public static final String SHELLY_WAKEUPT_BUTTON = "BUTTON"; // button pressed
62 public static final String SHELLY_WAKEUPT_POWERON = "POWERON"; // device powered up
63 public static final String SHELLY_WAKEUPT_UNKNOWN = "UNKNOWN"; // other event
66 // Action URLs according to the device type
68 public static final String SHELLY_EVENTURL_SUFFIX = "_url";
71 public static final String SHELLY_EVENT_BTN_ON = "btn_on";
72 public static final String SHELLY_EVENT_BTN_OFF = "btn_off";
73 public static final String SHELLY_EVENT_OUT_ON = "out_on";
74 public static final String SHELLY_EVENT_OUT_OFF = "out_off";
75 public static final String SHELLY_EVENT_SHORTPUSH = "shortpush";
76 public static final String SHELLY_EVENT_LONGPUSH = "longpush";
78 public static final String SHELLY_EVENT_DOUBLE_SHORTPUSH = "double_shortpush";
79 public static final String SHELLY_EVENT_TRIPLE_SHORTPUSH = "triple_shortpush";
80 public static final String SHELLY_EVENT_SHORT_LONGTPUSH = "shortpush_longpush";
81 public static final String SHELLY_EVENT_LONG_SHORTPUSH = "longpush_shortpush";
84 public static final String SHELLY_EVENT_BTN1_ON = "btn1_on";
85 public static final String SHELLY_EVENT_BTN1_OFF = "btn1_off";
86 public static final String SHELLY_EVENT_BTN2_ON = "btn2_on";
87 public static final String SHELLY_EVENT_BTN2_OFF = "btn2_off";
88 public static final String SHELLY_EVENT_SHORTPUSH1 = "btn1_shortpush";
89 public static final String SHELLY_EVENT_LONGPUSH1 = "btn1_longpush";
90 public static final String SHELLY_EVENT_SHORTPUSH2 = "btn2_shortpush";
91 public static final String SHELLY_EVENT_LONGPUSH2 = "btn2_longpush";
94 public static final String SHELLY_EVENT_ROLLER_OPEN = "roller_open";
95 public static final String SHELLY_EVENT_ROLLER_CLOSE = "roller_close";
96 public static final String SHELLY_EVENT_ROLLER_STOP = "roller_stop";
99 public static final String SHELLY_EVENT_SENSORREPORT = "report";
100 public static final String SHELLY_EVENT_DARK = "dark";
101 public static final String SHELLY_EVENT_TWILIGHT = "twilight";
102 public static final String SHELLY_EVENT_BRIGHT = "bright";
103 public static final String SHELLY_EVENT_FLOOD_DETECTED = "flood_detected";
104 public static final String SHELLY_EVENT_FLOOD_GONE = "flood_gone";
105 public static final String SHELLY_EVENT_VIBRATION = "vibration"; // DW 1.6.5+
106 public static final String SHELLY_EVENT_OPEN = "open"; // DW 1.6.5+
107 public static final String SHELLY_EVENT_CLOSE = "close"; // DW 1.6.5+
108 public static final String SHELLY_EVENT_TEMP_OVER = "temp_over"; // FW 1.7
109 public static final String SHELLY_EVENT_TEMP_UNDER = "temp_under"; // FW 1.7
112 public static final String SHELLY_EVENT_ALARM_MILD = "alarm_mild"; // DW 1.7+
113 public static final String SHELLY_EVENT_ALARM_HEAVY = "alarm_heavy"; // DW 1.7+
114 public static final String SHELLY_EVENT_ALARM_OFF = "alarm_off"; // DW 1.7+
119 public static final String SHELLY_BTNT_MOMENTARY = "momentary";
120 public static final String SHELLY_BTNT_MOM_ON_RELEASE = "momentary_on_release";
121 public static final String SHELLY_BTNT_ONE_BUTTON = "one_button";
122 public static final String SHELLY_BTNT_TWO_BUTTON = "dual_button";
123 public static final String SHELLY_BTNT_TOGGLE = "toggle";
124 public static final String SHELLY_BTNT_EDGE = "edge";
125 public static final String SHELLY_BTNT_DETACHED = "detached";
127 public static final String SHELLY_STATE_LAST = "last";
128 public static final String SHELLY_STATE_STOP = "stop";
130 public static final String SHELLY_INP_MODE_OPENCLOSE = "openclose";
131 public static final String SHELLY_OBSTMODE_DISABLED = "disabled";
132 public static final String SHELLY_SAFETYM_WHILEOPENING = "while_opening";
134 public static final String SHELLY_ALWD_TRIGGER_NONE = "none";
135 public static final String SHELLY_ALWD_ROLLER_TURN_OPEN = "open";
136 public static final String SHELLY_ALWD_ROLLER_TURN_CLOSE = "close";
137 public static final String SHELLY_ALWD_ROLLER_TURN_STOP = "stop";
140 public static final String SHELLY_APIERR_UNAUTHORIZED = "Unauthorized";
141 public static final String SHELLY_APIERR_TIMEOUT = "Timeout";
142 public static final String SHELLY_APIERR_NOT_CALIBRATED = "Not calibrated!";
144 // API device types / properties
145 public static final String SHELLY_CLASS_RELAY = "relay"; // Relay: relay mode
146 public static final String SHELLY_CLASS_ROLLER = "roller"; // Relay: roller mode
147 public static final String SHELLY_CLASS_LIGHT = "light"; // Bulb: color mode
148 public static final String SHELLY_CLASS_EMETER = "emeter"; // EM/EM3: emeter
150 public static final String SHELLY_API_ON = "on";
151 public static final String SHELLY_API_OFF = "off";
152 public static final String SHELLY_API_TRUE = "true";
153 public static final String SHELLY_API_FALSE = "false";
155 public static final String SHELLY_API_MODE = "mode";
156 public static final String SHELLY_MODE_RELAY = "relay"; // Relay: relay mode
157 public static final String SHELLY_MODE_ROLLER = "roller"; // Relay: roller mode
158 public static final String SHELLY_MODE_COLOR = "color"; // Bulb/RGBW2: color mode
159 public static final String SHELLY_MODE_WHITE = "white"; // Bulb/RGBW2: white mode
161 public static final String SHELLY_LED_STATUS_DISABLE = "led_status_disable";
162 public static final String SHELLY_LED_POWER_DISABLE = "led_power_disable";
164 public static final String SHELLY_API_STOPR_NORMAL = "normal";
165 public static final String SHELLY_API_STOPR_SAFETYSW = "safety_switch";
166 public static final String SHELLY_API_STOPR_OBSTACLE = "obstacle";
167 public static final String SHELLY_API_STOPR_OVERPOWER = "overpower";
169 public static final String SHELLY_TIMER_AUTOON = "auto_on";
170 public static final String SHELLY_TIMER_AUTOOFF = "auto_off";
171 public static final String SHELLY_TIMER_ACTIVE = "has_timer";
173 public static final String SHELLY_LIGHT_TURN = "turn";
174 public static final String SHELLY_LIGHT_DEFSTATE = "def_state";
175 public static final String SHELLY_LIGHTTIMER = "timer";
177 public static final String SHELLY_COLOR_RED = "red";
178 public static final String SHELLY_COLOR_BLUE = "blue";
179 public static final String SHELLY_COLOR_GREEN = "green";
180 public static final String SHELLY_COLOR_YELLOW = "yellow";
181 public static final String SHELLY_COLOR_WHITE = "white";
182 public static final String SHELLY_COLOR_GAIN = "gain";
183 public static final String SHELLY_COLOR_BRIGHTNESS = "brightness";
184 public static final String SHELLY_COLOR_TEMP = "temp";
185 public static final String SHELLY_COLOR_EFFECT = "effect";
187 public static final int SHELLY_MIN_ROLLER_POS = 0;
188 public static final int SHELLY_MAX_ROLLER_POS = 100;
189 public static final int SHELLY_MIN_BRIGHTNESS = 0;
190 public static final int SHELLY_MAX_BRIGHTNESS = 100;
191 public static final int SHELLY_MIN_GAIN = 0;
192 public static final int SHELLY_MAX_GAIN = 100;
193 public static final int SHELLY_MIN_COLOR = 0;
194 public static final int SHELLY_MAX_COLOR = 255;
195 public static final int SHELLY_DIM_STEPSIZE = 10;
197 // color temperature: 3000 = warm, 4750 = white, 6565 = cold; gain: 0..100
198 public static final int MIN_COLOR_TEMP_BULB = 3000;
199 public static final int MAX_COLOR_TEMP_BULB = 6500;
200 public static final int MIN_COLOR_TEMP_DUO = 2700;
201 public static final int MAX_COLOR_TEMP_DUO = 6500;
202 public static final int COLOR_TEMP_RANGE_BULB = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
203 public static final int COLOR_TEMP_RANGE_DUO = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
204 public static final double MIN_BRIGHTNESS = 0.0;
205 public static final double MAX_BRIGHTNESS = 100.0;
206 public static final double SATURATION_FACTOR = 2.55;
207 public static final double GAIN_FACTOR = SHELLY_MAX_GAIN / 100;
208 public static final double BRIGHTNESS_FACTOR = SHELLY_MAX_BRIGHTNESS / 100;
211 public static final String SHELLY_API_ILLUM_DARK = "dark";
212 public static final String SHELLY_API_ILLUM_TWILIGHT = "twilight";
213 public static final String SHELLY_API_ILLUM_BRIGHT = "bright";
214 public static final String SHELLY_API_DWSTATE_OPEN = "open";
215 public static final String SHELLY_API_DWSTATE_CLOSE = "close";
218 public static final String SHELLY_IR_CODET_STORED = "stored";
219 public static final String SHELLY_IR_CODET_PRONTO = "pronto";
220 public static final String SHELLY_IR_CODET_PRONTO_HEX = "pronto_hex";
223 public static final int SHELLY_MIN_EFFECT = 0;
224 public static final int SHELLY_MAX_EFFECT = 6;
227 public static final String SHELLY_BTNEVENT_1SHORTPUSH = "S";
228 public static final String SHELLY_BTNEVENT_2SHORTPUSH = "SS";
229 public static final String SHELLY_BTNEVENT_3SHORTPUSH = "SSS";
230 public static final String SHELLY_BTNEVENT_LONGPUSH = "L";
231 public static final String SHELLY_BTNEVENT_SHORTLONGPUSH = "SL";
232 public static final String SHELLY_BTNEVENT_LONGSHORTPUSH = "LS";
234 public static final String SHELLY_TEMP_CELSIUS = "C";
235 public static final String SHELLY_TEMP_FAHRENHEIT = "F";
238 public static final int SHELLY_MOTION_SLEEPTIME_OFFSET = 3; // we need to substract and offset
241 public static final int SHELLY_TRV_MIN_TEMP = 5; // < 5: means: lowest (valve fully closed)
242 public static final int SHELLY_TRV_MAX_TEMP = 30; // > 30: means: highest (valve fully open)
244 public static final String SHELLY_TRV_MODE_MANUAL = "manual";
245 public static final String SHELLY_TRV_MODE_AUTO = "automatic";
247 // CoIoT Multicast setting
248 public static final String SHELLY_COIOT_MCAST = "mcast";
250 public static class ShellySettingsDevice {
253 public String hostname;
257 @SerializedName("coiot") // Shelly Motion Multicast Endpoint
259 public Integer longid;
261 @SerializedName("num_outputs")
262 public Integer numOutputs;
263 @SerializedName("num_meters")
264 public Integer numMeters;
265 @SerializedName("num_emeters")
266 public Integer numEMeters;
267 @SerializedName("num_rollers")
268 public Integer numRollers;
271 public static class ShellySettingsWiFiAp {
272 public Boolean enabled;
277 public static class ShellySettingsWiFiNetwork {
278 public Boolean enabled;
282 @SerializedName("ipv4_method")
283 public String ipv4Method;
290 public static class ShellySettingsMqtt {
291 public Boolean enable;
292 public String server;
294 @SerializedName("reconnect_timeout_max")
295 public Double reconnectTimeoutMax;
296 @SerializedName("reconnect_timeout_min")
297 public Double reconnectTimeoutMin;
298 @SerializedName("clean_session")
299 public Boolean cleanSession;
300 @SerializedName("keep_alive")
301 public Integer keepAlive;
302 @SerializedName("will_topic")
303 public String willTopic;
304 @SerializedName("will_message")
305 public String willMessage;
306 @SerializedName("max_qos")
307 public Integer maxQOS;
308 public Boolean retain;
309 @SerializedName("update_period")
310 public Integer updatePeriod;
313 public static class ShellySettingsCoiot { // FW 1.6+
314 @SerializedName("update_period")
315 public Integer updatePeriod;
316 public Boolean enabled; // Motion 1.0.7: Coap can be disabled
317 public String peer; // if set the device uses singlecast CoAP, mcast=set back to Multicast
320 public static class ShellyStatusMqtt {
321 public Boolean connected;
324 public static class ShellySettingsSntp {
325 public String server;
326 public Boolean enabled;
329 public static class ShellySettingsLogin {
330 public Boolean enabled;
331 public Boolean unprotected;
332 public String username;
333 public String password;
336 public static class ShellySettingsBuildInfo {
337 @SerializedName("build_id")
338 public String buildId;
339 @SerializedName("build_timestamp")
340 public String buildTimestamp;
341 @SerializedName("build_version")
342 public String buildVersion;
345 public static class ShellyStatusCloud {
346 public Boolean enabled;
347 public Boolean connected;
350 public static class ShellySettingsHwInfo {
351 @SerializedName("hw_revision")
352 public String hwRevision;
353 @SerializedName("batch_id")
354 public Integer batchId;
357 public static class ShellySettingsScheduleRules {
360 public static class ShellySettingsRelay {
363 public Boolean overpower;
364 @SerializedName("default_state")
365 public String defaultState; // Accepted values: off, on, last, switch
366 @SerializedName("btn_type")
367 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
368 @SerializedName("btn1_type") // Shelly 1L
369 public String btnType1;
370 @SerializedName("btn2_type") // Shelly 1L
371 public String btnType2;
372 @SerializedName("has_timer")
373 public Boolean hasTimer; // Whether a timer is currently armed for this channel
374 @SerializedName("auto_on")
375 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
376 @SerializedName("auto_off")
377 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
378 @SerializedName("btn_on_url")
379 public String btnOnUrl; // input is activated
380 @SerializedName("btnOffUrl")
381 public String btnOffUrl; // input is deactivated
382 @SerializedName("out_on_url")
383 public String outOnUrl; // output is activated
384 @SerializedName("out_off_url")
385 public String outOffUrl; // output is deactivated
386 @SerializedName("roller_open_url")
387 public String rollerOpenUrl; // to access when roller reaches open position
388 @SerializedName("roller_close_url")
389 public String rollerCloseUrl; // to access when roller reaches close position
390 @SerializedName("roller_stop_url")
391 public String rollerStopUrl; // to access when roller stopped
392 @SerializedName("longpush_url")
393 public String pushLongUrl; // to access when roller stopped
394 @SerializedName("shortpush_url")
395 public String pushShortUrl; // to access when roller stopped
398 public static class ShellySettingsDimmer {
399 public String name; // unique name of the device
400 public Boolean ison; // true: output is ON
401 @SerializedName("default_state")
402 public String defaultState; // Accepted values: off, on, last, switch
403 @SerializedName("auto_on")
404 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
405 @SerializedName("auto_off")
406 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
407 @SerializedName("btn1_on_url")
408 public String btn1OnUrl; // URL to access when SW input is activated
409 @SerializedName("btn1_off_url")
410 public String btn1OffUrl; // URL to access when SW input is deactivated
411 @SerializedName("btn2_on_url")
412 public String btn2OnUrl; // URL to access when SW input is activated
413 @SerializedName("btn2_off_url")
414 public String btn2OoffUrl; // URL to access when SW input is deactivated
415 @SerializedName("out_on_url")
416 public String outOnUrl; // URL to access when output is activated
417 @SerializedName("out_off_url")
418 public String outOffUrl; // URL to access when output is deactivated
419 @SerializedName("longpush_url")
420 public String pushLongUrl; // long push button event
421 @SerializedName("shortpush_url")
422 public String pushShortUrl; // short push button event
423 @SerializedName("btn_type")
424 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
425 @SerializedName("btn1_type")
426 public String btnType1; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
427 @SerializedName("btn2_type")
428 public String btnType2; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
429 @SerializedName("swap_inputs")
430 public Integer swapInputs; // 0=no
433 public static class ShellySettingsRoller {
434 public Double maxtime;
435 @SerializedName("maxtime_open")
436 public Double maxtimeOpen;
437 @SerializedName("maxtime_close")
438 public Double maxtimeClose;
439 @SerializedName("default_state")
440 public String defaultState; // see SHELLY_STATE_xxx
442 @SerializedName("swap_inputs")
443 public Boolean swapInputs;
444 @SerializedName("input_mode")
445 public String inputMode; // see SHELLY_INP_MODE_OPENCLOSE
446 @SerializedName("button_type")
447 public String buttonType; // // see SHELLY_BTNT_xxx
448 @SerializedName("btn_Reverse")
449 public Integer btnReverse;
452 @SerializedName("is_valid")
453 public Boolean isValid;
454 @SerializedName("safety_switch")
455 public Boolean safetySwitch;
456 @SerializedName("obstacle_mode")
457 public String obstaclMode; // SHELLY_OBSTMODE_
458 @SerializedName("obstacle_action")
459 public String obstacleAction; // see SHELLY_STATE_xxx
460 @SerializedName("obstacle_power")
461 public Integer obstaclePower;
462 @SerializedName("obstacle_delay")
463 public Integer obstacleDelay;
464 @SerializedName("safety_mode")
465 public String safetyMode; // see SHELLY_SAFETYM_xxx
466 @SerializedName("safety_action")
467 public String safetyAction; // see SHELLY_STATE_xxx
468 @SerializedName("safety_allowed_on_trigger")
469 public String safetyAllowedOnTrigger; // see SHELLY_ALWD_TRIGGER_xxx
470 @SerializedName("off_power")
471 public Integer offPower;
472 public Boolean positioning;
475 public static class ShellySettingsRgbwLight {
477 public Boolean ison; // true: output is ON
478 public Integer brightness;
479 public Integer transition;
480 @SerializedName("default_state")
481 public String defaultState;
482 @SerializedName("auto_on")
483 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
484 @SerializedName("auto_off")
485 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
486 public Boolean schedule;
487 @SerializedName("btn_type")
488 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
489 @SerializedName("btn_reverse")
490 public Integer btnReverse; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
491 @SerializedName("out_on_url")
492 public String outOnUrl; // output is activated
493 @SerializedName("out_off_url")
494 public String outOffUrl; // output is deactivated
497 public static class ShellyFavPos { // FW 1.9.2+ in roller mode
502 public static class ShellyInputState {
503 public Integer input;
507 @SerializedName("event_cnt")
508 public Integer eventCount;
511 public static class ShellySettingsMeter {
512 @SerializedName("is_valid")
513 public Boolean isValid;
515 public Double[] counters = { 0.0, 0.0, 0.0 };
517 public Long timestamp;
520 public static class ShellySettingsEMeter { // ShellyEM meter
521 @SerializedName("is_valid")
522 public Boolean isValid; // Whether the associated meter is functioning properly
523 public Double power; // Instantaneous power, Watts
524 public Double reactive; // Instantaneous reactive power, Watts
525 public Double voltage; // RMS voltage, Volts
526 public Double total; // Total consumed energy, Wh
527 @SerializedName("total_returned")
528 public Double totalReturned; // Total returned energy, Wh
530 public Double pf; // 3EM
531 public Double current; // 3EM
534 public static class ShellySettingsUpdate {
535 public String status;
536 @SerializedName("has_update")
537 public Boolean hasUpdate;
538 @SerializedName("new_version")
539 public String newVersion;
540 @SerializedName("old_version")
541 public String oldVersion;
542 @SerializedName("beta_version")
543 public String betaVersion;
546 public static class ShellySettingsGlobal {
547 // https://shelly-api-docs.shelly.cloud/#shelly1pm-settings
548 public ShellySettingsDevice device;
549 @SerializedName("wifi_ap")
550 public ShellySettingsWiFiAp wifiAp;
551 @SerializedName("wifi_sta")
552 public ShellySettingsWiFiNetwork wifiSta;
553 @SerializedName("wifi_sta1")
554 public ShellySettingsWiFiNetwork wifiSta1;
555 @SerializedName("wifirecovery_reboot_enabled")
556 public Boolean wifiRecoveryReboot; // FW 1.10+
557 @SerializedName("ap_roaming")
558 public ShellyApRoaming apRoaming; // FW 1.10+
560 public ShellySettingsMqtt mqtt; // not used for now
561 public ShellySettingsSntp sntp; // not used for now
562 public ShellySettingsCoiot coiot; // Firmware 1.6+
563 public ShellySettingsLogin login;
564 @SerializedName("pin_code")
565 public String pinCode;
566 @SerializedName("coiot_execute_enable")
567 public Boolean coiotExecuteEnable;
569 public Boolean discoverable; // FW 1.6+
571 @SerializedName("build_info")
572 public ShellySettingsBuildInfo buildInfo;
573 public ShellyStatusCloud cloud;
574 @SerializedName("sleep_mode")
575 public ShellySensorSleepMode sleepMode; // FW 1.6
576 @SerializedName("external_power")
577 public Integer externalPower; // H&T FW 1.6, seems to be the same like charger for the Sense
578 @SerializedName("debug_enable") // FW 1.10+
579 public Boolean debugEnable;
581 public String timezone;
584 public Boolean tzautodetect;
587 public ShellySettingsHwInfo hwinfo;
589 @SerializedName("max_power")
590 public Double maxPower;
591 public Boolean calibrated;
593 public ArrayList<ShellySettingsRelay> relays;
594 public Double voltage; // AC voltage for Shelly 2.5
595 @SerializedName("supply_voltage")
596 public Long supplyVoltage; // Shelly 1PM/1L: 0=110V, 1=220V
597 public ArrayList<ShellySettingsDimmer> dimmers;
598 public ArrayList<ShellySettingsRgbwLight> lights;
599 public ArrayList<ShellySettingsEMeter> emeters;
600 public ArrayList<ShellySettingsInput> inputs; // ix3
602 public ArrayList<ShellyThermnostat> thermostats; // TRV
604 @SerializedName("temperature_units")
605 public String temperatureUnits; // Either'C'or'F'
607 @SerializedName("led_status_disable")
608 public Boolean ledStatusDisable; // PlugS only Disable LED indication for network
610 @SerializedName("led_power_disable")
611 public Boolean ledPowerDisable; // PlugS only Disable LED indication for network
613 @SerializedName("light_sensor")
614 public String lightSensor; // Sense: sensor type
615 @SerializedName("rain_sensor")
616 public Boolean rainSensor; // Flood: true=in rain mode
618 // FW 1.5.7: Door Window
619 @SerializedName("dark_treshold")
620 public Integer darkTreshold; // Illumination definition for "dark" in lux
621 @SerializedName("twilight_treshold")
622 public Integer twiLightTreshold; // Illumination definition for "twilight" in lux
623 @SerializedName("dark_url")
624 public String darkUrl; // URL to report to when luminance <= dark_threshold
625 @SerializedName("twilight_url")
626 public String twiLightUrl; // URL reports when luminance > dark_threshold AND luminance <=
627 @SerializedName("close_url")
628 public String closeUrl; // URL reports when DW contact is closed FW 1.6.5+
629 @SerializedName("vibration_url")
630 public String vibrationUrl; // URL reports when DW detects vibration FW 1.6.5+
633 @SerializedName("set_volume")
634 public Integer volume; // Speaker volume for alarm
635 @SerializedName("alarm_off_url")
636 public String alarmOffUrl; // URL reports when alarm went off
637 @SerializedName("alarm_mild_url")
638 public String alarmMidUrl; // URL reports middle alarm
639 @SerializedName("alarm_heavy_url")
640 public String alarmHeavyfUrl; // URL reports heavy alarm
642 // Roller with FW 1.9.2+
643 @SerializedName("favorites_enabled")
644 public Boolean favoritesEnabled;
645 public ArrayList<ShellyFavPos> favorites;
648 public ShellyMotionSettings motion;
649 @SerializedName("tamper_sensitivity")
650 public Integer tamperSensitivity;
651 @SerializedName("dark_threshold")
652 public Integer darkThreshold;
653 @SerializedName("twilight_threshold")
654 public Integer twilightThreshold;
656 @SerializedName("sleep_time") // Shelly Motion
657 public Integer sleepTime;
660 public static class ShellySettingsAttributes {
661 @SerializedName("device_type")
662 public String deviceType; // Device model identifier
663 @SerializedName("device_mac")
664 public String deviceMac; // MAC address of the device in hexadecimal
665 @SerializedName("wifi_ap")
666 public String wifiAp; // WiFi access poInteger configuration, see /settings/ap for details
667 @SerializedName("wifi_sta")
668 public String wifiSta; // WiFi client configuration. See /settings/sta for details
669 public String login; // credentials used for HTTP Basic authentication for the REST interface. If
670 // enabled is true clients must include an Authorization: Basic ... HTTP header with valid
671 // credentials when performing TP requests.
672 public String name; // unique name of the device.
673 public String fw; // current FW version
676 public static class ShellyActionsStats {
677 public Integer skipped;
680 public static class ShellySettingsStatus {
681 public String name; // FW 1.8: Symbolic Device name is configurable
683 @SerializedName("wifi_sta")
684 public ShellySettingsWiFiNetwork wifiSta; // WiFi client configuration. See /settings/sta for details
685 public ShellyStatusCloud cloud;
686 public ShellyStatusMqtt mqtt;
689 public Integer serial;
690 @SerializedName("has_update")
691 public Boolean hasUpdate;
693 public Boolean discoverable; // FW 1.6+
694 @SerializedName("cfg_changed_cnt")
695 public Integer cfgChangedCount; // FW 1.8
696 @SerializedName("actions_stats")
697 public ShellyActionsStats astats;
699 public ArrayList<ShellySettingsRelay> relays;
700 public Double voltage; // Shelly 2.5
702 public ArrayList<ShellySettingsRoller> rollers;
703 public Integer input; // RGBW2 has no JSON array
704 public ArrayList<ShellyInputState> inputs;
705 public ArrayList<ShellySettingsLight> lights;
706 public ArrayList<ShellyShortLightStatus> dimmers;
707 public ArrayList<ShellySettingsMeter> meters;
708 public ArrayList<ShellySettingsEMeter> emeters;
710 // Internal device temp
711 public ShellyStatusSensor.ShellySensorTmp tmp; // Shelly 1PM
712 public Double temperature; // Shelly 2.5
713 public Boolean overtemperature;
715 // Shelly Dimmer only
716 public Boolean loaderror;
717 public Boolean overload;
720 public Boolean calibrated;
721 public ArrayList<ShellyThermnostat> thermostats;
723 public ShellySettingsUpdate update;
724 @SerializedName("ram_total")
725 public Long ramTotal;
726 @SerializedName("ram_free")
728 @SerializedName("fs_size")
730 @SerializedName("fs_free")
734 @SerializedName("sleep_time") // Shelly Motion
735 public Integer sleepTime;
740 public static class ShellySettingsInput {
741 @SerializedName("btn_type")
742 public String btnType;
745 public static class ShellyControlRelay {
746 // https://shelly-api-docs.shelly.cloud/#shelly1-1pm-settings-relay-0
747 @SerializedName("is_valid")
748 public Boolean isValid;
749 @SerializedName("has_timer")
750 public Boolean hasTimer; // Whether a timer is currently armed for this channel
751 @SerializedName("timer_remaining")
752 public Integer timerRemaining; // FW 1.6+
753 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
755 public String turn; // Accepted values are on and off. This will turn ON/OFF the respective output
756 // channel when request is sent .
757 public Integer timer; // A one-shot flip-back timer in seconds.
760 public static class ShellyShortStatusRelay {
761 public String name; // FW 1.8+: Channel could now have a logical name
762 @SerializedName("is_valid")
763 public Boolean isValid;
764 public Boolean ison; // Whether output channel is on or off
765 @SerializedName("has_timer")
766 public Boolean hasTimer; // Whether a timer is currently armed for this channel
767 @SerializedName("timer_remaining")
768 public Integer timerRemaining;
769 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
770 public Double temperature; // Internal device temperature
771 public Boolean overtemperature; // Device over heated
774 public static class ShellyShortLightStatus {
775 public Boolean ison; // Whether output channel is on or off
776 public String mode; // color or white - valid only for Bulb and RGBW2 even Dimmer returns it also
777 public Integer brightness; // brightness: 0.100%
779 @SerializedName("has_timer")
780 public Boolean hasTimer;
783 public static class ShellyStatusRelay {
784 public String name; // FW 1.8: Symbolic channel name is configurable
786 @SerializedName("wifi_sta")
787 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
788 public ShellySettingsCoiot coiot; // Firmware 1.6+
789 public Integer serial;
790 public String mac; // MAC
791 public ArrayList<ShellyShortStatusRelay> relays; // relay status
792 public ArrayList<ShellySettingsMeter> meters; // current meter value
793 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
795 @SerializedName("ext_temperature")
796 public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
797 @SerializedName("ext_humidity")
798 public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
800 public Double temperature; // device temp acc. on the selected temp unit
801 public ShellyStatusSensor.ShellySensorTmp tmp;
804 public static class ShellyStatusDimmer {
805 @SerializedName("wifi_sta")
806 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
807 public ArrayList<ShellyShortLightStatus> lights; // relay status
808 public ArrayList<ShellySettingsMeter> meters; // current meter value
810 public ShellyStatusSensor.ShellySensorTmp tmp;
811 public Boolean overtemperature;
813 public Boolean loaderror;
814 public Boolean overload;
817 public static class ShellyControlRoller {
818 public String name; // FW 1.8: Symbolic name is configurable
820 @SerializedName("roller_pos")
821 public Integer rollerPos; // number Desired position in percent
822 public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
823 // value of maxtime in /settings/roller/N will be used.
824 public String state; // One of stop, open, close
825 public Double power; // Current power consumption in Watts
826 @SerializedName("is_valid")
827 public Boolean isValid; // If the power meter functions properly
828 @SerializedName("safety_switch")
829 public Boolean safetySwitch; // Whether the safety input is currently triggered
830 public Boolean overtemperature;
831 @SerializedName("stop_reason")
832 public String stopReason; // Last cause for stopping: normal, safety_switch, obstacle
833 @SerializedName("last_direction")
834 public String lastDirection; // Last direction of motion, open or close
835 public Boolean calibrating;
836 public Boolean positioning; // true when calibration was performed
837 @SerializedName("current_pos")
838 public Integer currentPos; // current position 0..100, 100=open
841 public class ShellyOtaCheckResult {
842 public String status;
845 public class ShellyApRoaming {
846 public Boolean enabled;
847 public Integer threshold;
850 public class ShellySensorSleepMode {
851 public Integer period;
856 public class ShellyThermnostat {
857 public class ShellyThermTargetTemp {
858 public Boolean enabled;
863 public class ShellyThermTemp {
866 @SerializedName("is_valid")
867 public Boolean isValid;
871 @SerializedName("target_t")
872 public ShellyThermTargetTemp targetTemp;
873 public Boolean schedule;
874 @SerializedName("schedule_profile")
875 public Integer profile;
876 @SerializedName("schedule_profile_names")
877 public String[] profileNames;
878 public ShellyThermTemp tmp;
879 @SerializedName("boost_minutes")
880 public Integer boostMinutes;
883 public static class ShellyStatusSensor {
884 // https://shelly-api-docs.shelly.cloud/#h-amp-t-settings
885 public static class ShellySensorTmp {
886 public Double value; // Temperature in configured unites
887 public String units; // 'C' or 'F'
888 public Double tC; // temperature in deg C
889 public Double tF; // temperature in deg F
890 @SerializedName("is_valid")
891 public Boolean isValid; // whether the internal sensor is operating properly
894 public static class ShellySensorHum {
895 public Double value; // relative humidity in %
898 public static class ShellySensorBat {
899 public Double value; // estimated remaining battery capacity in %
900 public Double voltage; // battery voltage
903 // Door/Window sensor
904 public static class ShellySensorState {
905 @SerializedName("is_valid")
906 public Boolean isValid; // whether the internal sensor is operating properly
907 public String state; // Shelly Door/Window
910 public Boolean motion;
911 public Boolean vibration;
912 @SerializedName("timestamp")
913 public Long motionTimestamp;
914 @SerializedName("active")
915 public Boolean motionActive;
918 public static class ShellySensorLux {
919 @SerializedName("is_valid")
920 public Boolean isValid; // whether the internal sensor is operating properly
923 public String illumination;
926 public static class ShellySensorAccel {
927 public Integer tilt; // Tilt in °
928 public Integer vibration; // Whether vibration is detected
931 public static class ShellyMotionSettings {
932 public Integer sensitivity;
933 @SerializedName("blind_time_minutes")
934 public Integer blindTimeMinutes;
935 @SerializedName("pulse_count")
936 public Integer pulseCount;
937 @SerializedName("operating_mode")
938 public Integer operatingMode;
939 public Boolean enabled;
942 public static class ShellyExtTemperature {
943 public static class ShellyShortTemp {
944 public Double tC; // temperature in deg C
945 public Double tF; // temperature in deg F
948 // Shelly 1/1PM have up to 3 sensors
949 // for whatever reasons it's not an array, but 3 independent elements
951 public ShellyShortTemp sensor1;
953 public ShellyShortTemp sensor2;
955 public ShellyShortTemp sensor3;
958 public static class ShellyExtHumidity {
959 public static class ShellyShortHum {
960 public Double hum; // Humidity reading of sensor 0, percent
963 // Shelly 1/1PM have up to 3 sensors
964 // for whatever reasons it's not an array, but 3 independent elements
966 public ShellyShortHum sensor1;
969 public static class ShellyADC {
970 public Double voltage;
973 public ShellySensorTmp tmp;
974 public ShellySensorHum hum;
975 public ShellySensorLux lux;
976 public ShellySensorAccel accel;
977 public ShellySensorBat bat;
978 @SerializedName("sensor")
979 public ShellySensorState sensor;
980 public Boolean smoke; // SHelly Smoke
981 public Boolean flood; // Shelly Flood: true = flood condition detected
982 @SerializedName("rain_sensor")
983 public Boolean rainSensor; // Shelly Flood: true=in rain mode
985 public Boolean motion; // Shelly Sense: true=motion detected
986 public Boolean charger; // Shelly Sense, TRV: true=charger connected
988 @SerializedName("act_reasons")
989 public List<Object> actReasons; // HT/Smoke/Flood: list of reasons which woke up the device
991 @SerializedName("sensor_error")
992 public String sensorError; // 1.5.7: Only displayed in case of error
994 // FW 1.7: Shelly Gas
995 @SerializedName("gas_sensor")
996 public ShellyStatusGasSensor gasSensor;
997 @SerializedName("concentration")
998 public ShellyStatusGasConcentration concentration;
999 public ArrayList<ShellyStatusValve> valves;
1002 @SerializedName("connect_retries")
1003 public Integer connectRetries;
1004 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
1006 // Shelly UNI FW 1.9+
1007 public ArrayList<ShellyADC> adcs;
1010 public Boolean calibrated;
1011 public ArrayList<ShellyThermnostat> thermostats;
1014 public static class ShellySettingsSmoke {
1015 @SerializedName("temperature_units")
1016 public String temperatureUnits; // Either 'C' or 'F'
1017 @SerializedName("temperature_threshold")
1018 public Integer temperatureThreshold; // Temperature delta (in configured degree units) which triggers an update
1019 @SerializedName("sleep_mode_period")
1020 public Integer sleepModePeriod; // Periodic update period in hours, between 1 and 24
1024 // "gas_sensor":{"sensor_state":"normal","self_test_state":"not_completed","alarm_state":"none"},
1025 // "concentration":{"ppm":0,"is_valid":true},
1026 public static class ShellyStatusGasSensor {
1027 @SerializedName("sensor_state")
1028 public String sensorState;
1029 @SerializedName("self_test_state")
1030 public String selfTestState;
1031 @SerializedName("alarm_state")
1032 public String alarmState;
1035 public static class ShellyStatusGasConcentration {
1037 @SerializedName("is_valid")
1038 public Boolean isValid;
1041 public static class ShellyStatusValve {
1042 public String state; // closed/opened/not_connected/failure/closing/opening/checking
1045 public static class ShellySettingsLight {
1046 public Integer red; // red brightness, 0..255, applies in mode="color"
1047 public Integer green; // green brightness, 0..255, applies in mode="color"
1048 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1049 public Integer white; // white brightness, 0..255, applies in mode="color"
1050 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1051 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1052 public Integer brightness; // brightness, 0..100, applies in mode="white"
1053 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1054 // Change, 3: Breath,
1055 // 4: Flash, 5: On/Off Gradual, 6: Red/Green Change
1056 @SerializedName("default_state")
1057 public String defaultState; // one of on, off or last
1058 @SerializedName("auto_on")
1059 public Double autoOn; // see above
1060 @SerializedName("auto_off")
1061 public Double autoOff; // see above
1063 public Integer dcpower; // RGW2:Set to true for 24 V power supply, false for 12 V
1067 public Boolean ison;
1070 public static class ShellySettingsNightMode { // FW1.5.7+
1071 public Integer enabled;
1072 @SerializedName("start_time")
1073 public String startTime;
1074 @SerializedName("end_time")
1075 public String endTime;
1076 public Integer brightness;
1079 public static class ShellyStatusLightChannel {
1080 public Boolean ison;
1081 public Double power;
1082 public Boolean overpower;
1083 @SerializedName("has_timer")
1084 public Boolean hasTimer;
1085 @SerializedName("timer_started")
1086 public Integer timerStarted;
1087 @SerializedName("timer_duration")
1088 public Integer timerDuration;
1089 @SerializedName("timer_remaining")
1090 public Integer timerRemaining;
1092 public Integer red; // red brightness, 0..255, applies in mode="color"
1093 public Integer green; // green brightness, 0..255, applies in mode="color"
1094 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1095 public Integer white; // white brightness, 0..255, applies in mode="color"
1096 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1097 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1098 public Integer brightness; // brightness, 0..100, applies in mode="white"
1099 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1100 // Change, 3: Breath,
1103 public static class ShellyStatusLight {
1104 public Boolean ison; // Whether output channel is on or off
1105 public Integer input;
1107 public ArrayList<ShellyStatusLightChannel> lights;
1108 public ArrayList<ShellySettingsMeter> meters;
1111 public static class ShellySenseKeyCode {
1112 String id; // ID of the stored IR code into Shelly Sense.
1113 String name; // Short description or name of the stored IR code.
1116 public static class ShellySendKeyList {
1117 @SerializedName("key_codes")
1118 public ArrayList<ShellySenseKeyCode> keyCodes;
1122 * Shelly Dimmer returns light[]. However, the structure doesn't match the lights[] of a Bulb/RGBW2.
1123 * The tag lights[] will be replaced with dimmers[] so this could be mapped to a different Gson structure.
1124 * The function requires that it's only called when the device is a dimmer - on get settings and get status
1126 * @param json Input Json as received by the API
1127 * @return Modified Json
1129 public static String fixDimmerJson(String json) {
1130 return !json.contains("\"lights\":[") ? json
1131 : json.replaceFirst(java.util.regex.Pattern.quote("\"lights\":["), "\"dimmers\":[");
1135 * Convert Shelly Button events into OH button states
1137 * @param eventType S/SS/SSS or L
1138 * @return OH button states
1140 public static String mapButtonEvent(String eventType) {
1141 // decode different codings
1143 // S/SS/SSS/L: CoAP for Button and xi3
1144 // shortpush/double_shortpush/triple_shortpush/longpush: REST
1145 switch (eventType) {
1147 return CommonTriggerEvents.RELEASED;
1149 case SHELLY_BTNEVENT_1SHORTPUSH:
1150 case SHELLY_EVENT_SHORTPUSH:
1151 return CommonTriggerEvents.SHORT_PRESSED;
1152 case SHELLY_BTNEVENT_2SHORTPUSH:
1153 case SHELLY_EVENT_DOUBLE_SHORTPUSH:
1154 return CommonTriggerEvents.DOUBLE_PRESSED;
1155 case SHELLY_BTNEVENT_3SHORTPUSH:
1156 case SHELLY_EVENT_TRIPLE_SHORTPUSH:
1157 return "TRIPLE_PRESSED";
1159 case SHELLY_BTNEVENT_LONGPUSH:
1160 case SHELLY_EVENT_LONGPUSH:
1161 return CommonTriggerEvents.LONG_PRESSED;
1162 case SHELLY_BTNEVENT_SHORTLONGPUSH:
1163 case SHELLY_EVENT_SHORT_LONGTPUSH:
1164 return "SHORT_LONG_PRESSED";
1165 case SHELLY_BTNEVENT_LONGSHORTPUSH:
1166 case SHELLY_EVENT_LONG_SHORTPUSH:
1167 return "LONG_SHORT_PRESSED";