2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.shelly.internal.api;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.openhab.binding.shelly.internal.api.ShellyApiJsonDTO.ShellyStatusSensor.ShellyMotionSettings;
19 import org.openhab.core.thing.CommonTriggerEvents;
21 import com.google.gson.annotations.SerializedName;
24 * The {@link ShellyApiJsonDTO} is used for the JSon/GSon mapping
26 * @author Markus Michels - Initial contribution
28 public class ShellyApiJsonDTO {
29 public static final String SHELLY_NULL_URL = "null";
30 public static final String SHELLY_URL_DEVINFO = "/shelly";
31 public static final String SHELLY_URL_STATUS = "/status";
32 public static final String SHELLY_URL_SETTINGS = "/settings";
33 public static final String SHELLY_URL_SETTINGS_AP = "/settings/ap";
34 public static final String SHELLY_URL_SETTINGS_STA = "/settings/sta";
35 public static final String SHELLY_URL_SETTINGS_LOGIN = "/settings/sta";
36 public static final String SHELLY_URL_SETTINGS_CLOUD = "/settings/cloud";
37 public static final String SHELLY_URL_LIST_IR = "/ir/list";
38 public static final String SHELLY_URL_SEND_IR = "/ir/emit";
39 public static final String SHELLY_URL_RESTART = "/reboot";
41 public static final String SHELLY_URL_SETTINGS_RELAY = "/settings/relay";
42 public static final String SHELLY_URL_STATUS_RELEAY = "/status/relay";
43 public static final String SHELLY_URL_CONTROL_RELEAY = "/relay";
45 public static final String SHELLY_URL_SETTINGS_EMETER = "/settings/emeter";
46 public static final String SHELLY_URL_STATUS_EMETER = "/emeter";
47 public static final String SHELLY_URL_DATA_EMETER = "/emeter/{0}/em_data.csv";
49 public static final String SHELLY_URL_CONTROL_ROLLER = "/roller";
50 public static final String SHELLY_URL_SETTINGS_ROLLER = "/settings/roller";
52 public static final String SHELLY_URL_SETTINGS_LIGHT = "/settings/light";
53 public static final String SHELLY_URL_STATUS_LIGHT = "/light";
54 public static final String SHELLY_URL_CONTROL_LIGHT = "/light";
56 public static final String SHELLY_URL_SETTINGS_DIMMER = "/settings/light";
59 // 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 Double voltage; // AC voltage for Shelly 2.5
580 @SerializedName("supply_voltage")
581 public Long supplyVoltage; // Shelly 1PM/1L: 0=110V, 1=220V
582 public ArrayList<ShellySettingsDimmer> dimmers;
583 public ArrayList<ShellySettingsRgbwLight> lights;
584 public ArrayList<ShellySettingsEMeter> emeters;
585 public ArrayList<ShellySettingsInput> inputs; // ix3
587 @SerializedName("temperature_units")
588 public String temperatureUnits; // Either'C'or'F'
590 @SerializedName("led_status_disable")
591 public Boolean ledStatusDisable; // PlugS only Disable LED indication for network
593 @SerializedName("led_power_disable")
594 public Boolean ledPowerDisable; // PlugS only Disable LED indication for network
596 @SerializedName("light_sensor")
597 public String lightSensor; // Sense: sensor type
598 @SerializedName("rain_sensor")
599 public Boolean rainSensor; // Flood: true=in rain mode
601 // FW 1.5.7: Door Window
602 @SerializedName("dark_treshold")
603 public Integer darkTreshold; // Illumination definition for "dark" in lux
604 @SerializedName("twilight_treshold")
605 public Integer twiLightTreshold; // Illumination definition for "twilight" in lux
606 @SerializedName("dark_url")
607 public String darkUrl; // URL to report to when luminance <= dark_threshold
608 @SerializedName("twilight_url")
609 public String twiLightUrl; // URL reports when luminance > dark_threshold AND luminance <=
610 @SerializedName("close_url")
611 public String closeUrl; // URL reports when DW contact is closed FW 1.6.5+
612 @SerializedName("vibration_url")
613 public String vibrationUrl; // URL reports when DW detects vibration FW 1.6.5+
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 ShellyMotionSettings motion;
632 @SerializedName("tamper_sensitivity")
633 public Integer tamperSensitivity;
634 @SerializedName("dark_threshold")
635 public Integer darkThreshold;
636 @SerializedName("twilight_threshold")
637 public Integer twilightThreshold;
639 @SerializedName("sleep_time") // Shelly Motion
640 public Integer sleepTime;
643 public static class ShellySettingsAttributes {
644 @SerializedName("device_type")
645 public String deviceType; // Device model identifier
646 @SerializedName("device_mac")
647 public String deviceMac; // MAC address of the device in hexadecimal
648 @SerializedName("wifi_ap")
649 public String wifiAp; // WiFi access poInteger configuration, see /settings/ap for details
650 @SerializedName("wifi_sta")
651 public String wifiSta; // WiFi client configuration. See /settings/sta for details
652 public String login; // credentials used for HTTP Basic authentication for the REST interface. If
653 // enabled is true clients must include an Authorization: Basic ... HTTP header with valid
654 // credentials when performing TP requests.
655 public String name; // unique name of the device.
656 public String fw; // current FW version
659 public static class ShellyActionsStats {
660 public Integer skipped;
663 public static class ShellySettingsStatus {
664 public String name; // FW 1.8: Symbolic Device name is configurable
666 @SerializedName("wifi_sta")
667 public ShellySettingsWiFiNetwork wifiSta; // WiFi client configuration. See /settings/sta for details
668 public ShellyStatusCloud cloud;
669 public ShellyStatusMqtt mqtt;
672 public Integer serial;
673 @SerializedName("has_update")
674 public Boolean hasUpdate;
676 public Boolean discoverable; // FW 1.6+
677 @SerializedName("cfg_changed_cnt")
678 public Integer cfgChangedCount; // FW 1.8
679 @SerializedName("actions_stats")
680 public ShellyActionsStats astats;
682 public ArrayList<ShellySettingsRelay> relays;
683 public Double voltage; // Shelly 2.5
685 public ArrayList<ShellySettingsRoller> rollers;
686 public Integer input; // RGBW2 has no JSON array
687 public ArrayList<ShellyInputState> inputs;
688 public ArrayList<ShellySettingsLight> lights;
689 public ArrayList<ShellyShortLightStatus> dimmers;
690 public ArrayList<ShellySettingsMeter> meters;
691 public ArrayList<ShellySettingsEMeter> emeters;
693 // Internal device temp
694 public ShellyStatusSensor.ShellySensorTmp tmp; // Shelly 1PM
695 public Double temperature; // Shelly 2.5
696 public Boolean overtemperature;
698 // Shelly Dimmer only
699 public Boolean loaderror;
700 public Boolean overload;
702 public ShellySettingsUpdate update;
703 @SerializedName("ram_total")
704 public Long ramTotal;
705 @SerializedName("ram_free")
707 @SerializedName("fs_size")
709 @SerializedName("fs_free")
713 @SerializedName("sleep_time") // Shelly Motion
714 public Integer sleepTime;
719 public static class ShellySettingsInput {
720 @SerializedName("btn_type")
721 public String btnType;
724 public static class ShellyControlRelay {
725 // https://shelly-api-docs.shelly.cloud/#shelly1-1pm-settings-relay-0
726 @SerializedName("is_valid")
727 public Boolean isValid;
728 @SerializedName("has_timer")
729 public Boolean hasTimer; // Whether a timer is currently armed for this channel
730 @SerializedName("timer_remaining")
731 public Integer timerRemaining; // FW 1.6+
732 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
734 public String turn; // Accepted values are on and off. This will turn ON/OFF the respective output
735 // channel when request is sent .
736 public Integer timer; // A one-shot flip-back timer in seconds.
739 public static class ShellyShortStatusRelay {
740 public String name; // FW 1.8+: Channel could now have a logical name
741 @SerializedName("is_valid")
742 public Boolean isValid;
743 public Boolean ison; // Whether output channel is on or off
744 @SerializedName("has_timer")
745 public Boolean hasTimer; // Whether a timer is currently armed for this channel
746 @SerializedName("timer_remaining")
747 public Integer timerRemaining;
748 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
749 public Double temperature; // Internal device temperature
750 public Boolean overtemperature; // Device over heated
753 public static class ShellyShortLightStatus {
754 public Boolean ison; // Whether output channel is on or off
755 public String mode; // color or white - valid only for Bulb and RGBW2 even Dimmer returns it also
756 public Integer brightness; // brightness: 0.100%
759 public static class ShellyStatusRelay {
760 public String name; // FW 1.8: Symbolic channel name is configurable
762 @SerializedName("wifi_sta")
763 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
764 public ShellySettingsCoiot coiot; // Firmware 1.6+
765 public Integer serial;
766 public String mac; // MAC
767 public ArrayList<ShellyShortStatusRelay> relays; // relay status
768 public ArrayList<ShellySettingsMeter> meters; // current meter value
769 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
771 @SerializedName("ext_temperature")
772 public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
773 @SerializedName("ext_humidity")
774 public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
776 public Double temperature; // device temp acc. on the selected temp unit
777 public ShellyStatusSensor.ShellySensorTmp tmp;
780 public static class ShellyStatusDimmer {
781 @SerializedName("wifi_sta")
782 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
783 public ArrayList<ShellyShortLightStatus> lights; // relay status
784 public ArrayList<ShellySettingsMeter> meters; // current meter value
786 public ShellyStatusSensor.ShellySensorTmp tmp;
787 public Boolean overtemperature;
789 public Boolean loaderror;
790 public Boolean overload;
793 public static class ShellyControlRoller {
794 public String name; // FW 1.8: Symbolic name is configurable
796 @SerializedName("roller_pos")
797 public Integer rollerPos; // number Desired position in percent
798 public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
799 // value of maxtime in /settings/roller/N will be used.
800 public String state; // One of stop, open, close
801 public Double power; // Current power consumption in Watts
802 @SerializedName("is_valid")
803 public Boolean isValid; // If the power meter functions properly
804 @SerializedName("safety_switch")
805 public Boolean safetySwitch; // Whether the safety input is currently triggered
806 public Boolean overtemperature;
807 @SerializedName("stop_reason")
808 public String stopReason; // Last cause for stopping: normal, safety_switch, obstacle
809 @SerializedName("last_direction")
810 public String lastDirection; // Last direction of motion, open or close
811 public Boolean calibrating;
812 public Boolean positioning; // true when calibration was performed
813 @SerializedName("current_pos")
814 public Integer currentPos; // current position 0..100, 100=open
817 public class ShellyOtaCheckResult {
818 public String status;
821 public class ShellyApRoaming {
822 public Boolean enabled;
823 public Integer threshold;
826 public class ShellySensorSleepMode {
827 public Integer period;
831 public static class ShellyStatusSensor {
832 // https://shelly-api-docs.shelly.cloud/#h-amp-t-settings
833 public static class ShellySensorTmp {
834 public Double value; // Temperature in configured unites
835 public String units; // 'C' or 'F'
836 public Double tC; // temperature in deg C
837 public Double tF; // temperature in deg F
838 @SerializedName("is_valid")
839 public Boolean isValid; // whether the internal sensor is operating properly
842 public static class ShellySensorHum {
843 public Double value; // relative humidity in %
846 public static class ShellySensorBat {
847 public Double value; // estimated remaining battery capacity in %
848 public Double voltage; // battery voltage
851 // Door/Window sensor
852 public static class ShellySensorState {
853 @SerializedName("is_valid")
854 public Boolean isValid; // whether the internal sensor is operating properly
855 public String state; // Shelly Door/Window
858 public Boolean motion;
859 public Boolean vibration;
860 @SerializedName("timestamp")
861 public Long motionTimestamp;
862 @SerializedName("active")
863 public Boolean motionActive;
866 public static class ShellySensorLux {
867 @SerializedName("is_valid")
868 public Boolean isValid; // whether the internal sensor is operating properly
871 public String illumination;
874 public static class ShellySensorAccel {
875 public Integer tilt; // Tilt in °
876 public Integer vibration; // Whether vibration is detected
879 public static class ShellyMotionSettings {
880 public Integer sensitivity;
881 @SerializedName("blind_time_minutes")
882 public Integer blindTimeMinutes;
883 @SerializedName("pulse_count")
884 public Integer pulseCount;
885 @SerializedName("operating_mode")
886 public Integer operatingMode;
887 public Boolean enabled;
890 public static class ShellyExtTemperature {
891 public static class ShellyShortTemp {
892 public Double tC; // temperature in deg C
893 public Double tF; // temperature in deg F
896 // Shelly 1/1PM have up to 3 sensors
897 // for whatever reasons it's not an array, but 3 independent elements
899 public ShellyShortTemp sensor1;
901 public ShellyShortTemp sensor2;
903 public ShellyShortTemp sensor3;
906 public static class ShellyExtHumidity {
907 public static class ShellyShortHum {
908 public Double hum; // Humidity reading of sensor 0, percent
911 // Shelly 1/1PM have up to 3 sensors
912 // for whatever reasons it's not an array, but 3 independent elements
914 public ShellyShortHum sensor1;
917 public static class ShellyADC {
918 public Double voltage;
921 public ShellySensorTmp tmp;
922 public ShellySensorHum hum;
923 public ShellySensorLux lux;
924 public ShellySensorAccel accel;
925 public ShellySensorBat bat;
926 @SerializedName("sensor")
927 public ShellySensorState sensor;
928 public Boolean smoke; // SHelly Smoke
929 public Boolean flood; // Shelly Flood: true = flood condition detected
930 @SerializedName("rain_sensor")
931 public Boolean rainSensor; // Shelly Flood: true=in rain mode
933 public Boolean motion; // Shelly Sense: true=motion detected
934 public Boolean charger; // Shelly Sense: true=charger connected
936 @SerializedName("act_reasons")
937 public List<Object> actReasons; // HT/Smoke/Flood: list of reasons which woke up the device
939 @SerializedName("sensor_error")
940 public String sensorError; // 1.5.7: Only displayed in case of error
942 // FW 1.7: Shelly Gas
943 @SerializedName("gas_sensor")
944 public ShellyStatusGasSensor gasSensor;
945 @SerializedName("concentration")
946 public ShellyStatusGasConcentration concentration;
947 public ArrayList<ShellyStatusValve> valves;
950 @SerializedName("connect_retries")
951 public Integer connectRetries;
952 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
954 // Shelly UNI FW 1.9+
955 public ArrayList<ShellyADC> adcs;
958 public static class ShellySettingsSmoke {
959 @SerializedName("temperature_units")
960 public String temperatureUnits; // Either 'C' or 'F'
961 @SerializedName("temperature_threshold")
962 public Integer temperatureThreshold; // Temperature delta (in configured degree units) which triggers an update
963 @SerializedName("sleep_mode_period")
964 public Integer sleepModePeriod; // Periodic update period in hours, between 1 and 24
968 // "gas_sensor":{"sensor_state":"normal","self_test_state":"not_completed","alarm_state":"none"},
969 // "concentration":{"ppm":0,"is_valid":true},
970 public static class ShellyStatusGasSensor {
971 @SerializedName("sensor_state")
972 public String sensorState;
973 @SerializedName("self_test_state")
974 public String selfTestState;
975 @SerializedName("alarm_state")
976 public String alarmState;
979 public static class ShellyStatusGasConcentration {
981 @SerializedName("is_valid")
982 public Boolean isValid;
985 public static class ShellyStatusValve {
986 public String state; // closed/opened/not_connected/failure/closing/opening/checking
989 public static class ShellySettingsLight {
990 public Integer red; // red brightness, 0..255, applies in mode="color"
991 public Integer green; // green brightness, 0..255, applies in mode="color"
992 public Integer blue; // blue brightness, 0..255, applies in mode="color"
993 public Integer white; // white brightness, 0..255, applies in mode="color"
994 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
995 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
996 public Integer brightness; // brightness, 0..100, applies in mode="white"
997 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
998 // Change, 3: Breath,
999 // 4: Flash, 5: On/Off Gradual, 6: Red/Green Change
1000 @SerializedName("default_state")
1001 public String defaultState; // one of on, off or last
1002 @SerializedName("auto_on")
1003 public Double autoOn; // see above
1004 @SerializedName("auto_off")
1005 public Double autoOff; // see above
1007 public Integer dcpower; // RGW2:Set to true for 24 V power supply, false for 12 V
1011 public Boolean ison;
1014 public static class ShellySettingsNightMode { // FW1.5.7+
1015 public Integer enabled;
1016 @SerializedName("start_time")
1017 public String startTime;
1018 @SerializedName("end_time")
1019 public String endTime;
1020 public Integer brightness;
1023 public static class ShellyStatusLightChannel {
1024 public Boolean ison;
1025 public Double power;
1026 public Boolean overpower;
1027 @SerializedName("has_timer")
1028 public Boolean hasTimer;
1029 @SerializedName("timer_started")
1030 public Integer timerStarted;
1031 @SerializedName("timer_duration")
1032 public Integer timerDuration;
1033 @SerializedName("timer_remaining")
1034 public Integer timerRemaining;
1036 public Integer red; // red brightness, 0..255, applies in mode="color"
1037 public Integer green; // green brightness, 0..255, applies in mode="color"
1038 public Integer blue; // blue brightness, 0..255, applies in mode="color"
1039 public Integer white; // white brightness, 0..255, applies in mode="color"
1040 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1041 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1042 public Integer brightness; // brightness, 0..100, applies in mode="white"
1043 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1044 // Change, 3: Breath,
1047 public static class ShellyStatusLight {
1048 public Boolean ison; // Whether output channel is on or off
1049 public Integer input;
1051 public ArrayList<ShellyStatusLightChannel> lights;
1052 public ArrayList<ShellySettingsMeter> meters;
1055 public static class ShellySenseKeyCode {
1056 String id; // ID of the stored IR code into Shelly Sense.
1057 String name; // Short description or name of the stored IR code.
1060 public static class ShellySendKeyList {
1061 @SerializedName("key_codes")
1062 public ArrayList<ShellySenseKeyCode> keyCodes;
1066 * Shelly Dimmer returns light[]. However, the structure doesn't match the lights[] of a Bulb/RGBW2.
1067 * The tag lights[] will be replaced with dimmers[] so this could be mapped to a different Gson structure.
1068 * The function requires that it's only called when the device is a dimmer - on get settings and get status
1070 * @param json Input Json as received by the API
1071 * @return Modified Json
1073 public static String fixDimmerJson(String json) {
1074 return !json.contains("\"lights\":[") ? json
1075 : json.replaceFirst(java.util.regex.Pattern.quote("\"lights\":["), "\"dimmers\":[");
1079 * Convert Shelly Button events into OH button states
1081 * @param eventType S/SS/SSS or L
1082 * @return OH button states
1084 public static String mapButtonEvent(String eventType) {
1085 // decode different codings
1087 // S/SS/SSS/L: CoAP for Button and xi3
1088 // shortpush/double_shortpush/triple_shortpush/longpush: REST
1089 switch (eventType) {
1091 return CommonTriggerEvents.RELEASED;
1093 case SHELLY_BTNEVENT_1SHORTPUSH:
1094 case SHELLY_EVENT_SHORTPUSH:
1095 return CommonTriggerEvents.SHORT_PRESSED;
1096 case SHELLY_BTNEVENT_2SHORTPUSH:
1097 case SHELLY_EVENT_DOUBLE_SHORTPUSH:
1098 return CommonTriggerEvents.DOUBLE_PRESSED;
1099 case SHELLY_BTNEVENT_3SHORTPUSH:
1100 case SHELLY_EVENT_TRIPLE_SHORTPUSH:
1101 return "TRIPLE_PRESSED";
1103 case SHELLY_BTNEVENT_LONGPUSH:
1104 case SHELLY_EVENT_LONGPUSH:
1105 return CommonTriggerEvents.LONG_PRESSED;
1106 case SHELLY_BTNEVENT_SHORTLONGPUSH:
1107 case SHELLY_EVENT_SHORT_LONGTPUSH:
1108 return "SHORT_LONG_PRESSED";
1109 case SHELLY_BTNEVENT_LONGSHORTPUSH:
1110 case SHELLY_EVENT_LONG_SHORTPUSH:
1111 return "LONG_SHORT_PRESSED";