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";
38 public static final String SHELLY_URL_RESTART = "/reboot";
40 public static final String SHELLY_URL_SETTINGS_RELAY = "/settings/relay";
41 public static final String SHELLY_URL_STATUS_RELEAY = "/status/relay";
42 public static final String SHELLY_URL_CONTROL_RELEAY = "/relay";
44 public static final String SHELLY_URL_SETTINGS_EMETER = "/settings/emeter";
45 public static final String SHELLY_URL_STATUS_EMETER = "/emeter";
46 public static final String SHELLY_URL_DATA_EMETER = "/emeter/{0}/em_data.csv";
48 public static final String SHELLY_URL_CONTROL_ROLLER = "/roller";
49 public static final String SHELLY_URL_SETTINGS_ROLLER = "/settings/roller";
51 public static final String SHELLY_URL_SETTINGS_LIGHT = "/settings/light";
52 public static final String SHELLY_URL_STATUS_LIGHT = "/light";
53 public static final String SHELLY_URL_CONTROL_LIGHT = "/light";
55 public static final String SHELLY_URL_SETTINGS_DIMMER = "/settings/light";
58 // Action URLs according to the device type
60 public static final String SHELLY_EVENTURL_SUFFIX = "_url";
63 public static final String SHELLY_EVENT_BTN_ON = "btn_on";
64 public static final String SHELLY_EVENT_BTN_OFF = "btn_off";
65 public static final String SHELLY_EVENT_OUT_ON = "out_on";
66 public static final String SHELLY_EVENT_OUT_OFF = "out_off";
67 public static final String SHELLY_EVENT_SHORTPUSH = "shortpush";
68 public static final String SHELLY_EVENT_LONGPUSH = "longpush";
70 public static final String SHELLY_EVENT_DOUBLE_SHORTPUSH = "double_shortpush";
71 public static final String SHELLY_EVENT_TRIPLE_SHORTPUSH = "triple_shortpush";
72 public static final String SHELLY_EVENT_SHORT_LONGTPUSH = "shortpush_longpush";
73 public static final String SHELLY_EVENT_LONG_SHORTPUSH = "longpush_shortpush";
76 public static final String SHELLY_EVENT_BTN1_ON = "btn1_on";
77 public static final String SHELLY_EVENT_BTN1_OFF = "btn1_off";
78 public static final String SHELLY_EVENT_BTN2_ON = "btn2_on";
79 public static final String SHELLY_EVENT_BTN2_OFF = "btn2_off";
80 public static final String SHELLY_EVENT_SHORTPUSH1 = "btn1_shortpush";
81 public static final String SHELLY_EVENT_LONGPUSH1 = "btn1_longpush";
82 public static final String SHELLY_EVENT_SHORTPUSH2 = "btn2_shortpush";
83 public static final String SHELLY_EVENT_LONGPUSH2 = "btn2_longpush";
86 public static final String SHELLY_EVENT_ROLLER_OPEN = "roller_open";
87 public static final String SHELLY_EVENT_ROLLER_CLOSE = "roller_close";
88 public static final String SHELLY_EVENT_ROLLER_STOP = "roller_stop";
91 public static final String SHELLY_EVENT_SENSORREPORT = "report";
92 public static final String SHELLY_EVENT_DARK = "dark";
93 public static final String SHELLY_EVENT_TWILIGHT = "twilight";
94 public static final String SHELLY_EVENT_BRIGHT = "bright";
95 public static final String SHELLY_EVENT_FLOOD_DETECTED = "flood_detected";
96 public static final String SHELLY_EVENT_FLOOD_GONE = "flood_gone";
97 public static final String SHELLY_EVENT_VIBRATION = "vibration"; // DW 1.6.5+
98 public static final String SHELLY_EVENT_OPEN = "open"; // DW 1.6.5+
99 public static final String SHELLY_EVENT_CLOSE = "close"; // DW 1.6.5+
100 public static final String SHELLY_EVENT_TEMP_OVER = "temp_over"; // FW 1.7
101 public static final String SHELLY_EVENT_TEMP_UNDER = "temp_under"; // FW 1.7
104 public static final String SHELLY_EVENT_ALARM_MILD = "alarm_mild"; // DW 1.7+
105 public static final String SHELLY_EVENT_ALARM_HEAVY = "alarm_heavy"; // DW 1.7+
106 public static final String SHELLY_EVENT_ALARM_OFF = "alarm_off"; // DW 1.7+
111 public static final String SHELLY_BTNT_MOMENTARY = "momentary";
112 public static final String SHELLY_BTNT_MOM_ON_RELEASE = "momentary_on_release";
113 public static final String SHELLY_BTNT_ONE_BUTTON = "one_button";
114 public static final String SHELLY_BTNT_TWO_BUTTON = "dual_button";
115 public static final String SHELLY_BTNT_TOGGLE = "toggle";
116 public static final String SHELLY_BTNT_EDGE = "edge";
117 public static final String SHELLY_BTNT_DETACHED = "detached";
119 public static final String SHELLY_STATE_LAST = "last";
120 public static final String SHELLY_STATE_STOP = "stop";
122 public static final String SHELLY_INP_MODE_OPENCLOSE = "openclose";
123 public static final String SHELLY_OBSTMODE_DISABLED = "disabled";
124 public static final String SHELLY_SAFETYM_WHILEOPENING = "while_opening";
126 public static final String SHELLY_ALWD_TRIGGER_NONE = "none";
127 public static final String SHELLY_ALWD_ROLLER_TURN_OPEN = "open";
128 public static final String SHELLY_ALWD_ROLLER_TURN_CLOSE = "close";
129 public static final String SHELLY_ALWD_ROLLER_TURN_STOP = "stop";
132 public static final String SHELLY_APIERR_UNAUTHORIZED = "Unauthorized";
133 public static final String SHELLY_APIERR_TIMEOUT = "Timeout";
134 public static final String SHELLY_APIERR_NOT_CALIBRATED = "Not calibrated!";
136 // API device types / properties
137 public static final String SHELLY_CLASS_RELAY = "relay"; // Relay: relay mode
138 public static final String SHELLY_CLASS_ROLLER = "roller"; // Relay: roller mode
139 public static final String SHELLY_CLASS_LIGHT = "light"; // Bulb: color mode
140 public static final String SHELLY_CLASS_EMETER = "emeter"; // EM/EM3: emeter
142 public static final String SHELLY_API_ON = "on";
143 public static final String SHELLY_API_OFF = "off";
144 public static final String SHELLY_API_TRUE = "true";
145 public static final String SHELLY_API_FALSE = "false";
147 public static final String SHELLY_API_MODE = "mode";
148 public static final String SHELLY_MODE_RELAY = "relay"; // Relay: relay mode
149 public static final String SHELLY_MODE_ROLLER = "roller"; // Relay: roller mode
150 public static final String SHELLY_MODE_COLOR = "color"; // Bulb/RGBW2: color mode
151 public static final String SHELLY_MODE_WHITE = "white"; // Bulb/RGBW2: white mode
153 public static final String SHELLY_LED_STATUS_DISABLE = "led_status_disable";
154 public static final String SHELLY_LED_POWER_DISABLE = "led_power_disable";
156 public static final String SHELLY_API_STOPR_NORMAL = "normal";
157 public static final String SHELLY_API_STOPR_SAFETYSW = "safety_switch";
158 public static final String SHELLY_API_STOPR_OBSTACLE = "obstacle";
159 public static final String SHELLY_API_STOPR_OVERPOWER = "overpower";
161 public static final String SHELLY_TIMER_AUTOON = "auto_on";
162 public static final String SHELLY_TIMER_AUTOOFF = "auto_off";
163 public static final String SHELLY_TIMER_ACTIVE = "has_timer";
165 public static final String SHELLY_LIGHT_TURN = "turn";
166 public static final String SHELLY_LIGHT_DEFSTATE = "def_state";
167 public static final String SHELLY_LIGHTTIMER = "timer";
169 public static final String SHELLY_COLOR_RED = "red";
170 public static final String SHELLY_COLOR_BLUE = "blue";
171 public static final String SHELLY_COLOR_GREEN = "green";
172 public static final String SHELLY_COLOR_YELLOW = "yellow";
173 public static final String SHELLY_COLOR_WHITE = "white";
174 public static final String SHELLY_COLOR_GAIN = "gain";
175 public static final String SHELLY_COLOR_BRIGHTNESS = "brightness";
176 public static final String SHELLY_COLOR_TEMP = "temp";
177 public static final String SHELLY_COLOR_EFFECT = "effect";
179 public static final int SHELLY_MIN_ROLLER_POS = 0;
180 public static final int SHELLY_MAX_ROLLER_POS = 100;
181 public static final int SHELLY_MIN_BRIGHTNESS = 0;
182 public static final int SHELLY_MAX_BRIGHTNESS = 100;
183 public static final int SHELLY_MIN_GAIN = 0;
184 public static final int SHELLY_MAX_GAIN = 100;
185 public static final int SHELLY_MIN_COLOR = 0;
186 public static final int SHELLY_MAX_COLOR = 255;
187 public static final int SHELLY_DIM_STEPSIZE = 10;
189 // color temperature: 3000 = warm, 4750 = white, 6565 = cold; gain: 0..100
190 public static final int MIN_COLOR_TEMP_BULB = 3000;
191 public static final int MAX_COLOR_TEMP_BULB = 6500;
192 public static final int MIN_COLOR_TEMP_DUO = 2700;
193 public static final int MAX_COLOR_TEMP_DUO = 6500;
194 public static final int COLOR_TEMP_RANGE_BULB = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
195 public static final int COLOR_TEMP_RANGE_DUO = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
196 public static final double MIN_BRIGHTNESS = 0.0;
197 public static final double MAX_BRIGHTNESS = 100.0;
198 public static final double SATURATION_FACTOR = 2.55;
199 public static final double GAIN_FACTOR = SHELLY_MAX_GAIN / 100;
200 public static final double BRIGHTNESS_FACTOR = SHELLY_MAX_BRIGHTNESS / 100;
203 public static final String SHELLY_API_ILLUM_DARK = "dark";
204 public static final String SHELLY_API_ILLUM_TWILIGHT = "twilight";
205 public static final String SHELLY_API_ILLUM_BRIGHT = "bright";
206 public static final String SHELLY_API_DWSTATE_OPEN = "open";
207 public static final String SHELLY_API_DWSTATE_CLOSE = "close";
210 public static final String SHELLY_IR_CODET_STORED = "stored";
211 public static final String SHELLY_IR_CODET_PRONTO = "pronto";
212 public static final String SHELLY_IR_CODET_PRONTO_HEX = "pronto_hex";
215 public static final int SHELLY_MIN_EFFECT = 0;
216 public static final int SHELLY_MAX_EFFECT = 6;
219 public static final String SHELLY_BTNEVENT_1SHORTPUSH = "S";
220 public static final String SHELLY_BTNEVENT_2SHORTPUSH = "SS";
221 public static final String SHELLY_BTNEVENT_3SHORTPUSH = "SSS";
222 public static final String SHELLY_BTNEVENT_LONGPUSH = "L";
223 public static final String SHELLY_BTNEVENT_SHORTLONGPUSH = "SL";
224 public static final String SHELLY_BTNEVENT_LONGSHORTPUSH = "LS";
226 public static final String SHELLY_TEMP_CELSIUS = "C";
227 public static final String SHELLY_TEMP_FAHRENHEIT = "F";
229 public static class ShellySettingsDevice {
232 public String hostname;
236 @SerializedName("coiot") // Shelly Motion Multicast Endpoint
238 public Integer longid;
240 @SerializedName("num_outputs")
241 public Integer numOutputs;
242 @SerializedName("num_meters")
243 public Integer numMeters;
244 @SerializedName("num_emeters")
245 public Integer numEMeters;
246 @SerializedName("num_rollers")
247 public Integer numRollers;
250 public static class ShellySettingsWiFiAp {
251 public Boolean enabled;
256 public static class ShellySettingsWiFiNetwork {
257 public Boolean enabled;
261 @SerializedName("ipv4_method")
262 public String ipv4Method;
269 public static class ShellySettingsMqtt {
270 public Boolean enabled;
271 public String server;
273 @SerializedName("reconnect_timeout_max")
274 public Double reconnectTimeoutMax;
275 @SerializedName("reconnect_timeout_min")
276 public Double reconnectTimeoutMin;
277 @SerializedName("clean_session")
278 public Boolean cleanSession;
279 @SerializedName("keep_alive")
280 public Integer keepAlive;
281 @SerializedName("will_topic")
282 public String willTopic;
283 @SerializedName("will_message")
284 public String willMessage;
285 @SerializedName("max_qos")
286 public Integer maxQOS;
287 public Boolean retain;
288 @SerializedName("update_period")
289 public Integer updatePeriod;
292 public static class ShellySettingsCoiot { // FW 1.6+
293 @SerializedName("update_period")
294 public Integer updatePeriod;
297 public static class ShellySettingsSntp {
298 public String server;
301 public static class ShellySettingsLogin {
302 public Boolean enabled;
303 public Boolean unprotected;
304 public String username;
305 public String password;
308 public static class ShellySettingsBuildInfo {
309 @SerializedName("build_id")
310 public String buildId;
311 @SerializedName("build_timestamp")
312 public String buildTimestamp;
313 @SerializedName("build_version")
314 public String buildVersion;
317 public static class ShellyStatusCloud {
318 public Boolean enabled;
319 public Boolean connected;
322 public static class ShellyStatusMqtt {
323 public Boolean connected;
326 public static class ShellySettingsHwInfo {
327 @SerializedName("hw_revision")
328 public String hwRevision;
329 @SerializedName("batch_id")
330 public Integer batchId;
333 public static class ShellySettingsScheduleRules {
336 public static class ShellySettingsRelay {
339 public Boolean overpower;
340 @SerializedName("default_state")
341 public String defaultState; // Accepted values: off, on, last, switch
342 @SerializedName("btn_type")
343 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
344 @SerializedName("btn1_type") // Shelly 1L
345 public String btnType1;
346 @SerializedName("btn2_type") // Shelly 1L
347 public String btnType2;
348 @SerializedName("has_timer")
349 public Boolean hasTimer; // Whether a timer is currently armed for this channel
350 @SerializedName("auto_on")
351 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
352 @SerializedName("auto_off")
353 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
354 @SerializedName("btn_on_url")
355 public String btnOnUrl; // input is activated
356 @SerializedName("btnOffUrl")
357 public String btnOffUrl; // input is deactivated
358 @SerializedName("out_on_url")
359 public String outOnUrl; // output is activated
360 @SerializedName("out_off_url")
361 public String outOffUrl; // output is deactivated
362 @SerializedName("roller_open_url")
363 public String rollerOpenUrl; // to access when roller reaches open position
364 @SerializedName("roller_close_url")
365 public String rollerCloseUrl; // to access when roller reaches close position
366 @SerializedName("roller_stop_url")
367 public String rollerStopUrl; // to access when roller stopped
368 @SerializedName("longpush_url")
369 public String pushLongUrl; // to access when roller stopped
370 @SerializedName("shortpush_url")
371 public String pushShortUrl; // to access when roller stopped
373 public Boolean schedule;
374 // ArrayList<ShellySettingsScheduleRules> schedule_rules;
377 public static class ShellySettingsDimmer {
378 public String name; // unique name of the device
379 public Boolean ison; // true: output is ON
380 @SerializedName("default_state")
381 public String defaultState; // Accepted values: off, on, last, switch
382 @SerializedName("auto_on")
383 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
384 @SerializedName("auto_off")
385 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
386 @SerializedName("btn1_on_url")
387 public String btn1OnUrl; // URL to access when SW input is activated
388 @SerializedName("btn1_off_url")
389 public String btn1OffUrl; // URL to access when SW input is deactivated
390 @SerializedName("btn2_on_url")
391 public String btn2OnUrl; // URL to access when SW input is activated
392 @SerializedName("btn2_off_url")
393 public String btn2OoffUrl; // URL to access when SW input is deactivated
394 @SerializedName("out_on_url")
395 public String outOnUrl; // URL to access when output is activated
396 @SerializedName("out_off_url")
397 public String outOffUrl; // URL to access when output is deactivated
398 @SerializedName("longpush_url")
399 public String pushLongUrl; // long push button event
400 @SerializedName("shortpush_url")
401 public String pushShortUrl; // short push button event
402 @SerializedName("btn_type")
403 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
404 @SerializedName("btn1_type")
405 public String btnType1; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
406 @SerializedName("btn2_type")
407 public String btnType2; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
408 @SerializedName("swap_inputs")
409 public Integer swapInputs; // 0=no
412 public static class ShellySettingsRoller {
413 public Double maxtime;
414 @SerializedName("maxtime_open")
415 public Double maxtimeOpen;
416 @SerializedName("maxtime_close")
417 public Double maxtimeClose;
418 @SerializedName("default_state")
419 public String defaultState; // see SHELLY_STATE_xxx
421 @SerializedName("swap_inputs")
422 public Boolean swapInputs;
423 @SerializedName("input_mode")
424 public String inputMode; // see SHELLY_INP_MODE_OPENCLOSE
425 @SerializedName("button_type")
426 public String buttonType; // // see SHELLY_BTNT_xxx
427 @SerializedName("btn_Reverse")
428 public Integer btnReverse;
431 @SerializedName("is_valid")
432 public Boolean isValid;
433 @SerializedName("safety_switch")
434 public Boolean safetySwitch;
435 public Boolean schedule;
436 // ArrayList<ShellySettingsScheduleRules> schedule_rules; // not used for now
437 @SerializedName("obstacle_mode")
438 public String obstaclMode; // SHELLY_OBSTMODE_
439 @SerializedName("obstacle_action")
440 public String obstacleAction; // see SHELLY_STATE_xxx
441 @SerializedName("obstacle_power")
442 public Integer obstaclePower;
443 @SerializedName("obstacle_delay")
444 public Integer obstacleDelay;
445 @SerializedName("safety_mode")
446 public String safetyMode; // see SHELLY_SAFETYM_xxx
447 @SerializedName("safety_action")
448 public String safetyAction; // see SHELLY_STATE_xxx
449 @SerializedName("safety_allowed_on_trigger")
450 public String safetyAllowedOnTrigger; // see SHELLY_ALWD_TRIGGER_xxx
451 @SerializedName("off_power")
452 public Integer offPower;
453 public Boolean positioning;
456 public static class ShellySettingsRgbwLight {
458 public Boolean ison; // true: output is ON
459 public Integer brightness;
460 public Integer transition;
461 public String default_state;
462 @SerializedName("auto_on")
463 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
464 @SerializedName("auto_off")
465 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
466 public Boolean schedule;
467 @SerializedName("btn_type")
468 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
469 @SerializedName("btn_reverse")
470 public Integer btnReverse; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
471 @SerializedName("out_on_url")
472 public String outOnUrl; // output is activated
473 @SerializedName("out_off_url")
474 public String outOffUrl; // output is deactivated
477 public static class ShellyFavPos { // FW 1.9.2+ in roller mode
482 public static class ShellyInputState {
483 public Integer input;
487 @SerializedName("event_cnt")
488 public Integer eventCount;
491 public static class ShellySettingsMeter {
492 @SerializedName("is_valid")
493 public Boolean isValid;
495 public Double[] counters = { 0.0, 0.0, 0.0 };
497 public Long timestamp;
500 public static class ShellySettingsEMeter { // ShellyEM meter
501 @SerializedName("is_valid")
502 public Boolean isValid; // Whether the associated meter is functioning properly
503 public Double power; // Instantaneous power, Watts
504 public Double reactive; // Instantaneous reactive power, Watts
505 public Double voltage; // RMS voltage, Volts
506 public Double total; // Total consumed energy, Wh
507 @SerializedName("total_returned")
508 public Double totalReturned; // Total returned energy, Wh
510 public Double pf; // 3EM
511 public Double current; // 3EM
514 public static class ShellySettingsUpdate {
515 public String status;
516 @SerializedName("has_update")
517 public Boolean hasUpdate;
518 @SerializedName("new_version")
519 public String newVersion;
520 @SerializedName("old_version")
521 public String oldVersion;
522 @SerializedName("beta_version")
523 public String betaVersion;
526 public static class ShellySettingsGlobal {
527 // https://shelly-api-docs.shelly.cloud/#shelly1pm-settings
528 public ShellySettingsDevice device;
529 @SerializedName("wifi_ap")
530 public ShellySettingsWiFiAp wifiAp;
531 @SerializedName("wifi_sta")
532 public ShellySettingsWiFiNetwork wifiSta;
533 @SerializedName("wifi_sta1")
534 public ShellySettingsWiFiNetwork wifiSta1;
535 // public ShellySettingsMqtt mqtt; // not used for now
536 // public ShellySettingsSntp sntp; // not used for now
537 public ShellySettingsCoiot coiot; // Firmware 1.6+
538 public ShellySettingsLogin login;
539 @SerializedName("pin_code")
540 public String pinCode;
541 @SerializedName("coiot_execute_enable")
542 public Boolean coiotExecuteEnable;
544 public Boolean discoverable; // FW 1.6+
546 @SerializedName("build_info")
547 ShellySettingsBuildInfo buildInfo;
548 ShellyStatusCloud cloud;
549 @SerializedName("sleep_mode")
550 public ShellySensorSleepMode sleepMode; // FW 1.6
551 @SerializedName("external_power")
552 public Integer externalPower; // H&T FW 1.6, seems to be the same like charger for the Sense
554 public String timezone;
557 public Boolean tzautodetect;
559 // @SerializedName("tz_utc_offset")
560 // public Integer tzUTCOoffset; // FW 1.6+
561 // @SerializedName("tz_dst")
562 // public Boolean tzDdst; // FW 1.6+
563 // @SerializedName("tz_dst_auto")
564 // public Boolean tzDstAuto; // FW 1.6+
565 // public Long unixtime; // FW 1.6+
567 public ShellySettingsHwInfo hwinfo;
569 @SerializedName("max_power")
570 public Double maxPower;
572 public ArrayList<ShellySettingsRelay> relays;
573 public ArrayList<ShellySettingsDimmer> dimmers;
574 public ArrayList<ShellySettingsRgbwLight> lights;
575 public ArrayList<ShellySettingsEMeter> emeters;
576 public ArrayList<ShellySettingsInput> inputs; // ix3
578 @SerializedName("temperature_units")
579 public String temperatureUnits; // Either'C'or'F'
581 @SerializedName("led_status_disable")
582 public Boolean ledStatusDisable; // PlugS only Disable LED indication for network
584 @SerializedName("led_power_disable")
585 public Boolean ledPowerDisable; // PlugS only Disable LED indication for network
587 @SerializedName("light_sensor")
588 public String lightSensor; // Sense: sensor type
589 @SerializedName("rain_sensor")
590 public Boolean rainSensor; // Flood: true=in rain mode
592 // FW 1.5.7: Door Window
593 @SerializedName("dark_treshold")
594 public Integer darkTreshold; // Illumination definition for "dark" in lux
595 @SerializedName("twilight_treshold")
596 public Integer twiLightTreshold; // Illumination definition for "twilight" in lux
597 @SerializedName("dark_url")
598 public String darkUrl; // URL to report to when luminance <= dark_threshold
599 @SerializedName("twilight_url")
600 public String twiLightUrl; // URL reports when luminance > dark_threshold AND luminance <=
601 @SerializedName("close_url")
602 public String closeUrl; // URL reports when DW contact is closed FW 1.6.5+
603 @SerializedName("vibration_url")
604 public String vibrationUrl; // URL reports when DW detects vibration FW 1.6.5+
606 // @SerializedName("tilt_enabled")
607 // public Boolean tiltEnabled; // Whether tilt monitoring is activated
608 // @SerializedName("tilt_calibrated")
609 // public Boolean tiltCalibrated; // Whether calibration data is valid
610 // @SerializedName("vibration_enabled")
611 // public Boolean vibrationEnabled; // Whether vibration monitoring is activated
612 // @SerializedName("reverse_open_close")
613 // public Boolean reverseOpenClose; // Whether to reverse which position the sensor consideres "open"
616 @SerializedName("set_volume")
617 public Integer volume; // Speaker volume for alarm
618 @SerializedName("alarm_off_url")
619 public String alarmOffUrl; // URL reports when alarm went off
620 @SerializedName("alarm_mild_url")
621 public String alarmMidUrl; // URL reports middle alarm
622 @SerializedName("alarm_heavy_url")
623 public String alarmHeavyfUrl; // URL reports heavy alarm
625 // Roller with FW 1.9.2+
626 @SerializedName("favorites_enabled")
627 public Boolean favoritesEnabled;
628 public ArrayList<ShellyFavPos> favorites;
631 public static class ShellySettingsAttributes {
632 @SerializedName("device_type")
633 public String deviceType; // Device model identifier
634 @SerializedName("device_mac")
635 public String deviceMac; // MAC address of the device in hexadecimal
636 @SerializedName("wifi_ap")
637 public String wifiAp; // WiFi access poInteger configuration, see /settings/ap for details
638 @SerializedName("wifi_sta")
639 public String wifiSta; // WiFi client configuration. See /settings/sta for details
640 public String login; // credentials used for HTTP Basic authentication for the REST interface. If
641 // enabled is true clients must include an Authorization: Basic ... HTTP header with valid
642 // credentials when performing TP requests.
643 public String name; // unique name of the device.
644 public String fw; // current FW version
647 public static class ShellySettingsStatus {
648 public String name; // FW 1.8: Symbolic Device name is configurable
650 @SerializedName("wifi_sta")
651 public ShellySettingsWiFiNetwork wifiSta; // WiFi client configuration. See /settings/sta for details
654 public Integer serial;
655 @SerializedName("has_update")
656 public Boolean hasUpdate;
658 public Boolean discoverable; // FW 1.6+
659 @SerializedName("cfg_changed_cnt")
660 public Integer cfgChangedCount; // FW 1.8
662 public ArrayList<ShellySettingsRelay> relays;
663 public ArrayList<ShellySettingsRoller> rollers;
664 public Integer input; // RGBW2 has no JSON array
665 public ArrayList<ShellyInputState> inputs;
666 public ArrayList<ShellySettingsLight> lights;
667 // @SerializedName("night_mode") // FW 1.5.7+
668 // public ShellySettingsNightMode nightMode;
669 public ArrayList<ShellyShortLightStatus> dimmers;
670 public ArrayList<ShellySettingsMeter> meters;
671 public ArrayList<ShellySettingsEMeter> emeters;
673 // Internal device temp
674 public ShellyStatusSensor.ShellySensorTmp tmp; // Shelly 1PM
675 public Double temperature; // Shelly 2.5
676 public Boolean overtemperature;
678 // Shelly Dimmer only
679 public Boolean loaderror;
680 public Boolean overload;
682 public ShellySettingsUpdate update;
683 @SerializedName("ram_total")
684 public Long ramTotal;
685 @SerializedName("ram_free")
687 @SerializedName("fs_size")
689 @SerializedName("fs_free")
696 public static class ShellySettingsInput {
697 @SerializedName("btn_type")
698 public String btnType;
700 // attributes not yet processed
701 // public String name;
702 // @SerializedName("btn_reverse")
703 // public Integer btnReverse;
704 // @SerializedName("btn_on_url")
705 // public String btnOnUrl;
706 // @SerializedName("btn_off_url")
707 // public String btnOffUrl;
708 // @SerializedName("shortpush_url")
709 // public String shortpushUrl;
710 // @SerializedName("longpush_url")
711 // public String longpushUrl;
712 // @SerializedName("double_shortpush_url")
713 // public String doubleShortpushUrl;
714 // @SerializedName("triple_shortpush_url")
715 // public String tripleShortpushUrl;
716 // @SerializedName("shortpush_longpush_url")
717 // public String shortpushLongpushUrl;
718 // @SerializedName("longpush_shortpush_url")
719 // public String longpushShortpushUrl;
722 public static class ShellyControlRelay {
723 // https://shelly-api-docs.shelly.cloud/#shelly1-1pm-settings-relay-0
724 @SerializedName("is_valid")
725 public Boolean isValid;
726 @SerializedName("has_timer")
727 public Boolean hasTimer; // Whether a timer is currently armed for this channel
728 @SerializedName("timer_remaining")
729 public Integer timerRemaining; // FW 1.6+
730 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
732 public String turn; // Accepted values are on and off. This will turn ON/OFF the respective output
733 // channel when request is sent .
734 public Integer timer; // A one-shot flip-back timer in seconds.
737 public static class ShellyShortStatusRelay {
738 public String name; // FW 1.8+: Channel could now have a logical name
739 @SerializedName("is_valid")
740 public Boolean isValid;
741 public Boolean ison; // Whether output channel is on or off
742 @SerializedName("has_timer")
743 public Boolean hasTimer; // Whether a timer is currently armed for this channel
744 @SerializedName("timer_remaining")
745 public Integer timerRemaining;
746 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
747 public Double temperature; // Internal device temperature
748 public Boolean overtemperature; // Device over heated
751 public static class ShellyShortLightStatus {
752 public Boolean ison; // Whether output channel is on or off
753 public String mode; // color or white - valid only for Bulb and RGBW2 even Dimmer returns it also
754 public Integer brightness; // brightness: 0.100%
755 // @SerializedName("has_timer")
756 // public Boolean hasTimer; // Whether a timer is currently armed for this channel
757 // @SerializedName("timer_remaining")
758 // public Integer timerRemaining;
759 // public Integer wgite;
760 // public Integer temp; // light temp
763 public static class ShellyStatusRelay {
764 public String name; // FW 1.8: Symbolic channel name is configurable
766 @SerializedName("wifi_sta")
767 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
768 // public ShellyStatusCloud cloud; // Cloud status
769 // public ShellyStatusMqtt mqtt; // mqtt status
770 public ShellySettingsCoiot coiot; // Firmware 1.6+
771 // public String time; // current time
772 public Integer serial;
773 public String mac; // MAC
774 public ArrayList<ShellyShortStatusRelay> relays; // relay status
775 public ArrayList<ShellySettingsMeter> meters; // current meter value
776 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
778 @SerializedName("ext_temperature")
779 public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
780 @SerializedName("ext_humidity")
781 public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
783 public Double temperature; // device temp acc. on the selected temp unit
784 public ShellyStatusSensor.ShellySensorTmp tmp;
786 @SerializedName("has_update")
787 public Boolean hasUpdate; // If a newer firmware version is available
788 public ShellySettingsUpdate update; // /status/firmware value
790 @SerializedName("ram_total")
791 public Integer ramTotal; // Total and available amount of system memory in bytes
792 @SerializedName("ram_free")
793 public Integer ramFree;
794 @SerializedName("fs_size")
795 public Integer fsSize;
796 @SerializedName("fs_free")
797 public Integer fsFree; // Total and available amount of file system space in bytes
798 public Integer uptime; // econds elapsed since boot
801 public static class ShellyStatusDimmer {
802 @SerializedName("wifi_sta")
803 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
804 // public ShellyStatusCloud cloud; // Cloud status
805 // public ShellyStatusMqtt mqtt; // mqtt status
806 public String time; // current time
807 public Integer serial;
808 public String mac; // MAC
809 public ArrayList<ShellyShortLightStatus> lights; // relay status
810 public ArrayList<ShellySettingsMeter> meters; // current meter value
812 public ShellyStatusSensor.ShellySensorTmp tmp;
813 public Boolean overtemperature;
815 public Boolean loaderror;
816 public Boolean overload;
818 @SerializedName("has_update")
819 public Boolean hasUpdate; // If a newer firmware version is available
820 public ShellySettingsUpdate update; // /status/firmware value
822 @SerializedName("ram_total")
823 public Integer ramTotal; // Total and available amount of system memory in
825 @SerializedName("ram_free")
826 public Integer ramFree;
827 @SerializedName("fs_size")
828 public Integer fsSize;
829 @SerializedName("fs_free")
830 public Integer fsFree; // Total and available amount of file system space in bytes
831 public Integer uptime; // seconds elapsed since boot
834 public static class ShellyControlRoller {
835 public String name; // FW 1.8: Symbolic name is configurable
837 @SerializedName("roller_pos")
838 public Integer rollerPos; // number Desired position in percent
839 public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
840 // value of maxtime in /settings/roller/N will be used.
841 public String state; // One of stop, open, close
842 public Double power; // Current power consumption in Watts
843 @SerializedName("is_valid")
844 public Boolean isValid; // If the power meter functions properly
845 @SerializedName("safety_switch")
846 public Boolean safetySwitch; // Whether the safety input is currently triggered
847 public Boolean overtemperature;
848 @SerializedName("stop_reason")
849 public String stopReason; // Last cause for stopping: normal, safety_switch, obstacle
850 @SerializedName("last_direction")
851 public String lastDirection; // Last direction of motion, open or close
852 public Boolean calibrating;
853 public Boolean positioning; // true when calibration was performed
854 @SerializedName("current_pos")
855 public Integer currentPos; // current position 0..100, 100=open
858 public class ShellySensorSleepMode {
859 public Integer period;
863 public static class ShellyStatusSensor {
864 // https://shelly-api-docs.shelly.cloud/#h-amp-t-settings
865 public static class ShellySensorTmp {
866 public Double value; // Temperature in configured unites
867 public String units; // 'C' or 'F'
868 public Double tC; // temperature in deg C
869 public Double tF; // temperature in deg F
870 @SerializedName("is_valid")
871 public Boolean isValid; // whether the internal sensor is operating properly
874 public static class ShellySensorHum {
875 public Double value; // relative humidity in %
878 public static class ShellySensorBat {
879 public Double value; // estimated remaining battery capacity in %
880 public Double voltage; // battery voltage
883 // Door/Window sensor
884 public static class ShellySensorState {
885 @SerializedName("is_valid")
886 public Boolean isValid; // whether the internal sensor is operating properly
887 public String state; // Shelly Door/Window
890 public Boolean motion;
891 public Boolean vibration;
892 @SerializedName("timestamp")
893 public Long motionTimestamp;
894 @SerializedName("active")
895 public Boolean motionActive;
898 public static class ShellySensorLux {
899 @SerializedName("is_valid")
900 public Boolean isValid; // whether the internal sensor is operating properly
903 public String illumination;
906 public static class ShellySensorAccel {
907 public Integer tilt; // Tilt in °
908 public Integer vibration; // Whether vibration is detected
911 public static class ShellyExtTemperature {
912 public static class ShellyShortTemp {
913 public Double tC; // temperature in deg C
914 public Double tF; // temperature in deg F
917 // Shelly 1/1PM have up to 3 sensors
918 // for whatever reasons it's not an array, but 3 independent elements
920 public ShellyShortTemp sensor1;
922 public ShellyShortTemp sensor2;
924 public ShellyShortTemp sensor3;
927 public static class ShellyExtHumidity {
928 public static class ShellyShortHum {
929 public Double hum; // Humidity reading of sensor 0, percent
932 // Shelly 1/1PM have up to 3 sensors
933 // for whatever reasons it's not an array, but 3 independent elements
935 public ShellyShortHum sensor1;
938 public static class ShellyADC {
939 public Double voltage;
942 public ShellySensorTmp tmp;
943 public ShellySensorHum hum;
944 public ShellySensorLux lux;
945 public ShellySensorAccel accel;
946 public ShellySensorBat bat;
947 @SerializedName("sensor")
948 public ShellySensorState sensor;
949 public Boolean smoke; // SHelly Smoke
950 public Boolean flood; // Shelly Flood: true = flood condition detected
951 @SerializedName("rain_sensor")
952 public Boolean rainSensor; // Shelly Flood: true=in rain mode
954 public Boolean motion; // Shelly Sense: true=motion detected
955 public Boolean charger; // Shelly Sense: true=charger connected
956 @SerializedName("external_power")
957 public Integer externalPower; // H&T FW 1.6, seems to be the same like charger for the Sense
959 @SerializedName("act_reasons")
960 public List<Object> actReasons; // HT/Smoke/Flood: list of reasons which woke up the device
962 @SerializedName("sensor_error")
963 public String sensorError; // 1.5.7: Only displayed in case of error
965 // FW 1.7: Shelly Gas
966 @SerializedName("gas_sensor")
967 public ShellyStatusGasSensor gasSensor;
968 @SerializedName("concentration")
969 public ShellyStatusGasConcentration concentration;
970 public ArrayList<ShellyStatusValve> valves;
973 @SerializedName("connect_retries")
974 public Integer connectRetries;
975 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
977 // Shelly UNI FW 1.9+
978 public ArrayList<ShellyADC> adcs;
981 public static class ShellySettingsSmoke {
982 @SerializedName("temperature_units")
983 public String temperatureUnits; // Either 'C' or 'F'
984 @SerializedName("temperature_threshold")
985 public Integer temperatureThreshold; // Temperature delta (in configured degree units) which triggers an update
986 @SerializedName("sleep_mode_period")
987 public Integer sleepModePeriod; // Periodic update period in hours, between 1 and 24
991 // "gas_sensor":{"sensor_state":"normal","self_test_state":"not_completed","alarm_state":"none"},
992 // "concentration":{"ppm":0,"is_valid":true},
993 public static class ShellyStatusGasSensor {
994 @SerializedName("sensor_state")
995 public String sensorState;
996 @SerializedName("self_test_state")
997 public String selfTestState;
998 @SerializedName("alarm_state")
999 public String alarmState;
1002 public static class ShellyStatusGasConcentration {
1004 @SerializedName("is_valid")
1005 public Boolean isValid;
1008 public static class ShellyStatusValve {
1009 public String state; // closed/opened/not_connected/failure/closing/opening/checking
1012 public static class ShellySettingsLight {
1013 public Integer red; // red brightness, 0..255, applies in mode="color"
1014 public Integer green; // green brightness, 0..255, applies in mode="color"
1015 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1016 public Integer white; // white brightness, 0..255, applies in mode="color"
1017 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1018 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1019 public Integer brightness; // brightness, 0..100, applies in mode="white"
1020 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1021 // Change, 3: Breath,
1022 // 4: Flash, 5: On/Off Gradual, 6: Red/Green Change
1023 @SerializedName("default_state")
1024 public String defaultState; // one of on, off or last
1025 @SerializedName("auto_on")
1026 public Double autoOn; // see above
1027 @SerializedName("auto_off")
1028 public Double autoOff; // see above
1030 public Integer dcpower; // RGW2:Set to true for 24 V power supply, false for 12 V
1034 public Boolean ison;
1037 public static class ShellySettingsNightMode { // FW1.5.7+
1038 public Integer enabled;
1039 @SerializedName("start_time")
1040 public String startTime;
1041 @SerializedName("end_time")
1042 public String endTime;
1043 public Integer brightness;
1046 public static class ShellyStatusLightChannel {
1047 public Boolean ison;
1048 public Double power;
1049 public Boolean overpower;
1050 @SerializedName("has_timer")
1051 public Boolean hasTimer;
1052 @SerializedName("timer_started")
1053 public Integer timerStarted;
1054 @SerializedName("timer_duration")
1055 public Integer timerDuration;
1056 @SerializedName("timer_remaining")
1057 public Integer timerRemaining;
1059 public Integer red; // red brightness, 0..255, applies in mode="color"
1060 public Integer green; // green brightness, 0..255, applies in mode="color"
1061 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1062 public Integer white; // white brightness, 0..255, applies in mode="color"
1063 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1064 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1065 public Integer brightness; // brightness, 0..100, applies in mode="white"
1066 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1067 // Change, 3: Breath,
1070 public static class ShellyStatusLight {
1071 public Boolean ison; // Whether output channel is on or off
1072 public Integer input;
1074 public ArrayList<ShellyStatusLightChannel> lights;
1075 public ArrayList<ShellySettingsMeter> meters;
1078 public static class ShellySenseKeyCode {
1079 String id; // ID of the stored IR code into Shelly Sense.
1080 String name; // Short description or name of the stored IR code.
1083 public static class ShellySendKeyList {
1084 @SerializedName("key_codes")
1085 public ArrayList<ShellySenseKeyCode> keyCodes;
1089 * Shelly Dimmer returns light[]. However, the structure doesn't match the lights[] of a Bulb/RGBW2.
1090 * The tag lights[] will be replaced with dimmers[] so this could be mapped to a different Gson structure.
1091 * The function requires that it's only called when the device is a dimmer - on get settings and get status
1093 * @param json Input Json as received by the API
1094 * @return Modified Json
1096 public static String fixDimmerJson(String json) {
1097 return !json.contains("\"lights\":[") ? json
1098 : json.replaceFirst(java.util.regex.Pattern.quote("\"lights\":["), "\"dimmers\":[");
1102 * Convert Shelly Button events into OH button states
1104 * @param eventType S/SS/SSS or L
1105 * @return OH button states
1107 public static String mapButtonEvent(String eventType) {
1108 // decode different codings
1110 // S/SS/SSS/L: CoAP for Button and xi3
1111 // shortpush/double_shortpush/triple_shortpush/longpush: REST
1112 switch (eventType) {
1114 return CommonTriggerEvents.RELEASED;
1116 case SHELLY_BTNEVENT_1SHORTPUSH:
1117 case SHELLY_EVENT_SHORTPUSH:
1118 return CommonTriggerEvents.SHORT_PRESSED;
1119 case SHELLY_BTNEVENT_2SHORTPUSH:
1120 case SHELLY_EVENT_DOUBLE_SHORTPUSH:
1121 return CommonTriggerEvents.DOUBLE_PRESSED;
1122 case SHELLY_BTNEVENT_3SHORTPUSH:
1123 case SHELLY_EVENT_TRIPLE_SHORTPUSH:
1124 return "TRIPLE_PRESSED";
1126 case SHELLY_BTNEVENT_LONGPUSH:
1127 case SHELLY_EVENT_LONGPUSH:
1128 return CommonTriggerEvents.LONG_PRESSED;
1129 case SHELLY_BTNEVENT_SHORTLONGPUSH:
1130 case SHELLY_EVENT_SHORT_LONGTPUSH:
1131 return "SHORT_LONG_PRESSED";
1132 case SHELLY_BTNEVENT_LONGSHORTPUSH:
1133 case SHELLY_EVENT_LONG_SHORTPUSH:
1134 return "LONG_SHORT_PRESSED";