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
384 public static class ShellySettingsDimmer {
385 public String name; // unique name of the device
386 public Boolean ison; // true: output is ON
387 @SerializedName("default_state")
388 public String defaultState; // Accepted values: off, on, last, switch
389 @SerializedName("auto_on")
390 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
391 @SerializedName("auto_off")
392 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
393 @SerializedName("btn1_on_url")
394 public String btn1OnUrl; // URL to access when SW input is activated
395 @SerializedName("btn1_off_url")
396 public String btn1OffUrl; // URL to access when SW input is deactivated
397 @SerializedName("btn2_on_url")
398 public String btn2OnUrl; // URL to access when SW input is activated
399 @SerializedName("btn2_off_url")
400 public String btn2OoffUrl; // URL to access when SW input is deactivated
401 @SerializedName("out_on_url")
402 public String outOnUrl; // URL to access when output is activated
403 @SerializedName("out_off_url")
404 public String outOffUrl; // URL to access when output is deactivated
405 @SerializedName("longpush_url")
406 public String pushLongUrl; // long push button event
407 @SerializedName("shortpush_url")
408 public String pushShortUrl; // short push button event
409 @SerializedName("btn_type")
410 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
411 @SerializedName("btn1_type")
412 public String btnType1; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
413 @SerializedName("btn2_type")
414 public String btnType2; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
415 @SerializedName("swap_inputs")
416 public Integer swapInputs; // 0=no
419 public static class ShellySettingsRoller {
420 public Double maxtime;
421 @SerializedName("maxtime_open")
422 public Double maxtimeOpen;
423 @SerializedName("maxtime_close")
424 public Double maxtimeClose;
425 @SerializedName("default_state")
426 public String defaultState; // see SHELLY_STATE_xxx
428 @SerializedName("swap_inputs")
429 public Boolean swapInputs;
430 @SerializedName("input_mode")
431 public String inputMode; // see SHELLY_INP_MODE_OPENCLOSE
432 @SerializedName("button_type")
433 public String buttonType; // // see SHELLY_BTNT_xxx
434 @SerializedName("btn_Reverse")
435 public Integer btnReverse;
438 @SerializedName("is_valid")
439 public Boolean isValid;
440 @SerializedName("safety_switch")
441 public Boolean safetySwitch;
442 @SerializedName("obstacle_mode")
443 public String obstaclMode; // SHELLY_OBSTMODE_
444 @SerializedName("obstacle_action")
445 public String obstacleAction; // see SHELLY_STATE_xxx
446 @SerializedName("obstacle_power")
447 public Integer obstaclePower;
448 @SerializedName("obstacle_delay")
449 public Integer obstacleDelay;
450 @SerializedName("safety_mode")
451 public String safetyMode; // see SHELLY_SAFETYM_xxx
452 @SerializedName("safety_action")
453 public String safetyAction; // see SHELLY_STATE_xxx
454 @SerializedName("safety_allowed_on_trigger")
455 public String safetyAllowedOnTrigger; // see SHELLY_ALWD_TRIGGER_xxx
456 @SerializedName("off_power")
457 public Integer offPower;
458 public Boolean positioning;
461 public static class ShellySettingsRgbwLight {
463 public Boolean ison; // true: output is ON
464 public Integer brightness;
465 public Integer transition;
466 @SerializedName("default_state")
467 public String defaultState;
468 @SerializedName("auto_on")
469 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
470 @SerializedName("auto_off")
471 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
472 public Boolean schedule;
473 @SerializedName("btn_type")
474 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
475 @SerializedName("btn_reverse")
476 public Integer btnReverse; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
477 @SerializedName("out_on_url")
478 public String outOnUrl; // output is activated
479 @SerializedName("out_off_url")
480 public String outOffUrl; // output is deactivated
483 public static class ShellyFavPos { // FW 1.9.2+ in roller mode
488 public static class ShellyInputState {
489 public Integer input;
493 @SerializedName("event_cnt")
494 public Integer eventCount;
497 public static class ShellySettingsMeter {
498 @SerializedName("is_valid")
499 public Boolean isValid;
501 public Double[] counters = { 0.0, 0.0, 0.0 };
503 public Long timestamp;
506 public static class ShellySettingsEMeter { // ShellyEM meter
507 @SerializedName("is_valid")
508 public Boolean isValid; // Whether the associated meter is functioning properly
509 public Double power; // Instantaneous power, Watts
510 public Double reactive; // Instantaneous reactive power, Watts
511 public Double voltage; // RMS voltage, Volts
512 public Double total; // Total consumed energy, Wh
513 @SerializedName("total_returned")
514 public Double totalReturned; // Total returned energy, Wh
516 public Double pf; // 3EM
517 public Double current; // 3EM
520 public static class ShellySettingsUpdate {
521 public String status;
522 @SerializedName("has_update")
523 public Boolean hasUpdate;
524 @SerializedName("new_version")
525 public String newVersion;
526 @SerializedName("old_version")
527 public String oldVersion;
528 @SerializedName("beta_version")
529 public String betaVersion;
532 public static class ShellySettingsGlobal {
533 // https://shelly-api-docs.shelly.cloud/#shelly1pm-settings
534 public ShellySettingsDevice device;
535 @SerializedName("wifi_ap")
536 public ShellySettingsWiFiAp wifiAp;
537 @SerializedName("wifi_sta")
538 public ShellySettingsWiFiNetwork wifiSta;
539 @SerializedName("wifi_sta1")
540 public ShellySettingsWiFiNetwork wifiSta1;
541 @SerializedName("wifirecovery_reboot_enabled")
542 public Boolean wifiRecoveryReboot; // FW 1.10+
543 @SerializedName("ap_roaming")
544 public ShellyApRoaming apRoaming; // FW 1.10+
546 public ShellySettingsMqtt mqtt; // not used for now
547 public ShellySettingsSntp sntp; // not used for now
548 public ShellySettingsCoiot coiot; // Firmware 1.6+
549 public ShellySettingsLogin login;
550 @SerializedName("pin_code")
551 public String pinCode;
552 @SerializedName("coiot_execute_enable")
553 public Boolean coiotExecuteEnable;
555 public Boolean discoverable; // FW 1.6+
557 @SerializedName("build_info")
558 public ShellySettingsBuildInfo buildInfo;
559 public ShellyStatusCloud cloud;
560 @SerializedName("sleep_mode")
561 public ShellySensorSleepMode sleepMode; // FW 1.6
562 @SerializedName("external_power")
563 public Integer externalPower; // H&T FW 1.6, seems to be the same like charger for the Sense
564 @SerializedName("debug_enable") // FW 1.10+
565 public Boolean debugEnable;
567 public String timezone;
570 public Boolean tzautodetect;
573 public ShellySettingsHwInfo hwinfo;
575 @SerializedName("max_power")
576 public Double maxPower;
578 public ArrayList<ShellySettingsRelay> relays;
579 public ArrayList<ShellySettingsDimmer> dimmers;
580 public ArrayList<ShellySettingsRgbwLight> lights;
581 public ArrayList<ShellySettingsEMeter> emeters;
582 public ArrayList<ShellySettingsInput> inputs; // ix3
584 @SerializedName("temperature_units")
585 public String temperatureUnits; // Either'C'or'F'
587 @SerializedName("led_status_disable")
588 public Boolean ledStatusDisable; // PlugS only Disable LED indication for network
590 @SerializedName("led_power_disable")
591 public Boolean ledPowerDisable; // PlugS only Disable LED indication for network
593 @SerializedName("light_sensor")
594 public String lightSensor; // Sense: sensor type
595 @SerializedName("rain_sensor")
596 public Boolean rainSensor; // Flood: true=in rain mode
598 // FW 1.5.7: Door Window
599 @SerializedName("dark_treshold")
600 public Integer darkTreshold; // Illumination definition for "dark" in lux
601 @SerializedName("twilight_treshold")
602 public Integer twiLightTreshold; // Illumination definition for "twilight" in lux
603 @SerializedName("dark_url")
604 public String darkUrl; // URL to report to when luminance <= dark_threshold
605 @SerializedName("twilight_url")
606 public String twiLightUrl; // URL reports when luminance > dark_threshold AND luminance <=
607 @SerializedName("close_url")
608 public String closeUrl; // URL reports when DW contact is closed FW 1.6.5+
609 @SerializedName("vibration_url")
610 public String vibrationUrl; // URL reports when DW detects vibration FW 1.6.5+
613 @SerializedName("set_volume")
614 public Integer volume; // Speaker volume for alarm
615 @SerializedName("alarm_off_url")
616 public String alarmOffUrl; // URL reports when alarm went off
617 @SerializedName("alarm_mild_url")
618 public String alarmMidUrl; // URL reports middle alarm
619 @SerializedName("alarm_heavy_url")
620 public String alarmHeavyfUrl; // URL reports heavy alarm
622 // Roller with FW 1.9.2+
623 @SerializedName("favorites_enabled")
624 public Boolean favoritesEnabled;
625 public ArrayList<ShellyFavPos> favorites;
628 public ShellyMotionSettings motion;
629 @SerializedName("tamper_sensitivity")
630 public Integer tamperSensitivity;
631 @SerializedName("dark_threshold")
632 public Integer darkThreshold;
633 @SerializedName("twilight_threshold")
634 public Integer twilightThreshold;
636 @SerializedName("sleep_time") // Shelly Motion
637 public Integer sleepTime;
640 public static class ShellySettingsAttributes {
641 @SerializedName("device_type")
642 public String deviceType; // Device model identifier
643 @SerializedName("device_mac")
644 public String deviceMac; // MAC address of the device in hexadecimal
645 @SerializedName("wifi_ap")
646 public String wifiAp; // WiFi access poInteger configuration, see /settings/ap for details
647 @SerializedName("wifi_sta")
648 public String wifiSta; // WiFi client configuration. See /settings/sta for details
649 public String login; // credentials used for HTTP Basic authentication for the REST interface. If
650 // enabled is true clients must include an Authorization: Basic ... HTTP header with valid
651 // credentials when performing TP requests.
652 public String name; // unique name of the device.
653 public String fw; // current FW version
656 public static class ShellyActionsStats {
657 public Integer skipped;
660 public static class ShellySettingsStatus {
661 public String name; // FW 1.8: Symbolic Device name is configurable
663 @SerializedName("wifi_sta")
664 public ShellySettingsWiFiNetwork wifiSta; // WiFi client configuration. See /settings/sta for details
665 public ShellyStatusCloud cloud;
666 public ShellyStatusMqtt mqtt;
669 public Integer serial;
670 @SerializedName("has_update")
671 public Boolean hasUpdate;
673 public Boolean discoverable; // FW 1.6+
674 @SerializedName("cfg_changed_cnt")
675 public Integer cfgChangedCount; // FW 1.8
676 @SerializedName("actions_stats")
677 public ShellyActionsStats astats;
679 public ArrayList<ShellySettingsRelay> relays;
680 public ArrayList<ShellySettingsRoller> rollers;
681 public Integer input; // RGBW2 has no JSON array
682 public ArrayList<ShellyInputState> inputs;
683 public ArrayList<ShellySettingsLight> lights;
684 public ArrayList<ShellyShortLightStatus> dimmers;
685 public ArrayList<ShellySettingsMeter> meters;
686 public ArrayList<ShellySettingsEMeter> emeters;
688 // Internal device temp
689 public ShellyStatusSensor.ShellySensorTmp tmp; // Shelly 1PM
690 public Double temperature; // Shelly 2.5
691 public Boolean overtemperature;
693 // Shelly Dimmer only
694 public Boolean loaderror;
695 public Boolean overload;
697 public ShellySettingsUpdate update;
698 @SerializedName("ram_total")
699 public Long ramTotal;
700 @SerializedName("ram_free")
702 @SerializedName("fs_size")
704 @SerializedName("fs_free")
708 @SerializedName("sleep_time") // Shelly Motion
709 public Integer sleepTime;
714 public static class ShellySettingsInput {
715 @SerializedName("btn_type")
716 public String btnType;
719 public static class ShellyControlRelay {
720 // https://shelly-api-docs.shelly.cloud/#shelly1-1pm-settings-relay-0
721 @SerializedName("is_valid")
722 public Boolean isValid;
723 @SerializedName("has_timer")
724 public Boolean hasTimer; // Whether a timer is currently armed for this channel
725 @SerializedName("timer_remaining")
726 public Integer timerRemaining; // FW 1.6+
727 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
729 public String turn; // Accepted values are on and off. This will turn ON/OFF the respective output
730 // channel when request is sent .
731 public Integer timer; // A one-shot flip-back timer in seconds.
734 public static class ShellyShortStatusRelay {
735 public String name; // FW 1.8+: Channel could now have a logical name
736 @SerializedName("is_valid")
737 public Boolean isValid;
738 public Boolean ison; // Whether output channel is on or off
739 @SerializedName("has_timer")
740 public Boolean hasTimer; // Whether a timer is currently armed for this channel
741 @SerializedName("timer_remaining")
742 public Integer timerRemaining;
743 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
744 public Double temperature; // Internal device temperature
745 public Boolean overtemperature; // Device over heated
748 public static class ShellyShortLightStatus {
749 public Boolean ison; // Whether output channel is on or off
750 public String mode; // color or white - valid only for Bulb and RGBW2 even Dimmer returns it also
751 public Integer brightness; // brightness: 0.100%
754 public static class ShellyStatusRelay {
755 public String name; // FW 1.8: Symbolic channel name is configurable
757 @SerializedName("wifi_sta")
758 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
759 public ShellySettingsCoiot coiot; // Firmware 1.6+
760 public Integer serial;
761 public String mac; // MAC
762 public ArrayList<ShellyShortStatusRelay> relays; // relay status
763 public ArrayList<ShellySettingsMeter> meters; // current meter value
764 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
766 @SerializedName("ext_temperature")
767 public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
768 @SerializedName("ext_humidity")
769 public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
771 public Double temperature; // device temp acc. on the selected temp unit
772 public ShellyStatusSensor.ShellySensorTmp tmp;
775 public static class ShellyStatusDimmer {
776 @SerializedName("wifi_sta")
777 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
778 public ArrayList<ShellyShortLightStatus> lights; // relay status
779 public ArrayList<ShellySettingsMeter> meters; // current meter value
781 public ShellyStatusSensor.ShellySensorTmp tmp;
782 public Boolean overtemperature;
784 public Boolean loaderror;
785 public Boolean overload;
788 public static class ShellyControlRoller {
789 public String name; // FW 1.8: Symbolic name is configurable
791 @SerializedName("roller_pos")
792 public Integer rollerPos; // number Desired position in percent
793 public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
794 // value of maxtime in /settings/roller/N will be used.
795 public String state; // One of stop, open, close
796 public Double power; // Current power consumption in Watts
797 @SerializedName("is_valid")
798 public Boolean isValid; // If the power meter functions properly
799 @SerializedName("safety_switch")
800 public Boolean safetySwitch; // Whether the safety input is currently triggered
801 public Boolean overtemperature;
802 @SerializedName("stop_reason")
803 public String stopReason; // Last cause for stopping: normal, safety_switch, obstacle
804 @SerializedName("last_direction")
805 public String lastDirection; // Last direction of motion, open or close
806 public Boolean calibrating;
807 public Boolean positioning; // true when calibration was performed
808 @SerializedName("current_pos")
809 public Integer currentPos; // current position 0..100, 100=open
812 public class ShellyOtaCheckResult {
813 public String status;
816 public class ShellyApRoaming {
817 public Boolean enabled;
818 public Integer threshold;
821 public class ShellySensorSleepMode {
822 public Integer period;
826 public static class ShellyStatusSensor {
827 // https://shelly-api-docs.shelly.cloud/#h-amp-t-settings
828 public static class ShellySensorTmp {
829 public Double value; // Temperature in configured unites
830 public String units; // 'C' or 'F'
831 public Double tC; // temperature in deg C
832 public Double tF; // temperature in deg F
833 @SerializedName("is_valid")
834 public Boolean isValid; // whether the internal sensor is operating properly
837 public static class ShellySensorHum {
838 public Double value; // relative humidity in %
841 public static class ShellySensorBat {
842 public Double value; // estimated remaining battery capacity in %
843 public Double voltage; // battery voltage
846 // Door/Window sensor
847 public static class ShellySensorState {
848 @SerializedName("is_valid")
849 public Boolean isValid; // whether the internal sensor is operating properly
850 public String state; // Shelly Door/Window
853 public Boolean motion;
854 public Boolean vibration;
855 @SerializedName("timestamp")
856 public Long motionTimestamp;
857 @SerializedName("active")
858 public Boolean motionActive;
861 public static class ShellySensorLux {
862 @SerializedName("is_valid")
863 public Boolean isValid; // whether the internal sensor is operating properly
866 public String illumination;
869 public static class ShellySensorAccel {
870 public Integer tilt; // Tilt in °
871 public Integer vibration; // Whether vibration is detected
874 public static class ShellyMotionSettings {
875 public Integer sensitivity;
876 @SerializedName("blind_time_minutes")
877 public Integer blindTimeMinutes;
878 @SerializedName("pulse_count")
879 public Integer pulseCount;
880 @SerializedName("operating_mode")
881 public Integer operatingMode;
882 public Boolean enabled;
885 public static class ShellyExtTemperature {
886 public static class ShellyShortTemp {
887 public Double tC; // temperature in deg C
888 public Double tF; // temperature in deg F
891 // Shelly 1/1PM have up to 3 sensors
892 // for whatever reasons it's not an array, but 3 independent elements
894 public ShellyShortTemp sensor1;
896 public ShellyShortTemp sensor2;
898 public ShellyShortTemp sensor3;
901 public static class ShellyExtHumidity {
902 public static class ShellyShortHum {
903 public Double hum; // Humidity reading of sensor 0, percent
906 // Shelly 1/1PM have up to 3 sensors
907 // for whatever reasons it's not an array, but 3 independent elements
909 public ShellyShortHum sensor1;
912 public static class ShellyADC {
913 public Double voltage;
916 public ShellySensorTmp tmp;
917 public ShellySensorHum hum;
918 public ShellySensorLux lux;
919 public ShellySensorAccel accel;
920 public ShellySensorBat bat;
921 @SerializedName("sensor")
922 public ShellySensorState sensor;
923 public Boolean smoke; // SHelly Smoke
924 public Boolean flood; // Shelly Flood: true = flood condition detected
925 @SerializedName("rain_sensor")
926 public Boolean rainSensor; // Shelly Flood: true=in rain mode
928 public Boolean motion; // Shelly Sense: true=motion detected
929 public Boolean charger; // Shelly Sense: true=charger connected
931 @SerializedName("act_reasons")
932 public List<Object> actReasons; // HT/Smoke/Flood: list of reasons which woke up the device
934 @SerializedName("sensor_error")
935 public String sensorError; // 1.5.7: Only displayed in case of error
937 // FW 1.7: Shelly Gas
938 @SerializedName("gas_sensor")
939 public ShellyStatusGasSensor gasSensor;
940 @SerializedName("concentration")
941 public ShellyStatusGasConcentration concentration;
942 public ArrayList<ShellyStatusValve> valves;
945 @SerializedName("connect_retries")
946 public Integer connectRetries;
947 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
949 // Shelly UNI FW 1.9+
950 public ArrayList<ShellyADC> adcs;
953 public static class ShellySettingsSmoke {
954 @SerializedName("temperature_units")
955 public String temperatureUnits; // Either 'C' or 'F'
956 @SerializedName("temperature_threshold")
957 public Integer temperatureThreshold; // Temperature delta (in configured degree units) which triggers an update
958 @SerializedName("sleep_mode_period")
959 public Integer sleepModePeriod; // Periodic update period in hours, between 1 and 24
963 // "gas_sensor":{"sensor_state":"normal","self_test_state":"not_completed","alarm_state":"none"},
964 // "concentration":{"ppm":0,"is_valid":true},
965 public static class ShellyStatusGasSensor {
966 @SerializedName("sensor_state")
967 public String sensorState;
968 @SerializedName("self_test_state")
969 public String selfTestState;
970 @SerializedName("alarm_state")
971 public String alarmState;
974 public static class ShellyStatusGasConcentration {
976 @SerializedName("is_valid")
977 public Boolean isValid;
980 public static class ShellyStatusValve {
981 public String state; // closed/opened/not_connected/failure/closing/opening/checking
984 public static class ShellySettingsLight {
985 public Integer red; // red brightness, 0..255, applies in mode="color"
986 public Integer green; // green brightness, 0..255, applies in mode="color"
987 public Integer blue; // blue brightness, 0..255, applies in mode="color"
988 public Integer white; // white brightness, 0..255, applies in mode="color"
989 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
990 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
991 public Integer brightness; // brightness, 0..100, applies in mode="white"
992 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
993 // Change, 3: Breath,
994 // 4: Flash, 5: On/Off Gradual, 6: Red/Green Change
995 @SerializedName("default_state")
996 public String defaultState; // one of on, off or last
997 @SerializedName("auto_on")
998 public Double autoOn; // see above
999 @SerializedName("auto_off")
1000 public Double autoOff; // see above
1002 public Integer dcpower; // RGW2:Set to true for 24 V power supply, false for 12 V
1006 public Boolean ison;
1009 public static class ShellySettingsNightMode { // FW1.5.7+
1010 public Integer enabled;
1011 @SerializedName("start_time")
1012 public String startTime;
1013 @SerializedName("end_time")
1014 public String endTime;
1015 public Integer brightness;
1018 public static class ShellyStatusLightChannel {
1019 public Boolean ison;
1020 public Double power;
1021 public Boolean overpower;
1022 @SerializedName("has_timer")
1023 public Boolean hasTimer;
1024 @SerializedName("timer_started")
1025 public Integer timerStarted;
1026 @SerializedName("timer_duration")
1027 public Integer timerDuration;
1028 @SerializedName("timer_remaining")
1029 public Integer timerRemaining;
1031 public Integer red; // red brightness, 0..255, applies in mode="color"
1032 public Integer green; // green brightness, 0..255, applies in mode="color"
1033 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1034 public Integer white; // white brightness, 0..255, applies in mode="color"
1035 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1036 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1037 public Integer brightness; // brightness, 0..100, applies in mode="white"
1038 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1039 // Change, 3: Breath,
1042 public static class ShellyStatusLight {
1043 public Boolean ison; // Whether output channel is on or off
1044 public Integer input;
1046 public ArrayList<ShellyStatusLightChannel> lights;
1047 public ArrayList<ShellySettingsMeter> meters;
1050 public static class ShellySenseKeyCode {
1051 String id; // ID of the stored IR code into Shelly Sense.
1052 String name; // Short description or name of the stored IR code.
1055 public static class ShellySendKeyList {
1056 @SerializedName("key_codes")
1057 public ArrayList<ShellySenseKeyCode> keyCodes;
1061 * Shelly Dimmer returns light[]. However, the structure doesn't match the lights[] of a Bulb/RGBW2.
1062 * The tag lights[] will be replaced with dimmers[] so this could be mapped to a different Gson structure.
1063 * The function requires that it's only called when the device is a dimmer - on get settings and get status
1065 * @param json Input Json as received by the API
1066 * @return Modified Json
1068 public static String fixDimmerJson(String json) {
1069 return !json.contains("\"lights\":[") ? json
1070 : json.replaceFirst(java.util.regex.Pattern.quote("\"lights\":["), "\"dimmers\":[");
1074 * Convert Shelly Button events into OH button states
1076 * @param eventType S/SS/SSS or L
1077 * @return OH button states
1079 public static String mapButtonEvent(String eventType) {
1080 // decode different codings
1082 // S/SS/SSS/L: CoAP for Button and xi3
1083 // shortpush/double_shortpush/triple_shortpush/longpush: REST
1084 switch (eventType) {
1086 return CommonTriggerEvents.RELEASED;
1088 case SHELLY_BTNEVENT_1SHORTPUSH:
1089 case SHELLY_EVENT_SHORTPUSH:
1090 return CommonTriggerEvents.SHORT_PRESSED;
1091 case SHELLY_BTNEVENT_2SHORTPUSH:
1092 case SHELLY_EVENT_DOUBLE_SHORTPUSH:
1093 return CommonTriggerEvents.DOUBLE_PRESSED;
1094 case SHELLY_BTNEVENT_3SHORTPUSH:
1095 case SHELLY_EVENT_TRIPLE_SHORTPUSH:
1096 return "TRIPLE_PRESSED";
1098 case SHELLY_BTNEVENT_LONGPUSH:
1099 case SHELLY_EVENT_LONGPUSH:
1100 return CommonTriggerEvents.LONG_PRESSED;
1101 case SHELLY_BTNEVENT_SHORTLONGPUSH:
1102 case SHELLY_EVENT_SHORT_LONGTPUSH:
1103 return "SHORT_LONG_PRESSED";
1104 case SHELLY_BTNEVENT_LONGSHORTPUSH:
1105 case SHELLY_EVENT_LONG_SHORTPUSH:
1106 return "LONG_SHORT_PRESSED";