2 * Copyright (c) 2010-2021 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 // Action URLs according to the device type
61 public static final String SHELLY_EVENTURL_SUFFIX = "_url";
64 public static final String SHELLY_EVENT_BTN_ON = "btn_on";
65 public static final String SHELLY_EVENT_BTN_OFF = "btn_off";
66 public static final String SHELLY_EVENT_OUT_ON = "out_on";
67 public static final String SHELLY_EVENT_OUT_OFF = "out_off";
68 public static final String SHELLY_EVENT_SHORTPUSH = "shortpush";
69 public static final String SHELLY_EVENT_LONGPUSH = "longpush";
71 public static final String SHELLY_EVENT_DOUBLE_SHORTPUSH = "double_shortpush";
72 public static final String SHELLY_EVENT_TRIPLE_SHORTPUSH = "triple_shortpush";
73 public static final String SHELLY_EVENT_SHORT_LONGTPUSH = "shortpush_longpush";
74 public static final String SHELLY_EVENT_LONG_SHORTPUSH = "longpush_shortpush";
77 public static final String SHELLY_EVENT_BTN1_ON = "btn1_on";
78 public static final String SHELLY_EVENT_BTN1_OFF = "btn1_off";
79 public static final String SHELLY_EVENT_BTN2_ON = "btn2_on";
80 public static final String SHELLY_EVENT_BTN2_OFF = "btn2_off";
81 public static final String SHELLY_EVENT_SHORTPUSH1 = "btn1_shortpush";
82 public static final String SHELLY_EVENT_LONGPUSH1 = "btn1_longpush";
83 public static final String SHELLY_EVENT_SHORTPUSH2 = "btn2_shortpush";
84 public static final String SHELLY_EVENT_LONGPUSH2 = "btn2_longpush";
87 public static final String SHELLY_EVENT_ROLLER_OPEN = "roller_open";
88 public static final String SHELLY_EVENT_ROLLER_CLOSE = "roller_close";
89 public static final String SHELLY_EVENT_ROLLER_STOP = "roller_stop";
92 public static final String SHELLY_EVENT_SENSORREPORT = "report";
93 public static final String SHELLY_EVENT_DARK = "dark";
94 public static final String SHELLY_EVENT_TWILIGHT = "twilight";
95 public static final String SHELLY_EVENT_BRIGHT = "bright";
96 public static final String SHELLY_EVENT_FLOOD_DETECTED = "flood_detected";
97 public static final String SHELLY_EVENT_FLOOD_GONE = "flood_gone";
98 public static final String SHELLY_EVENT_VIBRATION = "vibration"; // DW 1.6.5+
99 public static final String SHELLY_EVENT_OPEN = "open"; // DW 1.6.5+
100 public static final String SHELLY_EVENT_CLOSE = "close"; // DW 1.6.5+
101 public static final String SHELLY_EVENT_TEMP_OVER = "temp_over"; // FW 1.7
102 public static final String SHELLY_EVENT_TEMP_UNDER = "temp_under"; // FW 1.7
105 public static final String SHELLY_EVENT_ALARM_MILD = "alarm_mild"; // DW 1.7+
106 public static final String SHELLY_EVENT_ALARM_HEAVY = "alarm_heavy"; // DW 1.7+
107 public static final String SHELLY_EVENT_ALARM_OFF = "alarm_off"; // DW 1.7+
112 public static final String SHELLY_BTNT_MOMENTARY = "momentary";
113 public static final String SHELLY_BTNT_MOM_ON_RELEASE = "momentary_on_release";
114 public static final String SHELLY_BTNT_ONE_BUTTON = "one_button";
115 public static final String SHELLY_BTNT_TWO_BUTTON = "dual_button";
116 public static final String SHELLY_BTNT_TOGGLE = "toggle";
117 public static final String SHELLY_BTNT_EDGE = "edge";
118 public static final String SHELLY_BTNT_DETACHED = "detached";
120 public static final String SHELLY_STATE_LAST = "last";
121 public static final String SHELLY_STATE_STOP = "stop";
123 public static final String SHELLY_INP_MODE_OPENCLOSE = "openclose";
124 public static final String SHELLY_OBSTMODE_DISABLED = "disabled";
125 public static final String SHELLY_SAFETYM_WHILEOPENING = "while_opening";
127 public static final String SHELLY_ALWD_TRIGGER_NONE = "none";
128 public static final String SHELLY_ALWD_ROLLER_TURN_OPEN = "open";
129 public static final String SHELLY_ALWD_ROLLER_TURN_CLOSE = "close";
130 public static final String SHELLY_ALWD_ROLLER_TURN_STOP = "stop";
133 public static final String SHELLY_APIERR_UNAUTHORIZED = "Unauthorized";
134 public static final String SHELLY_APIERR_TIMEOUT = "Timeout";
135 public static final String SHELLY_APIERR_NOT_CALIBRATED = "Not calibrated!";
137 // API device types / properties
138 public static final String SHELLY_CLASS_RELAY = "relay"; // Relay: relay mode
139 public static final String SHELLY_CLASS_ROLLER = "roller"; // Relay: roller mode
140 public static final String SHELLY_CLASS_LIGHT = "light"; // Bulb: color mode
141 public static final String SHELLY_CLASS_EMETER = "emeter"; // EM/EM3: emeter
143 public static final String SHELLY_API_ON = "on";
144 public static final String SHELLY_API_OFF = "off";
145 public static final String SHELLY_API_TRUE = "true";
146 public static final String SHELLY_API_FALSE = "false";
148 public static final String SHELLY_API_MODE = "mode";
149 public static final String SHELLY_MODE_RELAY = "relay"; // Relay: relay mode
150 public static final String SHELLY_MODE_ROLLER = "roller"; // Relay: roller mode
151 public static final String SHELLY_MODE_COLOR = "color"; // Bulb/RGBW2: color mode
152 public static final String SHELLY_MODE_WHITE = "white"; // Bulb/RGBW2: white mode
154 public static final String SHELLY_LED_STATUS_DISABLE = "led_status_disable";
155 public static final String SHELLY_LED_POWER_DISABLE = "led_power_disable";
157 public static final String SHELLY_API_STOPR_NORMAL = "normal";
158 public static final String SHELLY_API_STOPR_SAFETYSW = "safety_switch";
159 public static final String SHELLY_API_STOPR_OBSTACLE = "obstacle";
160 public static final String SHELLY_API_STOPR_OVERPOWER = "overpower";
162 public static final String SHELLY_TIMER_AUTOON = "auto_on";
163 public static final String SHELLY_TIMER_AUTOOFF = "auto_off";
164 public static final String SHELLY_TIMER_ACTIVE = "has_timer";
166 public static final String SHELLY_LIGHT_TURN = "turn";
167 public static final String SHELLY_LIGHT_DEFSTATE = "def_state";
168 public static final String SHELLY_LIGHTTIMER = "timer";
170 public static final String SHELLY_COLOR_RED = "red";
171 public static final String SHELLY_COLOR_BLUE = "blue";
172 public static final String SHELLY_COLOR_GREEN = "green";
173 public static final String SHELLY_COLOR_YELLOW = "yellow";
174 public static final String SHELLY_COLOR_WHITE = "white";
175 public static final String SHELLY_COLOR_GAIN = "gain";
176 public static final String SHELLY_COLOR_BRIGHTNESS = "brightness";
177 public static final String SHELLY_COLOR_TEMP = "temp";
178 public static final String SHELLY_COLOR_EFFECT = "effect";
180 public static final int SHELLY_MIN_ROLLER_POS = 0;
181 public static final int SHELLY_MAX_ROLLER_POS = 100;
182 public static final int SHELLY_MIN_BRIGHTNESS = 0;
183 public static final int SHELLY_MAX_BRIGHTNESS = 100;
184 public static final int SHELLY_MIN_GAIN = 0;
185 public static final int SHELLY_MAX_GAIN = 100;
186 public static final int SHELLY_MIN_COLOR = 0;
187 public static final int SHELLY_MAX_COLOR = 255;
188 public static final int SHELLY_DIM_STEPSIZE = 10;
190 // color temperature: 3000 = warm, 4750 = white, 6565 = cold; gain: 0..100
191 public static final int MIN_COLOR_TEMP_BULB = 3000;
192 public static final int MAX_COLOR_TEMP_BULB = 6500;
193 public static final int MIN_COLOR_TEMP_DUO = 2700;
194 public static final int MAX_COLOR_TEMP_DUO = 6500;
195 public static final int COLOR_TEMP_RANGE_BULB = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
196 public static final int COLOR_TEMP_RANGE_DUO = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
197 public static final double MIN_BRIGHTNESS = 0.0;
198 public static final double MAX_BRIGHTNESS = 100.0;
199 public static final double SATURATION_FACTOR = 2.55;
200 public static final double GAIN_FACTOR = SHELLY_MAX_GAIN / 100;
201 public static final double BRIGHTNESS_FACTOR = SHELLY_MAX_BRIGHTNESS / 100;
204 public static final String SHELLY_API_ILLUM_DARK = "dark";
205 public static final String SHELLY_API_ILLUM_TWILIGHT = "twilight";
206 public static final String SHELLY_API_ILLUM_BRIGHT = "bright";
207 public static final String SHELLY_API_DWSTATE_OPEN = "open";
208 public static final String SHELLY_API_DWSTATE_CLOSE = "close";
211 public static final String SHELLY_IR_CODET_STORED = "stored";
212 public static final String SHELLY_IR_CODET_PRONTO = "pronto";
213 public static final String SHELLY_IR_CODET_PRONTO_HEX = "pronto_hex";
216 public static final int SHELLY_MIN_EFFECT = 0;
217 public static final int SHELLY_MAX_EFFECT = 6;
220 public static final String SHELLY_BTNEVENT_1SHORTPUSH = "S";
221 public static final String SHELLY_BTNEVENT_2SHORTPUSH = "SS";
222 public static final String SHELLY_BTNEVENT_3SHORTPUSH = "SSS";
223 public static final String SHELLY_BTNEVENT_LONGPUSH = "L";
224 public static final String SHELLY_BTNEVENT_SHORTLONGPUSH = "SL";
225 public static final String SHELLY_BTNEVENT_LONGSHORTPUSH = "LS";
227 public static final String SHELLY_TEMP_CELSIUS = "C";
228 public static final String SHELLY_TEMP_FAHRENHEIT = "F";
231 public static final int SHELLY_MOTION_SLEEPTIME_OFFSET = 3; // we need to substract and offset
233 // CoIoT Multicast setting
234 public static final String SHELLY_COIOT_MCAST = "mcast";
236 public static class ShellySettingsDevice {
239 public String hostname;
243 @SerializedName("coiot") // Shelly Motion Multicast Endpoint
245 public Integer longid;
247 @SerializedName("num_outputs")
248 public Integer numOutputs;
249 @SerializedName("num_meters")
250 public Integer numMeters;
251 @SerializedName("num_emeters")
252 public Integer numEMeters;
253 @SerializedName("num_rollers")
254 public Integer numRollers;
257 public static class ShellySettingsWiFiAp {
258 public Boolean enabled;
263 public static class ShellySettingsWiFiNetwork {
264 public Boolean enabled;
268 @SerializedName("ipv4_method")
269 public String ipv4Method;
276 public static class ShellySettingsMqtt {
277 public Boolean enable;
278 public String server;
280 @SerializedName("reconnect_timeout_max")
281 public Double reconnectTimeoutMax;
282 @SerializedName("reconnect_timeout_min")
283 public Double reconnectTimeoutMin;
284 @SerializedName("clean_session")
285 public Boolean cleanSession;
286 @SerializedName("keep_alive")
287 public Integer keepAlive;
288 @SerializedName("will_topic")
289 public String willTopic;
290 @SerializedName("will_message")
291 public String willMessage;
292 @SerializedName("max_qos")
293 public Integer maxQOS;
294 public Boolean retain;
295 @SerializedName("update_period")
296 public Integer updatePeriod;
299 public static class ShellySettingsCoiot { // FW 1.6+
300 @SerializedName("update_period")
301 public Integer updatePeriod;
302 public Boolean enabled; // Motion 1.0.7: Coap can be disabled
303 public String peer; // if set the device uses singlecast CoAP, mcast=set back to Multicast
306 public static class ShellyStatusMqtt {
307 public Boolean connected;
310 public static class ShellySettingsSntp {
311 public String server;
312 public Boolean enabled;
315 public static class ShellySettingsLogin {
316 public Boolean enabled;
317 public Boolean unprotected;
318 public String username;
319 public String password;
322 public static class ShellySettingsBuildInfo {
323 @SerializedName("build_id")
324 public String buildId;
325 @SerializedName("build_timestamp")
326 public String buildTimestamp;
327 @SerializedName("build_version")
328 public String buildVersion;
331 public static class ShellyStatusCloud {
332 public Boolean enabled;
333 public Boolean connected;
336 public static class ShellySettingsHwInfo {
337 @SerializedName("hw_revision")
338 public String hwRevision;
339 @SerializedName("batch_id")
340 public Integer batchId;
343 public static class ShellySettingsScheduleRules {
346 public static class ShellySettingsRelay {
349 public Boolean overpower;
350 @SerializedName("default_state")
351 public String defaultState; // Accepted values: off, on, last, switch
352 @SerializedName("btn_type")
353 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
354 @SerializedName("btn1_type") // Shelly 1L
355 public String btnType1;
356 @SerializedName("btn2_type") // Shelly 1L
357 public String btnType2;
358 @SerializedName("has_timer")
359 public Boolean hasTimer; // Whether a timer is currently armed for this channel
360 @SerializedName("auto_on")
361 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
362 @SerializedName("auto_off")
363 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
364 @SerializedName("btn_on_url")
365 public String btnOnUrl; // input is activated
366 @SerializedName("btnOffUrl")
367 public String btnOffUrl; // input is deactivated
368 @SerializedName("out_on_url")
369 public String outOnUrl; // output is activated
370 @SerializedName("out_off_url")
371 public String outOffUrl; // output is deactivated
372 @SerializedName("roller_open_url")
373 public String rollerOpenUrl; // to access when roller reaches open position
374 @SerializedName("roller_close_url")
375 public String rollerCloseUrl; // to access when roller reaches close position
376 @SerializedName("roller_stop_url")
377 public String rollerStopUrl; // to access when roller stopped
378 @SerializedName("longpush_url")
379 public String pushLongUrl; // to access when roller stopped
380 @SerializedName("shortpush_url")
381 public String pushShortUrl; // to access when roller stopped
383 public Boolean schedule;
384 // ArrayList<ShellySettingsScheduleRules> schedule_rules;
387 public static class ShellySettingsDimmer {
388 public String name; // unique name of the device
389 public Boolean ison; // true: output is ON
390 @SerializedName("default_state")
391 public String defaultState; // Accepted values: off, on, last, switch
392 @SerializedName("auto_on")
393 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
394 @SerializedName("auto_off")
395 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
396 @SerializedName("btn1_on_url")
397 public String btn1OnUrl; // URL to access when SW input is activated
398 @SerializedName("btn1_off_url")
399 public String btn1OffUrl; // URL to access when SW input is deactivated
400 @SerializedName("btn2_on_url")
401 public String btn2OnUrl; // URL to access when SW input is activated
402 @SerializedName("btn2_off_url")
403 public String btn2OoffUrl; // URL to access when SW input is deactivated
404 @SerializedName("out_on_url")
405 public String outOnUrl; // URL to access when output is activated
406 @SerializedName("out_off_url")
407 public String outOffUrl; // URL to access when output is deactivated
408 @SerializedName("longpush_url")
409 public String pushLongUrl; // long push button event
410 @SerializedName("shortpush_url")
411 public String pushShortUrl; // short push button event
412 @SerializedName("btn_type")
413 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
414 @SerializedName("btn1_type")
415 public String btnType1; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
416 @SerializedName("btn2_type")
417 public String btnType2; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
418 @SerializedName("swap_inputs")
419 public Integer swapInputs; // 0=no
422 public static class ShellySettingsRoller {
423 public Double maxtime;
424 @SerializedName("maxtime_open")
425 public Double maxtimeOpen;
426 @SerializedName("maxtime_close")
427 public Double maxtimeClose;
428 @SerializedName("default_state")
429 public String defaultState; // see SHELLY_STATE_xxx
431 @SerializedName("swap_inputs")
432 public Boolean swapInputs;
433 @SerializedName("input_mode")
434 public String inputMode; // see SHELLY_INP_MODE_OPENCLOSE
435 @SerializedName("button_type")
436 public String buttonType; // // see SHELLY_BTNT_xxx
437 @SerializedName("btn_Reverse")
438 public Integer btnReverse;
441 @SerializedName("is_valid")
442 public Boolean isValid;
443 @SerializedName("safety_switch")
444 public Boolean safetySwitch;
445 public Boolean schedule;
446 // ArrayList<ShellySettingsScheduleRules> schedule_rules; // not used for now
447 @SerializedName("obstacle_mode")
448 public String obstaclMode; // SHELLY_OBSTMODE_
449 @SerializedName("obstacle_action")
450 public String obstacleAction; // see SHELLY_STATE_xxx
451 @SerializedName("obstacle_power")
452 public Integer obstaclePower;
453 @SerializedName("obstacle_delay")
454 public Integer obstacleDelay;
455 @SerializedName("safety_mode")
456 public String safetyMode; // see SHELLY_SAFETYM_xxx
457 @SerializedName("safety_action")
458 public String safetyAction; // see SHELLY_STATE_xxx
459 @SerializedName("safety_allowed_on_trigger")
460 public String safetyAllowedOnTrigger; // see SHELLY_ALWD_TRIGGER_xxx
461 @SerializedName("off_power")
462 public Integer offPower;
463 public Boolean positioning;
466 public static class ShellySettingsRgbwLight {
468 public Boolean ison; // true: output is ON
469 public Integer brightness;
470 public Integer transition;
471 public String default_state;
472 @SerializedName("auto_on")
473 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
474 @SerializedName("auto_off")
475 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
476 public Boolean schedule;
477 @SerializedName("btn_type")
478 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
479 @SerializedName("btn_reverse")
480 public Integer btnReverse; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
481 @SerializedName("out_on_url")
482 public String outOnUrl; // output is activated
483 @SerializedName("out_off_url")
484 public String outOffUrl; // output is deactivated
487 public static class ShellyFavPos { // FW 1.9.2+ in roller mode
492 public static class ShellyInputState {
493 public Integer input;
497 @SerializedName("event_cnt")
498 public Integer eventCount;
501 public static class ShellySettingsMeter {
502 @SerializedName("is_valid")
503 public Boolean isValid;
505 public Double[] counters = { 0.0, 0.0, 0.0 };
507 public Long timestamp;
510 public static class ShellySettingsEMeter { // ShellyEM meter
511 @SerializedName("is_valid")
512 public Boolean isValid; // Whether the associated meter is functioning properly
513 public Double power; // Instantaneous power, Watts
514 public Double reactive; // Instantaneous reactive power, Watts
515 public Double voltage; // RMS voltage, Volts
516 public Double total; // Total consumed energy, Wh
517 @SerializedName("total_returned")
518 public Double totalReturned; // Total returned energy, Wh
520 public Double pf; // 3EM
521 public Double current; // 3EM
524 public static class ShellySettingsUpdate {
525 public String status;
526 @SerializedName("has_update")
527 public Boolean hasUpdate;
528 @SerializedName("new_version")
529 public String newVersion;
530 @SerializedName("old_version")
531 public String oldVersion;
532 @SerializedName("beta_version")
533 public String betaVersion;
536 public static class ShellySettingsGlobal {
537 // https://shelly-api-docs.shelly.cloud/#shelly1pm-settings
538 public ShellySettingsDevice device;
539 @SerializedName("wifi_ap")
540 public ShellySettingsWiFiAp wifiAp;
541 @SerializedName("wifi_sta")
542 public ShellySettingsWiFiNetwork wifiSta;
543 @SerializedName("wifi_sta1")
544 public ShellySettingsWiFiNetwork wifiSta1;
545 @SerializedName("wifirecovery_reboot_enabled")
546 public Boolean wifiRecoveryReboot;
548 public ShellySettingsMqtt mqtt; // not used for now
549 public ShellySettingsSntp sntp; // not used for now
550 public ShellySettingsCoiot coiot; // Firmware 1.6+
551 public ShellySettingsLogin login;
552 @SerializedName("pin_code")
553 public String pinCode;
554 @SerializedName("coiot_execute_enable")
555 public Boolean coiotExecuteEnable;
557 public Boolean discoverable; // FW 1.6+
559 @SerializedName("build_info")
560 public ShellySettingsBuildInfo buildInfo;
561 public ShellyStatusCloud cloud;
562 @SerializedName("sleep_mode")
563 public ShellySensorSleepMode sleepMode; // FW 1.6
564 @SerializedName("external_power")
565 public Integer externalPower; // H&T FW 1.6, seems to be the same like charger for the Sense
567 public String timezone;
570 public Boolean tzautodetect;
572 // @SerializedName("tz_utc_offset")
573 // public Integer tzUTCOoffset; // FW 1.6+
574 // @SerializedName("tz_dst")
575 // public Boolean tzDdst; // FW 1.6+
576 // @SerializedName("tz_dst_auto")
577 // public Boolean tzDstAuto; // FW 1.6+
578 // public Long unixtime; // FW 1.6+
580 public ShellySettingsHwInfo hwinfo;
582 @SerializedName("max_power")
583 public Double maxPower;
585 public ArrayList<ShellySettingsRelay> relays;
586 public ArrayList<ShellySettingsDimmer> dimmers;
587 public ArrayList<ShellySettingsRgbwLight> lights;
588 public ArrayList<ShellySettingsEMeter> emeters;
589 public ArrayList<ShellySettingsInput> inputs; // ix3
591 @SerializedName("temperature_units")
592 public String temperatureUnits; // Either'C'or'F'
594 @SerializedName("led_status_disable")
595 public Boolean ledStatusDisable; // PlugS only Disable LED indication for network
597 @SerializedName("led_power_disable")
598 public Boolean ledPowerDisable; // PlugS only Disable LED indication for network
600 @SerializedName("light_sensor")
601 public String lightSensor; // Sense: sensor type
602 @SerializedName("rain_sensor")
603 public Boolean rainSensor; // Flood: true=in rain mode
605 // FW 1.5.7: Door Window
606 @SerializedName("dark_treshold")
607 public Integer darkTreshold; // Illumination definition for "dark" in lux
608 @SerializedName("twilight_treshold")
609 public Integer twiLightTreshold; // Illumination definition for "twilight" in lux
610 @SerializedName("dark_url")
611 public String darkUrl; // URL to report to when luminance <= dark_threshold
612 @SerializedName("twilight_url")
613 public String twiLightUrl; // URL reports when luminance > dark_threshold AND luminance <=
614 @SerializedName("close_url")
615 public String closeUrl; // URL reports when DW contact is closed FW 1.6.5+
616 @SerializedName("vibration_url")
617 public String vibrationUrl; // URL reports when DW detects vibration FW 1.6.5+
619 // @SerializedName("tilt_enabled")
620 // public Boolean tiltEnabled; // Whether tilt monitoring is activated
621 // @SerializedName("tilt_calibrated")
622 // public Boolean tiltCalibrated; // Whether calibration data is valid
623 // @SerializedName("vibration_enabled")
624 // public Boolean vibrationEnabled; // Whether vibration monitoring is activated
625 // @SerializedName("reverse_open_close")
626 // public Boolean reverseOpenClose; // Whether to reverse which position the sensor consideres "open"
629 @SerializedName("set_volume")
630 public Integer volume; // Speaker volume for alarm
631 @SerializedName("alarm_off_url")
632 public String alarmOffUrl; // URL reports when alarm went off
633 @SerializedName("alarm_mild_url")
634 public String alarmMidUrl; // URL reports middle alarm
635 @SerializedName("alarm_heavy_url")
636 public String alarmHeavyfUrl; // URL reports heavy alarm
638 // Roller with FW 1.9.2+
639 @SerializedName("favorites_enabled")
640 public Boolean favoritesEnabled;
641 public ArrayList<ShellyFavPos> favorites;
644 public ShellyMotionSettings motion;
645 @SerializedName("tamper_sensitivity")
646 public Integer tamperSensitivity;
647 @SerializedName("dark_threshold")
648 public Integer darkThreshold;
649 @SerializedName("twilight_threshold")
650 public Integer twilightThreshold;
652 @SerializedName("sleep_time") // Shelly Motion
653 public Integer sleepTime;
656 public static class ShellySettingsAttributes {
657 @SerializedName("device_type")
658 public String deviceType; // Device model identifier
659 @SerializedName("device_mac")
660 public String deviceMac; // MAC address of the device in hexadecimal
661 @SerializedName("wifi_ap")
662 public String wifiAp; // WiFi access poInteger configuration, see /settings/ap for details
663 @SerializedName("wifi_sta")
664 public String wifiSta; // WiFi client configuration. See /settings/sta for details
665 public String login; // credentials used for HTTP Basic authentication for the REST interface. If
666 // enabled is true clients must include an Authorization: Basic ... HTTP header with valid
667 // credentials when performing TP requests.
668 public String name; // unique name of the device.
669 public String fw; // current FW version
672 public static class ShellyActionsStats {
673 public Integer skipped;
676 public static class ShellySettingsStatus {
677 public String name; // FW 1.8: Symbolic Device name is configurable
679 @SerializedName("wifi_sta")
680 public ShellySettingsWiFiNetwork wifiSta; // WiFi client configuration. See /settings/sta for details
681 public ShellyStatusCloud cloud;
682 public ShellyStatusMqtt mqtt;
685 public Integer serial;
686 @SerializedName("has_update")
687 public Boolean hasUpdate;
689 public Boolean discoverable; // FW 1.6+
690 @SerializedName("cfg_changed_cnt")
691 public Integer cfgChangedCount; // FW 1.8
692 @SerializedName("actions_stats")
693 public ShellyActionsStats astats;
695 public ArrayList<ShellySettingsRelay> relays;
696 public ArrayList<ShellySettingsRoller> rollers;
697 public Integer input; // RGBW2 has no JSON array
698 public ArrayList<ShellyInputState> inputs;
699 public ArrayList<ShellySettingsLight> lights;
700 // @SerializedName("night_mode") // FW 1.5.7+
701 // public ShellySettingsNightMode nightMode;
702 public ArrayList<ShellyShortLightStatus> dimmers;
703 public ArrayList<ShellySettingsMeter> meters;
704 public ArrayList<ShellySettingsEMeter> emeters;
706 // Internal device temp
707 public ShellyStatusSensor.ShellySensorTmp tmp; // Shelly 1PM
708 public Double temperature; // Shelly 2.5
709 public Boolean overtemperature;
711 // Shelly Dimmer only
712 public Boolean loaderror;
713 public Boolean overload;
715 public ShellySettingsUpdate update;
716 @SerializedName("ram_total")
717 public Long ramTotal;
718 @SerializedName("ram_free")
720 @SerializedName("fs_size")
722 @SerializedName("fs_free")
726 @SerializedName("sleep_time") // Shelly Motion
727 public Integer sleepTime;
732 public static class ShellySettingsInput {
733 @SerializedName("btn_type")
734 public String btnType;
736 // attributes not yet processed
737 // public String name;
738 // @SerializedName("btn_reverse")
739 // public Integer btnReverse;
740 // @SerializedName("btn_on_url")
741 // public String btnOnUrl;
742 // @SerializedName("btn_off_url")
743 // public String btnOffUrl;
744 // @SerializedName("shortpush_url")
745 // public String shortpushUrl;
746 // @SerializedName("longpush_url")
747 // public String longpushUrl;
748 // @SerializedName("double_shortpush_url")
749 // public String doubleShortpushUrl;
750 // @SerializedName("triple_shortpush_url")
751 // public String tripleShortpushUrl;
752 // @SerializedName("shortpush_longpush_url")
753 // public String shortpushLongpushUrl;
754 // @SerializedName("longpush_shortpush_url")
755 // public String longpushShortpushUrl;
758 public static class ShellyControlRelay {
759 // https://shelly-api-docs.shelly.cloud/#shelly1-1pm-settings-relay-0
760 @SerializedName("is_valid")
761 public Boolean isValid;
762 @SerializedName("has_timer")
763 public Boolean hasTimer; // Whether a timer is currently armed for this channel
764 @SerializedName("timer_remaining")
765 public Integer timerRemaining; // FW 1.6+
766 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
768 public String turn; // Accepted values are on and off. This will turn ON/OFF the respective output
769 // channel when request is sent .
770 public Integer timer; // A one-shot flip-back timer in seconds.
773 public static class ShellyShortStatusRelay {
774 public String name; // FW 1.8+: Channel could now have a logical name
775 @SerializedName("is_valid")
776 public Boolean isValid;
777 public Boolean ison; // Whether output channel is on or off
778 @SerializedName("has_timer")
779 public Boolean hasTimer; // Whether a timer is currently armed for this channel
780 @SerializedName("timer_remaining")
781 public Integer timerRemaining;
782 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
783 public Double temperature; // Internal device temperature
784 public Boolean overtemperature; // Device over heated
787 public static class ShellyShortLightStatus {
788 public Boolean ison; // Whether output channel is on or off
789 public String mode; // color or white - valid only for Bulb and RGBW2 even Dimmer returns it also
790 public Integer brightness; // brightness: 0.100%
791 // @SerializedName("has_timer")
792 // public Boolean hasTimer; // Whether a timer is currently armed for this channel
793 // @SerializedName("timer_remaining")
794 // public Integer timerRemaining;
795 // public Integer wgite;
796 // public Integer temp; // light temp
799 public static class ShellyStatusRelay {
800 public String name; // FW 1.8: Symbolic channel name is configurable
802 @SerializedName("wifi_sta")
803 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
804 // public ShellyStatusCloud cloud; // Cloud status
805 // public ShellyStatusMqtt mqtt; // mqtt status
806 public ShellySettingsCoiot coiot; // Firmware 1.6+
807 // public String time; // current time
808 public Integer serial;
809 public String mac; // MAC
810 public ArrayList<ShellyShortStatusRelay> relays; // relay status
811 public ArrayList<ShellySettingsMeter> meters; // current meter value
812 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
814 @SerializedName("ext_temperature")
815 public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
816 @SerializedName("ext_humidity")
817 public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
819 public Double temperature; // device temp acc. on the selected temp unit
820 public ShellyStatusSensor.ShellySensorTmp tmp;
822 @SerializedName("has_update")
823 public Boolean hasUpdate; // If a newer firmware version is available
824 public ShellySettingsUpdate update; // /status/firmware value
826 @SerializedName("ram_total")
827 public Integer ramTotal; // Total and available amount of system memory in bytes
828 @SerializedName("ram_free")
829 public Integer ramFree;
830 @SerializedName("fs_size")
831 public Integer fsSize;
832 @SerializedName("fs_free")
833 public Integer fsFree; // Total and available amount of file system space in bytes
834 public Integer uptime; // econds elapsed since boot
837 public static class ShellyStatusDimmer {
838 @SerializedName("wifi_sta")
839 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
840 // public ShellyStatusCloud cloud; // Cloud status
841 // public ShellyStatusMqtt mqtt; // mqtt status
842 public String time; // current time
843 public Integer serial;
844 public String mac; // MAC
845 public ArrayList<ShellyShortLightStatus> lights; // relay status
846 public ArrayList<ShellySettingsMeter> meters; // current meter value
848 public ShellyStatusSensor.ShellySensorTmp tmp;
849 public Boolean overtemperature;
851 public Boolean loaderror;
852 public Boolean overload;
854 @SerializedName("has_update")
855 public Boolean hasUpdate; // If a newer firmware version is available
856 public ShellySettingsUpdate update; // /status/firmware value
858 @SerializedName("ram_total")
859 public Integer ramTotal; // Total and available amount of system memory in
861 @SerializedName("ram_free")
862 public Integer ramFree;
863 @SerializedName("fs_size")
864 public Integer fsSize;
865 @SerializedName("fs_free")
866 public Integer fsFree; // Total and available amount of file system space in bytes
867 public Integer uptime; // seconds elapsed since boot
870 public static class ShellyControlRoller {
871 public String name; // FW 1.8: Symbolic name is configurable
873 @SerializedName("roller_pos")
874 public Integer rollerPos; // number Desired position in percent
875 public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
876 // value of maxtime in /settings/roller/N will be used.
877 public String state; // One of stop, open, close
878 public Double power; // Current power consumption in Watts
879 @SerializedName("is_valid")
880 public Boolean isValid; // If the power meter functions properly
881 @SerializedName("safety_switch")
882 public Boolean safetySwitch; // Whether the safety input is currently triggered
883 public Boolean overtemperature;
884 @SerializedName("stop_reason")
885 public String stopReason; // Last cause for stopping: normal, safety_switch, obstacle
886 @SerializedName("last_direction")
887 public String lastDirection; // Last direction of motion, open or close
888 public Boolean calibrating;
889 public Boolean positioning; // true when calibration was performed
890 @SerializedName("current_pos")
891 public Integer currentPos; // current position 0..100, 100=open
894 public class ShellySensorSleepMode {
895 public Integer period;
899 public static class ShellyStatusSensor {
900 // https://shelly-api-docs.shelly.cloud/#h-amp-t-settings
901 public static class ShellySensorTmp {
902 public Double value; // Temperature in configured unites
903 public String units; // 'C' or 'F'
904 public Double tC; // temperature in deg C
905 public Double tF; // temperature in deg F
906 @SerializedName("is_valid")
907 public Boolean isValid; // whether the internal sensor is operating properly
910 public static class ShellySensorHum {
911 public Double value; // relative humidity in %
914 public static class ShellySensorBat {
915 public Double value; // estimated remaining battery capacity in %
916 public Double voltage; // battery voltage
919 // Door/Window sensor
920 public static class ShellySensorState {
921 @SerializedName("is_valid")
922 public Boolean isValid; // whether the internal sensor is operating properly
923 public String state; // Shelly Door/Window
926 public Boolean motion;
927 public Boolean vibration;
928 @SerializedName("timestamp")
929 public Long motionTimestamp;
930 @SerializedName("active")
931 public Boolean motionActive;
934 public static class ShellySensorLux {
935 @SerializedName("is_valid")
936 public Boolean isValid; // whether the internal sensor is operating properly
939 public String illumination;
942 public static class ShellySensorAccel {
943 public Integer tilt; // Tilt in °
944 public Integer vibration; // Whether vibration is detected
947 public static class ShellyMotionSettings {
948 public Integer sensitivity;
949 @SerializedName("blind_time_minutes")
950 public Integer blindTimeMinutes;
951 @SerializedName("pulse_count")
952 public Integer pulseCount;
953 @SerializedName("operating_mode")
954 public Integer operatingMode;
955 public Boolean enabled;
958 public static class ShellyExtTemperature {
959 public static class ShellyShortTemp {
960 public Double tC; // temperature in deg C
961 public Double tF; // temperature in deg F
964 // Shelly 1/1PM have up to 3 sensors
965 // for whatever reasons it's not an array, but 3 independent elements
967 public ShellyShortTemp sensor1;
969 public ShellyShortTemp sensor2;
971 public ShellyShortTemp sensor3;
974 public static class ShellyExtHumidity {
975 public static class ShellyShortHum {
976 public Double hum; // Humidity reading of sensor 0, percent
979 // Shelly 1/1PM have up to 3 sensors
980 // for whatever reasons it's not an array, but 3 independent elements
982 public ShellyShortHum sensor1;
985 public static class ShellyADC {
986 public Double voltage;
989 public ShellySensorTmp tmp;
990 public ShellySensorHum hum;
991 public ShellySensorLux lux;
992 public ShellySensorAccel accel;
993 public ShellySensorBat bat;
994 @SerializedName("sensor")
995 public ShellySensorState sensor;
996 public Boolean smoke; // SHelly Smoke
997 public Boolean flood; // Shelly Flood: true = flood condition detected
998 @SerializedName("rain_sensor")
999 public Boolean rainSensor; // Shelly Flood: true=in rain mode
1001 public Boolean motion; // Shelly Sense: true=motion detected
1002 public Boolean charger; // Shelly Sense: true=charger connected
1004 @SerializedName("act_reasons")
1005 public List<Object> actReasons; // HT/Smoke/Flood: list of reasons which woke up the device
1007 @SerializedName("sensor_error")
1008 public String sensorError; // 1.5.7: Only displayed in case of error
1010 // FW 1.7: Shelly Gas
1011 @SerializedName("gas_sensor")
1012 public ShellyStatusGasSensor gasSensor;
1013 @SerializedName("concentration")
1014 public ShellyStatusGasConcentration concentration;
1015 public ArrayList<ShellyStatusValve> valves;
1018 @SerializedName("connect_retries")
1019 public Integer connectRetries;
1020 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
1022 // Shelly UNI FW 1.9+
1023 public ArrayList<ShellyADC> adcs;
1026 public static class ShellySettingsSmoke {
1027 @SerializedName("temperature_units")
1028 public String temperatureUnits; // Either 'C' or 'F'
1029 @SerializedName("temperature_threshold")
1030 public Integer temperatureThreshold; // Temperature delta (in configured degree units) which triggers an update
1031 @SerializedName("sleep_mode_period")
1032 public Integer sleepModePeriod; // Periodic update period in hours, between 1 and 24
1036 // "gas_sensor":{"sensor_state":"normal","self_test_state":"not_completed","alarm_state":"none"},
1037 // "concentration":{"ppm":0,"is_valid":true},
1038 public static class ShellyStatusGasSensor {
1039 @SerializedName("sensor_state")
1040 public String sensorState;
1041 @SerializedName("self_test_state")
1042 public String selfTestState;
1043 @SerializedName("alarm_state")
1044 public String alarmState;
1047 public static class ShellyStatusGasConcentration {
1049 @SerializedName("is_valid")
1050 public Boolean isValid;
1053 public static class ShellyStatusValve {
1054 public String state; // closed/opened/not_connected/failure/closing/opening/checking
1057 public static class ShellySettingsLight {
1058 public Integer red; // red brightness, 0..255, applies in mode="color"
1059 public Integer green; // green brightness, 0..255, applies in mode="color"
1060 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1061 public Integer white; // white brightness, 0..255, applies in mode="color"
1062 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1063 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1064 public Integer brightness; // brightness, 0..100, applies in mode="white"
1065 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1066 // Change, 3: Breath,
1067 // 4: Flash, 5: On/Off Gradual, 6: Red/Green Change
1068 @SerializedName("default_state")
1069 public String defaultState; // one of on, off or last
1070 @SerializedName("auto_on")
1071 public Double autoOn; // see above
1072 @SerializedName("auto_off")
1073 public Double autoOff; // see above
1075 public Integer dcpower; // RGW2:Set to true for 24 V power supply, false for 12 V
1079 public Boolean ison;
1082 public static class ShellySettingsNightMode { // FW1.5.7+
1083 public Integer enabled;
1084 @SerializedName("start_time")
1085 public String startTime;
1086 @SerializedName("end_time")
1087 public String endTime;
1088 public Integer brightness;
1091 public static class ShellyStatusLightChannel {
1092 public Boolean ison;
1093 public Double power;
1094 public Boolean overpower;
1095 @SerializedName("has_timer")
1096 public Boolean hasTimer;
1097 @SerializedName("timer_started")
1098 public Integer timerStarted;
1099 @SerializedName("timer_duration")
1100 public Integer timerDuration;
1101 @SerializedName("timer_remaining")
1102 public Integer timerRemaining;
1104 public Integer red; // red brightness, 0..255, applies in mode="color"
1105 public Integer green; // green brightness, 0..255, applies in mode="color"
1106 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1107 public Integer white; // white brightness, 0..255, applies in mode="color"
1108 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1109 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1110 public Integer brightness; // brightness, 0..100, applies in mode="white"
1111 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1112 // Change, 3: Breath,
1115 public static class ShellyStatusLight {
1116 public Boolean ison; // Whether output channel is on or off
1117 public Integer input;
1119 public ArrayList<ShellyStatusLightChannel> lights;
1120 public ArrayList<ShellySettingsMeter> meters;
1123 public static class ShellySenseKeyCode {
1124 String id; // ID of the stored IR code into Shelly Sense.
1125 String name; // Short description or name of the stored IR code.
1128 public static class ShellySendKeyList {
1129 @SerializedName("key_codes")
1130 public ArrayList<ShellySenseKeyCode> keyCodes;
1134 * Shelly Dimmer returns light[]. However, the structure doesn't match the lights[] of a Bulb/RGBW2.
1135 * The tag lights[] will be replaced with dimmers[] so this could be mapped to a different Gson structure.
1136 * The function requires that it's only called when the device is a dimmer - on get settings and get status
1138 * @param json Input Json as received by the API
1139 * @return Modified Json
1141 public static String fixDimmerJson(String json) {
1142 return !json.contains("\"lights\":[") ? json
1143 : json.replaceFirst(java.util.regex.Pattern.quote("\"lights\":["), "\"dimmers\":[");
1147 * Convert Shelly Button events into OH button states
1149 * @param eventType S/SS/SSS or L
1150 * @return OH button states
1152 public static String mapButtonEvent(String eventType) {
1153 // decode different codings
1155 // S/SS/SSS/L: CoAP for Button and xi3
1156 // shortpush/double_shortpush/triple_shortpush/longpush: REST
1157 switch (eventType) {
1159 return CommonTriggerEvents.RELEASED;
1161 case SHELLY_BTNEVENT_1SHORTPUSH:
1162 case SHELLY_EVENT_SHORTPUSH:
1163 return CommonTriggerEvents.SHORT_PRESSED;
1164 case SHELLY_BTNEVENT_2SHORTPUSH:
1165 case SHELLY_EVENT_DOUBLE_SHORTPUSH:
1166 return CommonTriggerEvents.DOUBLE_PRESSED;
1167 case SHELLY_BTNEVENT_3SHORTPUSH:
1168 case SHELLY_EVENT_TRIPLE_SHORTPUSH:
1169 return "TRIPLE_PRESSED";
1171 case SHELLY_BTNEVENT_LONGPUSH:
1172 case SHELLY_EVENT_LONGPUSH:
1173 return CommonTriggerEvents.LONG_PRESSED;
1174 case SHELLY_BTNEVENT_SHORTLONGPUSH:
1175 case SHELLY_EVENT_SHORT_LONGTPUSH:
1176 return "SHORT_LONG_PRESSED";
1177 case SHELLY_BTNEVENT_LONGSHORTPUSH:
1178 case SHELLY_EVENT_LONG_SHORTPUSH:
1179 return "LONG_SHORT_PRESSED";