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.core.thing.CommonTriggerEvents;
20 import com.google.gson.annotations.SerializedName;
23 * The {@link ShellyApiJsonDTO} is used for the JSon/GSon mapping
25 * @author Markus Michels - Initial contribution
27 public class ShellyApiJsonDTO {
28 public static final String SHELLY_NULL_URL = "null";
29 public static final String SHELLY_URL_DEVINFO = "/shelly";
30 public static final String SHELLY_URL_STATUS = "/status";
31 public static final String SHELLY_URL_SETTINGS = "/settings";
32 public static final String SHELLY_URL_SETTINGS_AP = "/settings/ap";
33 public static final String SHELLY_URL_SETTINGS_STA = "/settings/sta";
34 public static final String SHELLY_URL_SETTINGS_LOGIN = "/settings/sta";
35 public static final String SHELLY_URL_SETTINGS_CLOUD = "/settings/cloud";
36 public static final String SHELLY_URL_LIST_IR = "/ir/list";
37 public static final String SHELLY_URL_SEND_IR = "/ir/emit";
39 public static final String SHELLY_URL_SETTINGS_RELAY = "/settings/relay";
40 public static final String SHELLY_URL_STATUS_RELEAY = "/status/relay";
41 public static final String SHELLY_URL_CONTROL_RELEAY = "/relay";
43 public static final String SHELLY_URL_SETTINGS_EMETER = "/settings/emeter";
44 public static final String SHELLY_URL_STATUS_EMETER = "/emeter";
45 public static final String SHELLY_URL_DATA_EMETER = "/emeter/{0}/em_data.csv";
47 public static final String SHELLY_URL_CONTROL_ROLLER = "/roller";
48 public static final String SHELLY_URL_SETTINGS_ROLLER = "/settings/roller";
50 public static final String SHELLY_URL_SETTINGS_LIGHT = "/settings/light";
51 public static final String SHELLY_URL_STATUS_LIGHT = "/light";
52 public static final String SHELLY_URL_CONTROL_LIGHT = "/light";
54 public static final String SHELLY_URL_SETTINGS_DIMMER = "/settings/light";
57 // Action URLs according to the device type
59 public static final String SHELLY_EVENTURL_SUFFIX = "_url";
62 public static final String SHELLY_EVENT_BTN_ON = "btn_on";
63 public static final String SHELLY_EVENT_BTN_OFF = "btn_off";
64 public static final String SHELLY_EVENT_OUT_ON = "out_on";
65 public static final String SHELLY_EVENT_OUT_OFF = "out_off";
66 public static final String SHELLY_EVENT_SHORTPUSH = "shortpush";
67 public static final String SHELLY_EVENT_LONGPUSH = "longpush";
69 public static final String SHELLY_EVENT_DOUBLE_SHORTPUSH = "double_shortpush";
70 public static final String SHELLY_EVENT_TRIPLE_SHORTPUSH = "triple_shortpush";
71 public static final String SHELLY_EVENT_SHORT_LONGTPUSH = "shortpush_longpush";
72 public static final String SHELLY_EVENT_LONG_SHORTPUSH = "longpush_shortpush";
75 public static final String SHELLY_EVENT_BTN1_ON = "btn1_on";
76 public static final String SHELLY_EVENT_BTN1_OFF = "btn1_off";
77 public static final String SHELLY_EVENT_BTN2_ON = "btn2_on";
78 public static final String SHELLY_EVENT_BTN2_OFF = "btn2_off";
79 public static final String SHELLY_EVENT_SHORTPUSH1 = "btn1_shortpush";
80 public static final String SHELLY_EVENT_LONGPUSH1 = "btn1_longpush";
81 public static final String SHELLY_EVENT_SHORTPUSH2 = "btn2_shortpush";
82 public static final String SHELLY_EVENT_LONGPUSH2 = "btn2_longpush";
85 public static final String SHELLY_EVENT_ROLLER_OPEN = "roller_open";
86 public static final String SHELLY_EVENT_ROLLER_CLOSE = "roller_close";
87 public static final String SHELLY_EVENT_ROLLER_STOP = "roller_stop";
90 public static final String SHELLY_EVENT_SENSORREPORT = "report";
91 public static final String SHELLY_EVENT_DARK = "dark";
92 public static final String SHELLY_EVENT_TWILIGHT = "twilight";
93 public static final String SHELLY_EVENT_BRIGHT = "bright";
94 public static final String SHELLY_EVENT_FLOOD_DETECTED = "flood_detected";
95 public static final String SHELLY_EVENT_FLOOD_GONE = "flood_gone";
96 public static final String SHELLY_EVENT_VIBRATION = "vibration"; // DW 1.6.5+
97 public static final String SHELLY_EVENT_OPEN = "open"; // DW 1.6.5+
98 public static final String SHELLY_EVENT_CLOSE = "close"; // DW 1.6.5+
99 public static final String SHELLY_EVENT_TEMP_OVER = "temp_over"; // FW 1.7
100 public static final String SHELLY_EVENT_TEMP_UNDER = "temp_under"; // FW 1.7
103 public static final String SHELLY_EVENT_ALARM_MILD = "alarm_mild"; // DW 1.7+
104 public static final String SHELLY_EVENT_ALARM_HEAVY = "alarm_heavy"; // DW 1.7+
105 public static final String SHELLY_EVENT_ALARM_OFF = "alarm_off"; // DW 1.7+
110 public static final String SHELLY_BTNT_MOMENTARY = "momentary";
111 public static final String SHELLY_BTNT_MOM_ON_RELEASE = "momentary_on_release";
112 public static final String SHELLY_BTNT_ONE_BUTTON = "one_button";
113 public static final String SHELLY_BTNT_TWO_BUTTON = "dual_button";
114 public static final String SHELLY_BTNT_TOGGLE = "toggle";
115 public static final String SHELLY_BTNT_EDGE = "edge";
116 public static final String SHELLY_BTNT_DETACHED = "detached";
118 public static final String SHELLY_STATE_LAST = "last";
119 public static final String SHELLY_STATE_STOP = "stop";
121 public static final String SHELLY_INP_MODE_OPENCLOSE = "openclose";
122 public static final String SHELLY_OBSTMODE_DISABLED = "disabled";
123 public static final String SHELLY_SAFETYM_WHILEOPENING = "while_opening";
125 public static final String SHELLY_ALWD_TRIGGER_NONE = "none";
126 public static final String SHELLY_ALWD_ROLLER_TURN_OPEN = "open";
127 public static final String SHELLY_ALWD_ROLLER_TURN_CLOSE = "close";
128 public static final String SHELLY_ALWD_ROLLER_TURN_STOP = "stop";
131 public static final String SHELLY_APIERR_UNAUTHORIZED = "Unauthorized";
132 public static final String SHELLY_APIERR_TIMEOUT = "Timeout";
133 public static final String SHELLY_APIERR_NOT_CALIBRATED = "Not calibrated!";
135 // API device types / properties
136 public static final String SHELLY_CLASS_RELAY = "relay"; // Relay: relay mode
137 public static final String SHELLY_CLASS_ROLLER = "roller"; // Relay: roller mode
138 public static final String SHELLY_CLASS_LIGHT = "light"; // Bulb: color mode
139 public static final String SHELLY_CLASS_EMETER = "emeter"; // EM/EM3: emeter
141 public static final String SHELLY_API_ON = "on";
142 public static final String SHELLY_API_OFF = "off";
143 public static final String SHELLY_API_TRUE = "true";
144 public static final String SHELLY_API_FALSE = "false";
146 public static final String SHELLY_API_MODE = "mode";
147 public static final String SHELLY_MODE_RELAY = "relay"; // Relay: relay mode
148 public static final String SHELLY_MODE_ROLLER = "roller"; // Relay: roller mode
149 public static final String SHELLY_MODE_COLOR = "color"; // Bulb/RGBW2: color mode
150 public static final String SHELLY_MODE_WHITE = "white"; // Bulb/RGBW2: white mode
152 public static final String SHELLY_LED_STATUS_DISABLE = "led_status_disable";
153 public static final String SHELLY_LED_POWER_DISABLE = "led_power_disable";
155 public static final String SHELLY_API_STOPR_NORMAL = "normal";
156 public static final String SHELLY_API_STOPR_SAFETYSW = "safety_switch";
157 public static final String SHELLY_API_STOPR_OBSTACLE = "obstacle";
158 public static final String SHELLY_API_STOPR_OVERPOWER = "overpower";
160 public static final String SHELLY_TIMER_AUTOON = "auto_on";
161 public static final String SHELLY_TIMER_AUTOOFF = "auto_off";
162 public static final String SHELLY_TIMER_ACTIVE = "has_timer";
164 public static final String SHELLY_LIGHT_TURN = "turn";
165 public static final String SHELLY_LIGHT_DEFSTATE = "def_state";
166 public static final String SHELLY_LIGHTTIMER = "timer";
168 public static final String SHELLY_COLOR_RED = "red";
169 public static final String SHELLY_COLOR_BLUE = "blue";
170 public static final String SHELLY_COLOR_GREEN = "green";
171 public static final String SHELLY_COLOR_YELLOW = "yellow";
172 public static final String SHELLY_COLOR_WHITE = "white";
173 public static final String SHELLY_COLOR_GAIN = "gain";
174 public static final String SHELLY_COLOR_BRIGHTNESS = "brightness";
175 public static final String SHELLY_COLOR_TEMP = "temp";
176 public static final String SHELLY_COLOR_EFFECT = "effect";
178 public static final int SHELLY_MIN_ROLLER_POS = 0;
179 public static final int SHELLY_MAX_ROLLER_POS = 100;
180 public static final int SHELLY_MIN_BRIGHTNESS = 0;
181 public static final int SHELLY_MAX_BRIGHTNESS = 100;
182 public static final int SHELLY_MIN_GAIN = 0;
183 public static final int SHELLY_MAX_GAIN = 100;
184 public static final int SHELLY_MIN_COLOR = 0;
185 public static final int SHELLY_MAX_COLOR = 255;
186 public static final int SHELLY_DIM_STEPSIZE = 10;
188 // color temperature: 3000 = warm, 4750 = white, 6565 = cold; gain: 0..100
189 public static final int MIN_COLOR_TEMP_BULB = 3000;
190 public static final int MAX_COLOR_TEMP_BULB = 6500;
191 public static final int MIN_COLOR_TEMP_DUO = 2700;
192 public static final int MAX_COLOR_TEMP_DUO = 6500;
193 public static final int COLOR_TEMP_RANGE_BULB = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
194 public static final int COLOR_TEMP_RANGE_DUO = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
195 public static final double MIN_BRIGHTNESS = 0.0;
196 public static final double MAX_BRIGHTNESS = 100.0;
197 public static final double SATURATION_FACTOR = 2.55;
198 public static final double GAIN_FACTOR = SHELLY_MAX_GAIN / 100;
199 public static final double BRIGHTNESS_FACTOR = SHELLY_MAX_BRIGHTNESS / 100;
202 public static final String SHELLY_API_ILLUM_DARK = "dark";
203 public static final String SHELLY_API_ILLUM_TWILIGHT = "twilight";
204 public static final String SHELLY_API_ILLUM_BRIGHT = "bright";
205 public static final String SHELLY_API_DWSTATE_OPEN = "open";
206 public static final String SHELLY_API_DWSTATE_CLOSE = "close";
209 public static final String SHELLY_IR_CODET_STORED = "stored";
210 public static final String SHELLY_IR_CODET_PRONTO = "pronto";
211 public static final String SHELLY_IR_CODET_PRONTO_HEX = "pronto_hex";
214 public static final int SHELLY_MIN_EFFECT = 0;
215 public static final int SHELLY_MAX_EFFECT = 6;
218 public static final String SHELLY_BTNEVENT_1SHORTPUSH = "S";
219 public static final String SHELLY_BTNEVENT_2SHORTPUSH = "SS";
220 public static final String SHELLY_BTNEVENT_3SHORTPUSH = "SSS";
221 public static final String SHELLY_BTNEVENT_LONGPUSH = "L";
222 public static final String SHELLY_BTNEVENT_SHORTLONGPUSH = "SL";
223 public static final String SHELLY_BTNEVENT_LONGSHORTPUSH = "LS";
225 public static final String SHELLY_TEMP_CELSIUS = "C";
226 public static final String SHELLY_TEMP_FAHRENHEIT = "F";
228 public static class ShellySettingsDevice {
231 public String hostname;
234 @SerializedName("num_outputs")
235 public Integer numOutputs;
236 @SerializedName("num_meters")
237 public Integer numMeters;
238 @SerializedName("num_emeters")
239 public Integer numEMeters;
240 @SerializedName("num_rollers")
241 public Integer numRollers;
244 public static class ShellySettingsWiFiAp {
245 public Boolean enabled;
250 public static class ShellySettingsWiFiNetwork {
251 public Boolean enabled;
255 @SerializedName("ipv4_method")
256 public String ipv4Method;
263 public static class ShellySettingsMqtt {
264 public Boolean enabled;
265 public String server;
267 @SerializedName("reconnect_timeout_max")
268 public Double reconnectTimeoutMax;
269 @SerializedName("reconnect_timeout_min")
270 public Double reconnectTimeoutMin;
271 @SerializedName("clean_session")
272 public Boolean cleanSession;
273 @SerializedName("keep_alive")
274 public Integer keepAlive;
275 @SerializedName("will_topic")
276 public String willTopic;
277 @SerializedName("will_message")
278 public String willMessage;
279 @SerializedName("max_qos")
280 public Integer maxQOS;
281 public Boolean retain;
282 @SerializedName("update_period")
283 public Integer updatePeriod;
286 public static class ShellySettingsCoiot { // FW 1.6+
287 @SerializedName("update_period")
288 public Integer updatePeriod;
291 public static class ShellySettingsSntp {
292 public String server;
295 public static class ShellySettingsLogin {
296 public Boolean enabled;
297 public Boolean unprotected;
298 public String username;
299 public String password;
302 public static class ShellySettingsBuildInfo {
303 @SerializedName("build_id")
304 public String buildId;
305 @SerializedName("build_timestamp")
306 public String buildTimestamp;
307 @SerializedName("build_version")
308 public String buildVersion;
311 public static class ShellyStatusCloud {
312 public Boolean enabled;
313 public Boolean connected;
316 public static class ShellyStatusMqtt {
317 public Boolean connected;
320 public static class ShellySettingsHwInfo {
321 @SerializedName("hw_revision")
322 public String hwRevision;
323 @SerializedName("batch_id")
324 public Integer batchId;
327 public static class ShellySettingsScheduleRules {
330 public static class ShellySettingsRelay {
333 public Boolean overpower;
334 @SerializedName("default_state")
335 public String defaultState; // Accepted values: off, on, last, switch
336 @SerializedName("btn_type")
337 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
338 @SerializedName("btn1_type") // Shelly 1L
339 public String btnType1;
340 @SerializedName("btn2_type") // Shelly 1L
341 public String btnType2;
342 @SerializedName("has_timer")
343 public Boolean hasTimer; // Whether a timer is currently armed for this channel
344 @SerializedName("auto_on")
345 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
346 @SerializedName("auto_off")
347 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
348 @SerializedName("btn_on_url")
349 public String btnOnUrl; // input is activated
350 @SerializedName("btnOffUrl")
351 public String btnOffUrl; // input is deactivated
352 @SerializedName("out_on_url")
353 public String outOnUrl; // output is activated
354 @SerializedName("out_off_url")
355 public String outOffUrl; // output is deactivated
356 @SerializedName("roller_open_url")
357 public String rollerOpenUrl; // to access when roller reaches open position
358 @SerializedName("roller_close_url")
359 public String rollerCloseUrl; // to access when roller reaches close position
360 @SerializedName("roller_stop_url")
361 public String rollerStopUrl; // to access when roller stopped
362 @SerializedName("longpush_url")
363 public String pushLongUrl; // to access when roller stopped
364 @SerializedName("shortpush_url")
365 public String pushShortUrl; // to access when roller stopped
367 public Boolean schedule;
368 // ArrayList<ShellySettingsScheduleRules> schedule_rules;
371 public static class ShellySettingsDimmer {
372 public String name; // unique name of the device
373 public Boolean ison; // true: output is ON
374 @SerializedName("default_state")
375 public String defaultState; // Accepted values: off, on, last, switch
376 @SerializedName("auto_on")
377 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
378 @SerializedName("auto_off")
379 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
380 @SerializedName("btn1_on_url")
381 public String btn1OnUrl; // URL to access when SW input is activated
382 @SerializedName("btn1_off_url")
383 public String btn1OffUrl; // URL to access when SW input is deactivated
384 @SerializedName("btn2_on_url")
385 public String btn2OnUrl; // URL to access when SW input is activated
386 @SerializedName("btn2_off_url")
387 public String btn2OoffUrl; // URL to access when SW input is deactivated
388 @SerializedName("out_on_url")
389 public String outOnUrl; // URL to access when output is activated
390 @SerializedName("out_off_url")
391 public String outOffUrl; // URL to access when output is deactivated
392 @SerializedName("longpush_url")
393 public String pushLongUrl; // long push button event
394 @SerializedName("shortpush_url")
395 public String pushShortUrl; // short push button event
396 @SerializedName("btn_type")
397 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
398 @SerializedName("btn1_type")
399 public String btnType1; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
400 @SerializedName("btn2_type")
401 public String btnType2; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
402 @SerializedName("swap_inputs")
403 public Integer swapInputs; // 0=no
406 public static class ShellySettingsRoller {
407 public Double maxtime;
408 @SerializedName("maxtime_open")
409 public Double maxtimeOpen;
410 @SerializedName("maxtime_close")
411 public Double maxtimeClose;
412 @SerializedName("default_state")
413 public String defaultState; // see SHELLY_STATE_xxx
415 @SerializedName("swap_inputs")
416 public Boolean swapInputs;
417 @SerializedName("input_mode")
418 public String inputMode; // see SHELLY_INP_MODE_OPENCLOSE
419 @SerializedName("button_type")
420 public String buttonType; // // see SHELLY_BTNT_xxx
421 @SerializedName("btn_Reverse")
422 public Integer btnReverse;
425 @SerializedName("is_valid")
426 public Boolean isValid;
427 @SerializedName("safety_switch")
428 public Boolean safetySwitch;
429 public Boolean schedule;
430 // ArrayList<ShellySettingsScheduleRules> schedule_rules; // not used for now
431 @SerializedName("obstacle_mode")
432 public String obstaclMode; // SHELLY_OBSTMODE_
433 @SerializedName("obstacle_action")
434 public String obstacleAction; // see SHELLY_STATE_xxx
435 @SerializedName("obstacle_power")
436 public Integer obstaclePower;
437 @SerializedName("obstacle_delay")
438 public Integer obstacleDelay;
439 @SerializedName("safety_mode")
440 public String safetyMode; // see SHELLY_SAFETYM_xxx
441 @SerializedName("safety_action")
442 public String safetyAction; // see SHELLY_STATE_xxx
443 @SerializedName("safety_allowed_on_trigger")
444 public String safetyAllowedOnTrigger; // see SHELLY_ALWD_TRIGGER_xxx
445 @SerializedName("off_power")
446 public Integer offPower;
447 public Boolean positioning;
450 public static class ShellySettingsRgbwLight {
452 public Boolean ison; // true: output is ON
453 public Integer brightness;
454 public Integer transition;
455 public String default_state;
456 @SerializedName("auto_on")
457 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
458 @SerializedName("auto_off")
459 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
460 public Boolean schedule;
461 @SerializedName("btn_type")
462 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
463 @SerializedName("btn_reverse")
464 public Integer btnReverse; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
465 @SerializedName("out_on_url")
466 public String outOnUrl; // output is activated
467 @SerializedName("out_off_url")
468 public String outOffUrl; // output is deactivated
471 public static class ShellyFavPos { // FW 1.9.2+ in roller mode
476 public static class ShellyInputState {
477 public Integer input;
481 @SerializedName("event_cnt")
482 public Integer eventCount;
485 public static class ShellySettingsMeter {
486 @SerializedName("is_valid")
487 public Boolean isValid;
489 public Double[] counters = { 0.0, 0.0, 0.0 };
491 public Long timestamp;
494 public static class ShellySettingsEMeter { // ShellyEM meter
495 @SerializedName("is_valid")
496 public Boolean isValid; // Whether the associated meter is functioning properly
497 public Double power; // Instantaneous power, Watts
498 public Double reactive; // Instantaneous reactive power, Watts
499 public Double voltage; // RMS voltage, Volts
500 public Double total; // Total consumed energy, Wh
501 @SerializedName("total_returned")
502 public Double totalReturned; // Total returned energy, Wh
504 public Double pf; // 3EM
505 public Double current; // 3EM
508 public static class ShellySettingsUpdate {
509 public String status;
510 @SerializedName("has_update")
511 public Boolean hasUpdate;
512 @SerializedName("new_version")
513 public String newVersion;
514 @SerializedName("old_version")
515 public String oldVersion;
518 public static class ShellySettingsGlobal {
519 // https://shelly-api-docs.shelly.cloud/#shelly1pm-settings
520 public ShellySettingsDevice device;
521 @SerializedName("wifi_ap")
522 public ShellySettingsWiFiAp wifiAp;
523 @SerializedName("wifi_sta")
524 public ShellySettingsWiFiNetwork wifiSta;
525 @SerializedName("wifi_sta1")
526 public ShellySettingsWiFiNetwork wifiSta1;
527 // public ShellySettingsMqtt mqtt; // not used for now
528 // public ShellySettingsSntp sntp; // not used for now
529 public ShellySettingsCoiot coiot; // Firmware 1.6+
530 public ShellySettingsLogin login;
531 @SerializedName("pin_code")
532 public String pinCode;
533 @SerializedName("coiot_execute_enable")
534 public Boolean coiotExecuteEnable;
536 public Boolean discoverable; // FW 1.6+
538 @SerializedName("build_info")
539 ShellySettingsBuildInfo buildInfo;
540 ShellyStatusCloud cloud;
541 @SerializedName("sleep_mode")
542 public ShellySensorSleepMode sleepMode; // FW 1.6
544 public String timezone;
547 public Boolean tzautodetect;
549 // @SerializedName("tz_utc_offset")
550 // public Integer tzUTCOoffset; // FW 1.6+
551 // @SerializedName("tz_dst")
552 // public Boolean tzDdst; // FW 1.6+
553 // @SerializedName("tz_dst_auto")
554 // public Boolean tzDstAuto; // FW 1.6+
555 // public Long unixtime; // FW 1.6+
557 public ShellySettingsHwInfo hwinfo;
559 @SerializedName("max_power")
560 public Double maxPower;
562 public ArrayList<ShellySettingsRelay> relays;
563 public ArrayList<ShellySettingsDimmer> dimmers;
564 public ArrayList<ShellySettingsRgbwLight> lights;
565 public ArrayList<ShellySettingsEMeter> emeters;
566 public ArrayList<ShellySettingsInput> inputs; // ix3
568 @SerializedName("temperature_units")
569 public String temperatureUnits; // Either'C'or'F'
571 @SerializedName("led_status_disable")
572 public Boolean ledStatusDisable; // PlugS only Disable LED indication for network
574 @SerializedName("led_power_disable")
575 public Boolean ledPowerDisable; // PlugS only Disable LED indication for network
577 @SerializedName("light_sensor")
578 public String lightSensor; // Sense: sensor type
579 @SerializedName("rain_sensor")
580 public Boolean rainSensor; // Flood: true=in rain mode
582 // FW 1.5.7: Door Window
583 @SerializedName("dark_treshold")
584 public Integer darkTreshold; // Illumination definition for "dark" in lux
585 @SerializedName("twilight_treshold")
586 public Integer twiLightTreshold; // Illumination definition for "twilight" in lux
587 @SerializedName("dark_url")
588 public String darkUrl; // URL to report to when luminance <= dark_threshold
589 @SerializedName("twilight_url")
590 public String twiLightUrl; // URL reports when luminance > dark_threshold AND luminance <=
591 @SerializedName("close_url")
592 public String closeUrl; // URL reports when DW contact is closed FW 1.6.5+
593 @SerializedName("vibration_url")
594 public String vibrationUrl; // URL reports when DW detects vibration FW 1.6.5+
596 // @SerializedName("tilt_enabled")
597 // public Boolean tiltEnabled; // Whether tilt monitoring is activated
598 // @SerializedName("tilt_calibrated")
599 // public Boolean tiltCalibrated; // Whether calibration data is valid
600 // @SerializedName("vibration_enabled")
601 // public Boolean vibrationEnabled; // Whether vibration monitoring is activated
602 // @SerializedName("reverse_open_close")
603 // public Boolean reverseOpenClose; // Whether to reverse which position the sensor consideres "open"
606 @SerializedName("set_volume")
607 public Integer volume; // Speaker volume for alarm
608 @SerializedName("alarm_off_url")
609 public String alarmOffUrl; // URL reports when alarm went off
610 @SerializedName("alarm_mild_url")
611 public String alarmMidUrl; // URL reports middle alarm
612 @SerializedName("alarm_heavy_url")
613 public String alarmHeavyfUrl; // URL reports heavy alarm
615 // Roller with FW 1.9.2+
616 @SerializedName("favorites_enabled")
617 public Boolean favoritesEnabled;
618 public ArrayList<ShellyFavPos> favorites;
621 public static class ShellySettingsAttributes {
622 @SerializedName("device_type")
623 public String deviceType; // Device model identifier
624 @SerializedName("device_mac")
625 public String deviceMac; // MAC address of the device in hexadecimal
626 @SerializedName("wifi_ap")
627 public String wifiAp; // WiFi access poInteger configuration, see /settings/ap for details
628 @SerializedName("wifi_sta")
629 public String wifiSta; // WiFi client configuration. See /settings/sta for details
630 public String login; // credentials used for HTTP Basic authentication for the REST interface. If
631 // enabled is true clients must include an Authorization: Basic ... HTTP header with valid
632 // credentials when performing TP requests.
633 public String name; // unique name of the device.
634 public String fw; // current FW version
637 public static class ShellySettingsStatus {
638 public String name; // FW 1.8: Symbolic Device name is configurable
640 @SerializedName("wifi_sta")
641 public ShellySettingsWiFiNetwork wifiSta; // WiFi client configuration. See /settings/sta for details
644 public Integer serial;
645 @SerializedName("has_update")
646 public Boolean hasUpdate;
648 public Boolean discoverable; // FW 1.6+
649 @SerializedName("cfg_changed_cnt")
650 public Integer cfgChangedCount; // FW 1.8
652 public ArrayList<ShellySettingsRelay> relays;
653 public ArrayList<ShellySettingsRoller> rollers;
654 public Integer input; // RGBW2 has no JSON array
655 public ArrayList<ShellyInputState> inputs;
656 public ArrayList<ShellySettingsLight> lights;
657 // @SerializedName("night_mode") // FW 1.5.7+
658 // public ShellySettingsNightMode nightMode;
659 public ArrayList<ShellyShortLightStatus> dimmers;
660 public ArrayList<ShellySettingsMeter> meters;
661 public ArrayList<ShellySettingsEMeter> emeters;
663 // Internal device temp
664 public ShellyStatusSensor.ShellySensorTmp tmp; // Shelly 1PM
665 public Double temperature; // Shelly 2.5
666 public Boolean overtemperature;
668 // Shelly Dimmer only
669 public Boolean loaderror;
670 public Boolean overload;
672 public ShellySettingsUpdate update;
673 @SerializedName("ram_total")
674 public Long ramTotal;
675 @SerializedName("ram_free")
677 @SerializedName("fs_size")
679 @SerializedName("fs_free")
686 public static class ShellySettingsInput {
687 @SerializedName("btn_type")
688 public String btnType;
690 // attributes not yet processed
691 // public String name;
692 // @SerializedName("btn_reverse")
693 // public Integer btnReverse;
694 // @SerializedName("btn_on_url")
695 // public String btnOnUrl;
696 // @SerializedName("btn_off_url")
697 // public String btnOffUrl;
698 // @SerializedName("shortpush_url")
699 // public String shortpushUrl;
700 // @SerializedName("longpush_url")
701 // public String longpushUrl;
702 // @SerializedName("double_shortpush_url")
703 // public String doubleShortpushUrl;
704 // @SerializedName("triple_shortpush_url")
705 // public String tripleShortpushUrl;
706 // @SerializedName("shortpush_longpush_url")
707 // public String shortpushLongpushUrl;
708 // @SerializedName("longpush_shortpush_url")
709 // public String longpushShortpushUrl;
712 public static class ShellyControlRelay {
713 // https://shelly-api-docs.shelly.cloud/#shelly1-1pm-settings-relay-0
714 @SerializedName("is_valid")
715 public Boolean isValid;
716 @SerializedName("has_timer")
717 public Boolean hasTimer; // Whether a timer is currently armed for this channel
718 @SerializedName("timer_remaining")
719 public Integer timerRemaining; // FW 1.6+
720 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
722 public String turn; // Accepted values are on and off. This will turn ON/OFF the respective output
723 // channel when request is sent .
724 public Integer timer; // A one-shot flip-back timer in seconds.
727 public static class ShellyShortStatusRelay {
728 public String name; // FW 1.8+: Channel could now have a logical name
729 @SerializedName("is_valid")
730 public Boolean isValid;
731 public Boolean ison; // Whether output channel is on or off
732 @SerializedName("has_timer")
733 public Boolean hasTimer; // Whether a timer is currently armed for this channel
734 @SerializedName("timer_remaining")
735 public Integer timerRemaining;
736 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
737 public Double temperature; // Internal device temperature
738 public Boolean overtemperature; // Device over heated
741 public static class ShellyShortLightStatus {
742 public Boolean ison; // Whether output channel is on or off
743 public String mode; // color or white - valid only for Bulb and RGBW2 even Dimmer returns it also
744 public Integer brightness; // brightness: 0.100%
745 // @SerializedName("has_timer")
746 // public Boolean hasTimer; // Whether a timer is currently armed for this channel
747 // @SerializedName("timer_remaining")
748 // public Integer timerRemaining;
749 // public Integer wgite;
750 // public Integer temp; // light temp
753 public static class ShellyStatusRelay {
754 public String name; // FW 1.8: Symbolic channel name is configurable
756 @SerializedName("wifi_sta")
757 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
758 // public ShellyStatusCloud cloud; // Cloud status
759 // public ShellyStatusMqtt mqtt; // mqtt status
760 public ShellySettingsCoiot coiot; // Firmware 1.6+
761 // public String time; // current time
762 public Integer serial;
763 public String mac; // MAC
764 public ArrayList<ShellyShortStatusRelay> relays; // relay status
765 public ArrayList<ShellySettingsMeter> meters; // current meter value
766 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
768 @SerializedName("ext_temperature")
769 public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
770 @SerializedName("ext_humidity")
771 public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
773 public Double temperature; // device temp acc. on the selected temp unit
774 public ShellyStatusSensor.ShellySensorTmp tmp;
776 @SerializedName("has_update")
777 public Boolean hasUpdate; // If a newer firmware version is available
778 public ShellySettingsUpdate update; // /status/firmware value
780 @SerializedName("ram_total")
781 public Integer ramTotal; // Total and available amount of system memory in bytes
782 @SerializedName("ram_free")
783 public Integer ramFree;
784 @SerializedName("fs_size")
785 public Integer fsSize;
786 @SerializedName("fs_free")
787 public Integer fsFree; // Total and available amount of file system space in bytes
788 public Integer uptime; // econds elapsed since boot
791 public static class ShellyStatusDimmer {
792 @SerializedName("wifi_sta")
793 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
794 // public ShellyStatusCloud cloud; // Cloud status
795 // public ShellyStatusMqtt mqtt; // mqtt status
796 public String time; // current time
797 public Integer serial;
798 public String mac; // MAC
799 public ArrayList<ShellyShortLightStatus> lights; // relay status
800 public ArrayList<ShellySettingsMeter> meters; // current meter value
802 public ShellyStatusSensor.ShellySensorTmp tmp;
803 public Boolean overtemperature;
805 public Boolean loaderror;
806 public Boolean overload;
808 @SerializedName("has_update")
809 public Boolean hasUpdate; // If a newer firmware version is available
810 public ShellySettingsUpdate update; // /status/firmware value
812 @SerializedName("ram_total")
813 public Integer ramTotal; // Total and available amount of system memory in
815 @SerializedName("ram_free")
816 public Integer ramFree;
817 @SerializedName("fs_size")
818 public Integer fsSize;
819 @SerializedName("fs_free")
820 public Integer fsFree; // Total and available amount of file system space in bytes
821 public Integer uptime; // seconds elapsed since boot
824 public static class ShellyControlRoller {
825 public String name; // FW 1.8: Symbolic name is configurable
827 @SerializedName("roller_pos")
828 public Integer rollerPos; // number Desired position in percent
829 public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
830 // value of maxtime in /settings/roller/N will be used.
831 public String state; // One of stop, open, close
832 public Double power; // Current power consumption in Watts
833 @SerializedName("is_valid")
834 public Boolean isValid; // If the power meter functions properly
835 @SerializedName("safety_switch")
836 public Boolean safetySwitch; // Whether the safety input is currently triggered
837 public Boolean overtemperature;
838 @SerializedName("stop_reason")
839 public String stopReason; // Last cause for stopping: normal, safety_switch, obstacle
840 @SerializedName("last_direction")
841 public String lastDirection; // Last direction of motion, open or close
842 public Boolean calibrating;
843 public Boolean positioning; // true when calibration was performed
844 @SerializedName("current_pos")
845 public Integer currentPos; // current position 0..100, 100=open
848 public class ShellySensorSleepMode {
849 public Integer period;
853 public static class ShellyStatusSensor {
854 // https://shelly-api-docs.shelly.cloud/#h-amp-t-settings
855 public static class ShellySensorTmp {
856 public Double value; // Temperature in configured unites
857 public String units; // 'C' or 'F'
858 public Double tC; // temperature in deg C
859 public Double tF; // temperature in deg F
860 @SerializedName("is_valid")
861 public Boolean isValid; // whether the internal sensor is operating properly
864 public static class ShellySensorHum {
865 public Double value; // relative humidity in %
868 public static class ShellySensorBat {
869 public Double value; // estimated remaining battery capacity in %
870 public Double voltage; // battery voltage
873 // Door/Window sensor
874 public static class ShellySensorState {
875 @SerializedName("is_valid")
876 public Boolean isValid; // whether the internal sensor is operating properly
877 public String state; // Shelly Door/Window
880 public Boolean motion;
881 public Boolean vibration;
882 @SerializedName("timestamp")
883 public Long motionTimestamp;
884 @SerializedName("active")
885 public Boolean motionActive;
888 public static class ShellySensorLux {
889 @SerializedName("is_valid")
890 public Boolean isValid; // whether the internal sensor is operating properly
893 public String illumination;
896 public static class ShellySensorAccel {
897 public Integer tilt; // Tilt in °
898 public Integer vibration; // Whether vibration is detected
901 public static class ShellyExtTemperature {
902 public static class ShellyShortTemp {
903 public Double tC; // temperature in deg C
904 public Double tF; // temperature in deg F
907 // Shelly 1/1PM have up to 3 sensors
908 // for whatever reasons it's not an array, but 3 independent elements
910 public ShellyShortTemp sensor1;
912 public ShellyShortTemp sensor2;
914 public ShellyShortTemp sensor3;
917 public static class ShellyExtHumidity {
918 public static class ShellyShortHum {
919 public Double hum; // Humidity reading of sensor 0, percent
922 // Shelly 1/1PM have up to 3 sensors
923 // for whatever reasons it's not an array, but 3 independent elements
925 public ShellyShortHum sensor1;
928 public static class ShellyADC {
929 public Double voltage;
932 public ShellySensorTmp tmp;
933 public ShellySensorHum hum;
934 public ShellySensorLux lux;
935 public ShellySensorAccel accel;
936 public ShellySensorBat bat;
937 @SerializedName("sensor")
938 public ShellySensorState sensor;
939 public Boolean smoke; // SHelly Smoke
940 public Boolean flood; // Shelly Flood: true = flood condition detected
941 @SerializedName("rain_sensor")
942 public Boolean rainSensor; // Shelly Flood: true=in rain mode
944 public Boolean motion; // Shelly Sense: true=motion detected
945 public Boolean charger; // Shelly Sense: true=charger connected
946 @SerializedName("external_power")
947 public Integer externalPower; // H&T FW 1.6, seems to be the same like charger for the Sense
949 @SerializedName("act_reasons")
950 public List<Object> actReasons; // HT/Smoke/Flood: list of reasons which woke up the device
952 @SerializedName("sensor_error")
953 public String sensorError; // 1.5.7: Only displayed in case of error
955 // FW 1.7: Shelly Gas
956 @SerializedName("gas_sensor")
957 public ShellyStatusGasSensor gasSensor;
958 @SerializedName("concentration")
959 public ShellyStatusGasConcentration concentration;
960 public ArrayList<ShellyStatusValve> valves;
963 @SerializedName("connect_retries")
964 public Integer connectRetries;
965 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
967 // Shelly UNI FW 1.9+
968 public ArrayList<ShellyADC> adcs;
971 public static class ShellySettingsSmoke {
972 @SerializedName("temperature_units")
973 public String temperatureUnits; // Either 'C' or 'F'
974 @SerializedName("temperature_threshold")
975 public Integer temperatureThreshold; // Temperature delta (in configured degree units) which triggers an update
976 @SerializedName("sleep_mode_period")
977 public Integer sleepModePeriod; // Periodic update period in hours, between 1 and 24
981 // "gas_sensor":{"sensor_state":"normal","self_test_state":"not_completed","alarm_state":"none"},
982 // "concentration":{"ppm":0,"is_valid":true},
983 public static class ShellyStatusGasSensor {
984 @SerializedName("sensor_state")
985 public String sensorState;
986 @SerializedName("self_test_state")
987 public String selfTestState;
988 @SerializedName("alarm_state")
989 public String alarmState;
992 public static class ShellyStatusGasConcentration {
994 @SerializedName("is_valid")
995 public Boolean isValid;
998 public static class ShellyStatusValve {
999 public String state; // closed/opened/not_connected/failure/closing/opening/checking
1002 public static class ShellySettingsLight {
1003 public Integer red; // red brightness, 0..255, applies in mode="color"
1004 public Integer green; // green brightness, 0..255, applies in mode="color"
1005 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1006 public Integer white; // white brightness, 0..255, applies in mode="color"
1007 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1008 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1009 public Integer brightness; // brightness, 0..100, applies in mode="white"
1010 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1011 // Change, 3: Breath,
1012 // 4: Flash, 5: On/Off Gradual, 6: Red/Green Change
1013 @SerializedName("default_state")
1014 public String defaultState; // one of on, off or last
1015 @SerializedName("auto_on")
1016 public Double autoOn; // see above
1017 @SerializedName("auto_off")
1018 public Double autoOff; // see above
1020 public Integer dcpower; // RGW2:Set to true for 24 V power supply, false for 12 V
1024 public Boolean ison;
1027 public static class ShellySettingsNightMode { // FW1.5.7+
1028 public Integer enabled;
1029 @SerializedName("start_time")
1030 public String startTime;
1031 @SerializedName("end_time")
1032 public String endTime;
1033 public Integer brightness;
1036 public static class ShellyStatusLightChannel {
1037 public Boolean ison;
1038 public Double power;
1039 public Boolean overpower;
1040 @SerializedName("has_timer")
1041 public Boolean hasTimer;
1042 @SerializedName("timer_started")
1043 public Integer timerStarted;
1044 @SerializedName("timer_duration")
1045 public Integer timerDuration;
1046 @SerializedName("timer_remaining")
1047 public Integer timerRemaining;
1049 public Integer red; // red brightness, 0..255, applies in mode="color"
1050 public Integer green; // green brightness, 0..255, applies in mode="color"
1051 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1052 public Integer white; // white brightness, 0..255, applies in mode="color"
1053 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1054 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1055 public Integer brightness; // brightness, 0..100, applies in mode="white"
1056 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1057 // Change, 3: Breath,
1060 public static class ShellyStatusLight {
1061 public Boolean ison; // Whether output channel is on or off
1062 public Integer input;
1064 public ArrayList<ShellyStatusLightChannel> lights;
1065 public ArrayList<ShellySettingsMeter> meters;
1068 public static class ShellySenseKeyCode {
1069 String id; // ID of the stored IR code into Shelly Sense.
1070 String name; // Short description or name of the stored IR code.
1073 public static class ShellySendKeyList {
1074 @SerializedName("key_codes")
1075 public ArrayList<ShellySenseKeyCode> keyCodes;
1079 * Shelly Dimmer returns light[]. However, the structure doesn't match the lights[] of a Bulb/RGBW2.
1080 * The tag lights[] will be replaced with dimmers[] so this could be mapped to a different Gson structure.
1081 * The function requires that it's only called when the device is a dimmer - on get settings and get status
1083 * @param json Input Json as received by the API
1084 * @return Modified Json
1086 public static String fixDimmerJson(String json) {
1087 return !json.contains("\"lights\":[") ? json
1088 : json.replaceFirst(java.util.regex.Pattern.quote("\"lights\":["), "\"dimmers\":[");
1092 * Convert Shelly Button events into OH button states
1094 * @param eventType S/SS/SSS or L
1095 * @return OH button states
1097 public static String mapButtonEvent(String eventType) {
1098 // decode different codings
1100 // S/SS/SSS/L: CoAP for Button and xi3
1101 // shortpush/double_shortpush/triple_shortpush/longpush: REST
1102 switch (eventType) {
1104 return CommonTriggerEvents.RELEASED;
1106 case SHELLY_BTNEVENT_1SHORTPUSH:
1107 case SHELLY_EVENT_SHORTPUSH:
1108 return CommonTriggerEvents.SHORT_PRESSED;
1109 case SHELLY_BTNEVENT_2SHORTPUSH:
1110 case SHELLY_EVENT_DOUBLE_SHORTPUSH:
1111 return CommonTriggerEvents.DOUBLE_PRESSED;
1112 case SHELLY_BTNEVENT_3SHORTPUSH:
1113 case SHELLY_EVENT_TRIPLE_SHORTPUSH:
1114 return "TRIPLE_PRESSED";
1116 case SHELLY_BTNEVENT_LONGPUSH:
1117 case SHELLY_EVENT_LONGPUSH:
1118 return CommonTriggerEvents.LONG_PRESSED;
1119 case SHELLY_BTNEVENT_SHORTLONGPUSH:
1120 case SHELLY_EVENT_SHORT_LONGTPUSH:
1121 return "SHORT_LONG_PRESSED";
1122 case SHELLY_BTNEVENT_LONGSHORTPUSH:
1123 case SHELLY_EVENT_LONG_SHORTPUSH:
1124 return "LONG_SHORT_PRESSED";