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_TOGGLE = "toggle";
114 public static final String SHELLY_BTNT_EDGE = "edge";
115 public static final String SHELLY_BTNT_DETACHED = "detached";
117 public static final String SHELLY_STATE_LAST = "last";
118 public static final String SHELLY_STATE_STOP = "stop";
120 public static final String SHELLY_INP_MODE_OPENCLOSE = "openclose";
121 public static final String SHELLY_OBSTMODE_DISABLED = "disabled";
122 public static final String SHELLY_SAFETYM_WHILEOPENING = "while_opening";
124 public static final String SHELLY_ALWD_TRIGGER_NONE = "none";
125 public static final String SHELLY_ALWD_ROLLER_TURN_OPEN = "open";
126 public static final String SHELLY_ALWD_ROLLER_TURN_CLOSE = "close";
127 public static final String SHELLY_ALWD_ROLLER_TURN_STOP = "stop";
130 public static final String SHELLY_APIERR_UNAUTHORIZED = "Unauthorized";
131 public static final String SHELLY_APIERR_TIMEOUT = "Timeout";
132 public static final String SHELLY_APIERR_NOT_CALIBRATED = "Not calibrated!";
134 // API device types / properties
135 public static final String SHELLY_CLASS_RELAY = "relay"; // Relay: relay mode
136 public static final String SHELLY_CLASS_ROLLER = "roller"; // Relay: roller mode
137 public static final String SHELLY_CLASS_LIGHT = "light"; // Bulb: color mode
138 public static final String SHELLY_CLASS_EMETER = "emeter"; // EM/EM3: emeter
140 public static final String SHELLY_API_ON = "on";
141 public static final String SHELLY_API_OFF = "off";
142 public static final String SHELLY_API_TRUE = "true";
143 public static final String SHELLY_API_FALSE = "false";
145 public static final String SHELLY_API_MODE = "mode";
146 public static final String SHELLY_MODE_RELAY = "relay"; // Relay: relay mode
147 public static final String SHELLY_MODE_ROLLER = "roller"; // Relay: roller mode
148 public static final String SHELLY_MODE_COLOR = "color"; // Bulb/RGBW2: color mode
149 public static final String SHELLY_MODE_WHITE = "white"; // Bulb/RGBW2: white mode
151 public static final String SHELLY_LED_STATUS_DISABLE = "led_status_disable";
152 public static final String SHELLY_LED_POWER_DISABLE = "led_power_disable";
154 public static final String SHELLY_API_STOPR_NORMAL = "normal";
155 public static final String SHELLY_API_STOPR_SAFETYSW = "safety_switch";
156 public static final String SHELLY_API_STOPR_OBSTACLE = "obstacle";
157 public static final String SHELLY_API_STOPR_OVERPOWER = "overpower";
159 public static final String SHELLY_TIMER_AUTOON = "auto_on";
160 public static final String SHELLY_TIMER_AUTOOFF = "auto_off";
161 public static final String SHELLY_TIMER_ACTIVE = "has_timer";
163 public static final String SHELLY_LIGHT_TURN = "turn";
164 public static final String SHELLY_LIGHT_DEFSTATE = "def_state";
165 public static final String SHELLY_LIGHTTIMER = "timer";
167 public static final String SHELLY_COLOR_RED = "red";
168 public static final String SHELLY_COLOR_BLUE = "blue";
169 public static final String SHELLY_COLOR_GREEN = "green";
170 public static final String SHELLY_COLOR_YELLOW = "yellow";
171 public static final String SHELLY_COLOR_WHITE = "white";
172 public static final String SHELLY_COLOR_GAIN = "gain";
173 public static final String SHELLY_COLOR_BRIGHTNESS = "brightness";
174 public static final String SHELLY_COLOR_TEMP = "temp";
175 public static final String SHELLY_COLOR_EFFECT = "effect";
177 public static final int SHELLY_MIN_ROLLER_POS = 0;
178 public static final int SHELLY_MAX_ROLLER_POS = 100;
179 public static final int SHELLY_MIN_BRIGHTNESS = 0;
180 public static final int SHELLY_MAX_BRIGHTNESS = 100;
181 public static final int SHELLY_MIN_GAIN = 0;
182 public static final int SHELLY_MAX_GAIN = 100;
183 public static final int SHELLY_MIN_COLOR = 0;
184 public static final int SHELLY_MAX_COLOR = 255;
185 public static final int SHELLY_DIM_STEPSIZE = 10;
187 // color temperature: 3000 = warm, 4750 = white, 6565 = cold; gain: 0..100
188 public static final int MIN_COLOR_TEMP_BULB = 3000;
189 public static final int MAX_COLOR_TEMP_BULB = 6500;
190 public static final int MIN_COLOR_TEMP_DUO = 2700;
191 public static final int MAX_COLOR_TEMP_DUO = 6500;
192 public static final int COLOR_TEMP_RANGE_BULB = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
193 public static final int COLOR_TEMP_RANGE_DUO = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
194 public static final double MIN_BRIGHTNESS = 0.0;
195 public static final double MAX_BRIGHTNESS = 100.0;
196 public static final double SATURATION_FACTOR = 2.55;
197 public static final double GAIN_FACTOR = SHELLY_MAX_GAIN / 100;
198 public static final double BRIGHTNESS_FACTOR = SHELLY_MAX_BRIGHTNESS / 100;
201 public static final String SHELLY_API_ILLUM_DARK = "dark";
202 public static final String SHELLY_API_ILLUM_TWILIGHT = "twilight";
203 public static final String SHELLY_API_ILLUM_BRIGHT = "bright";
204 public static final String SHELLY_API_DWSTATE_OPEN = "open";
205 public static final String SHELLY_API_DWSTATE_CLOSE = "close";
208 public static final String SHELLY_IR_CODET_STORED = "stored";
209 public static final String SHELLY_IR_CODET_PRONTO = "pronto";
210 public static final String SHELLY_IR_CODET_PRONTO_HEX = "pronto_hex";
213 public static final int SHELLY_MIN_EFFECT = 0;
214 public static final int SHELLY_MAX_EFFECT = 6;
217 public static final String SHELLY_BTNEVENT_1SHORTPUSH = "S";
218 public static final String SHELLY_BTNEVENT_2SHORTPUSH = "SS";
219 public static final String SHELLY_BTNEVENT_3SHORTPUSH = "SSS";
220 public static final String SHELLY_BTNEVENT_LONGPUSH = "L";
221 public static final String SHELLY_BTNEVENT_SHORTLONGPUSH = "SL";
222 public static final String SHELLY_BTNEVENT_LONGSHORTPUSH = "LS";
224 public static final String SHELLY_TEMP_CELSIUS = "C";
225 public static final String SHELLY_TEMP_FAHRENHEIT = "F";
227 public static class ShellySettingsDevice {
230 public String hostname;
233 @SerializedName("num_outputs")
234 public Integer numOutputs;
235 @SerializedName("num_meters")
236 public Integer numMeters;
237 @SerializedName("num_emeters")
238 public Integer numEMeters;
239 @SerializedName("num_rollers")
240 public Integer numRollers;
243 public static class ShellySettingsWiFiAp {
244 public Boolean enabled;
249 public static class ShellySettingsWiFiNetwork {
250 public Boolean enabled;
254 @SerializedName("ipv4_method")
255 public String ipv4Method;
262 public static class ShellySettingsMqtt {
263 public Boolean enabled;
264 public String server;
266 @SerializedName("reconnect_timeout_max")
267 public Double reconnectTimeoutMax;
268 @SerializedName("reconnect_timeout_min")
269 public Double reconnectTimeoutMin;
270 @SerializedName("clean_session")
271 public Boolean cleanSession;
272 @SerializedName("keep_alive")
273 public Integer keepAlive;
274 @SerializedName("will_topic")
275 public String willTopic;
276 @SerializedName("will_message")
277 public String willMessage;
278 @SerializedName("max_qos")
279 public Integer maxQOS;
280 public Boolean retain;
281 @SerializedName("update_period")
282 public Integer updatePeriod;
285 public static class ShellySettingsCoiot { // FW 1.6+
286 @SerializedName("update_period")
287 public Integer updatePeriod;
290 public static class ShellySettingsSntp {
291 public String server;
294 public static class ShellySettingsLogin {
295 public Boolean enabled;
296 public Boolean unprotected;
297 public String username;
298 public String password;
301 public static class ShellySettingsBuildInfo {
302 @SerializedName("build_id")
303 public String buildId;
304 @SerializedName("build_timestamp")
305 public String buildTimestamp;
306 @SerializedName("build_version")
307 public String buildVersion;
310 public static class ShellyStatusCloud {
311 public Boolean enabled;
312 public Boolean connected;
315 public static class ShellyStatusMqtt {
316 public Boolean connected;
319 public static class ShellySettingsHwInfo {
320 @SerializedName("hw_revision")
321 public String hwRevision;
322 @SerializedName("batch_id")
323 public Integer batchId;
326 public static class ShellySettingsScheduleRules {
329 public static class ShellySettingsRelay {
332 public Boolean overpower;
333 @SerializedName("default_state")
334 public String defaultState; // Accepted values: off, on, last, switch
335 @SerializedName("btn_type")
336 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
337 @SerializedName("has_timer")
338 public Boolean hasTimer; // Whether a timer is currently armed for this channel
339 @SerializedName("auto_on")
340 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
341 @SerializedName("auto_off")
342 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
343 @SerializedName("btn_on_url")
344 public String btnOnUrl; // input is activated
345 @SerializedName("btnOffUrl")
346 public String btnOffUrl; // input is deactivated
347 @SerializedName("out_on_url")
348 public String outOnUrl; // output is activated
349 @SerializedName("out_off_url")
350 public String outOffUrl; // output is deactivated
351 @SerializedName("roller_open_url")
352 public String rollerOpenUrl; // to access when roller reaches open position
353 @SerializedName("roller_close_url")
354 public String rollerCloseUrl; // to access when roller reaches close position
355 @SerializedName("roller_stop_url")
356 public String rollerStopUrl; // to access when roller stopped
357 @SerializedName("longpush_url")
358 public String pushLongUrl; // to access when roller stopped
359 @SerializedName("shortpush_url")
360 public String pushShortUrl; // to access when roller stopped
362 public Boolean schedule;
363 // ArrayList<ShellySettingsScheduleRules> schedule_rules;
366 public static class ShellySettingsDimmer {
367 public String name; // unique name of the device
368 public Boolean ison; // true: output is ON
369 @SerializedName("default_state")
370 public String defaultState; // Accepted values: off, on, last, switch
371 @SerializedName("auto_on")
372 public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
373 @SerializedName("auto_off")
374 public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
375 @SerializedName("btn1_on_url")
376 public String btn1OnUrl; // URL to access when SW input is activated
377 @SerializedName("btn1_off_url")
378 public String btn1OffUrl; // URL to access when SW input is deactivated
379 @SerializedName("btn2_on_url")
380 public String btn2OnUrl; // URL to access when SW input is activated
381 @SerializedName("btn2_off_url")
382 public String btn2OoffUrl; // URL to access when SW input is deactivated
383 @SerializedName("out_on_url")
384 public String outOnUrl; // URL to access when output is activated
385 @SerializedName("out_off_url")
386 public String outOffUrl; // URL to access when output is deactivated
387 @SerializedName("longpush_url")
388 public String pushLongUrl; // long push button event
389 @SerializedName("shortpush_url")
390 public String pushShortUrl; // short push button event
391 @SerializedName("btn_type")
392 public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
393 @SerializedName("swap_inputs")
394 public Integer swapInputs; // 0=no
397 public static class ShellySettingsRoller {
398 public Double maxtime;
399 @SerializedName("maxtime_open")
400 public Double maxtimeOpen;
401 @SerializedName("maxtime_close")
402 public Double maxtimeClose;
403 @SerializedName("default_state")
404 public String defaultState; // see SHELLY_STATE_xxx
406 @SerializedName("swap_inputs")
407 public Boolean swapInputs;
408 @SerializedName("input_mode")
409 public String inputMode; // see SHELLY_INP_MODE_OPENCLOSE
410 @SerializedName("button_type")
411 public String buttonType; // // see SHELLY_BTNT_xxx
412 @SerializedName("btn_Reverse")
413 public Integer btnReverse;
416 @SerializedName("is_valid")
417 public Boolean isValid;
418 @SerializedName("safety_switch")
419 public Boolean safetySwitch;
420 public Boolean schedule;
421 // ArrayList<ShellySettingsScheduleRules> schedule_rules; // not used for now
422 @SerializedName("obstacle_mode")
423 public String obstaclMode; // SHELLY_OBSTMODE_
424 @SerializedName("obstacle_action")
425 public String obstacleAction; // see SHELLY_STATE_xxx
426 @SerializedName("obstacle_power")
427 public Integer obstaclePower;
428 @SerializedName("obstacle_delay")
429 public Integer obstacleDelay;
430 @SerializedName("safety_mode")
431 public String safetyMode; // see SHELLY_SAFETYM_xxx
432 @SerializedName("safety_action")
433 public String safetyAction; // see SHELLY_STATE_xxx
434 @SerializedName("safety_allowed_on_trigger")
435 public String safetyAllowedOnTrigger; // see SHELLY_ALWD_TRIGGER_xxx
436 @SerializedName("off_power")
437 public Integer offPower;
438 public Boolean positioning;
441 public static class ShellyInputState {
442 public Integer input;
446 @SerializedName("event_cnt")
447 public Integer eventCount;
450 public static class ShellySettingsMeter {
451 @SerializedName("is_valid")
452 public Boolean isValid;
454 public Double[] counters = { 0.0, 0.0, 0.0 };
456 public Long timestamp;
459 public static class ShellySettingsEMeter { // ShellyEM meter
460 @SerializedName("is_valid")
461 public Boolean isValid; // Whether the associated meter is functioning properly
462 public Double power; // Instantaneous power, Watts
463 public Double reactive; // Instantaneous reactive power, Watts
464 public Double voltage; // RMS voltage, Volts
465 public Double total; // Total consumed energy, Wh
466 @SerializedName("total_returned")
467 public Double totalReturned; // Total returned energy, Wh
469 public Double pf; // 3EM
470 public Double current; // 3EM
473 public static class ShellySettingsUpdate {
474 public String status;
475 @SerializedName("has_update")
476 public Boolean hasUpdate;
477 @SerializedName("new_version")
478 public String newVersion;
479 @SerializedName("old_version")
480 public String oldVersion;
483 public static class ShellySettingsGlobal {
484 // https://shelly-api-docs.shelly.cloud/#shelly1pm-settings
485 public ShellySettingsDevice device;
486 @SerializedName("wifi_ap")
487 public ShellySettingsWiFiAp wifiAp;
488 @SerializedName("wifi_sta")
489 public ShellySettingsWiFiNetwork wifiSta;
490 @SerializedName("wifi_sta1")
491 public ShellySettingsWiFiNetwork wifiSta1;
492 // public ShellySettingsMqtt mqtt; // not used for now
493 // public ShellySettingsSntp sntp; // not used for now
494 public ShellySettingsCoiot coiot; // Firmware 1.6+
495 public ShellySettingsLogin login;
496 @SerializedName("pin_code")
497 public String pinCode;
498 @SerializedName("coiot_execute_enable")
499 public Boolean coiotExecuteEnable;
501 public Boolean discoverable; // FW 1.6+
503 @SerializedName("build_info")
504 ShellySettingsBuildInfo buildInfo;
505 ShellyStatusCloud cloud;
506 @SerializedName("sleep_mode")
507 public ShellySensorSleepMode sleepMode; // FW 1.6
509 // @SerializedName("ext_temperature")
510 // public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
511 // @SerializedName("ext_humidity")
512 // public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
514 public String timezone;
517 public Boolean tzautodetect;
519 // @SerializedName("tz_utc_offset")
520 // public Integer tzUTCOoffset; // FW 1.6+
521 // @SerializedName("tz_dst")
522 // public Boolean tzDdst; // FW 1.6+
523 // @SerializedName("tz_dst_auto")
524 // public Boolean tzDstAuto; // FW 1.6+
525 // public Long unixtime; // FW 1.6+
527 public ShellySettingsHwInfo hwinfo;
529 @SerializedName("max_power")
530 public Double maxPower;
532 public ArrayList<ShellySettingsRelay> relays;
533 public ArrayList<ShellySettingsDimmer> dimmers;
534 public ArrayList<ShellySettingsEMeter> emeters;
535 public ArrayList<ShellySettingsInput> inputs; // ix3
537 @SerializedName("temperature_units")
538 public String temperatureUnits; // Either'C'or'F'
540 @SerializedName("led_status_disable")
541 public Boolean ledStatusDisable; // PlugS only Disable LED indication for network
543 @SerializedName("led_power_disable")
544 public Boolean ledPowerDisable; // PlugS only Disable LED indication for network
546 @SerializedName("light_sensor")
547 public String lightSensor; // Sense: sensor type
548 @SerializedName("rain_sensor")
549 public Boolean rainSensor; // Flood: true=in rain mode
551 // FW 1.5.7: Door Window
552 @SerializedName("dark_treshold")
553 public Integer darkTreshold; // Illumination definition for "dark" in lux
554 @SerializedName("twilight_treshold")
555 public Integer twiLightTreshold; // Illumination definition for "twilight" in lux
556 @SerializedName("dark_url")
557 public String darkUrl; // URL to report to when luminance <= dark_threshold
558 @SerializedName("twilight_url")
559 public String twiLightUrl; // URL reports when luminance > dark_threshold AND luminance <=
560 @SerializedName("close_url")
561 public String closeUrl; // URL reports when DW contact is closed FW 1.6.5+
562 @SerializedName("vibration_url")
563 public String vibrationUrl; // URL reports when DW detects vibration FW 1.6.5+
565 // @SerializedName("tilt_enabled")
566 // public Boolean tiltEnabled; // Whether tilt monitoring is activated
567 // @SerializedName("tilt_calibrated")
568 // public Boolean tiltCalibrated; // Whether calibration data is valid
569 // @SerializedName("vibration_enabled")
570 // public Boolean vibrationEnabled; // Whether vibration monitoring is activated
571 // @SerializedName("reverse_open_close")
572 // public Boolean reverseOpenClose; // Whether to reverse which position the sensor consideres "open"
575 @SerializedName("set_volume")
576 public Integer volume; // Speaker volume for alarm
577 @SerializedName("alarm_off_url")
578 public String alarmOffUrl; // URL reports when alarm went off
579 @SerializedName("alarm_mild_url")
580 public String alarmMidUrl; // URL reports middle alarm
581 @SerializedName("alarm_heavy_url")
582 public String alarmHeavyfUrl; // URL reports heavy alarm
585 public static class ShellySettingsAttributes {
586 @SerializedName("device_type")
587 public String deviceType; // Device model identifier
588 @SerializedName("device_mac")
589 public String deviceMac; // MAC address of the device in hexadecimal
590 @SerializedName("wifi_ap")
591 public String wifiAp; // WiFi access poInteger configuration, see /settings/ap for details
592 @SerializedName("wifi_sta")
593 public String wifiSta; // WiFi client configuration. See /settings/sta for details
594 public String login; // credentials used for HTTP Basic authentication for the REST interface. If
595 // enabled is true clients must include an Authorization: Basic ... HTTP header with valid
596 // credentials when performing TP requests.
597 public String name; // unique name of the device.
598 public String fw; // current FW version
601 public static class ShellySettingsStatus {
602 public String name; // FW 1.8: Symbolic Device name is configurable
604 @SerializedName("wifi_sta")
605 public ShellySettingsWiFiNetwork wifiSta; // WiFi client configuration. See /settings/sta for details
608 public Integer serial;
609 @SerializedName("has_update")
610 public Boolean hasUpdate;
612 public Boolean discoverable; // FW 1.6+
613 @SerializedName("cfg_changed_cnt")
614 public Integer cfgChangedCount; // FW 1.8
616 public ArrayList<ShellySettingsRelay> relays;
617 public ArrayList<ShellySettingsRoller> rollers;
618 public Integer input; // RGBW2 has no JSON array
619 public ArrayList<ShellyInputState> inputs;
620 public ArrayList<ShellySettingsLight> lights;
621 // @SerializedName("night_mode") // FW 1.5.7+
622 // public ShellySettingsNightMode nightMode;
623 public ArrayList<ShellyShortLightStatus> dimmers;
624 public ArrayList<ShellySettingsMeter> meters;
625 public ArrayList<ShellySettingsEMeter> emeters;
627 // Internal device temp
628 public ShellyStatusSensor.ShellySensorTmp tmp; // Shelly 1PM
629 public Double temperature; // Shelly 2.5
630 public Boolean overtemperature;
632 // Shelly Dimmer only
633 public Boolean loaderror;
634 public Boolean overload;
636 public ShellySettingsUpdate update;
637 @SerializedName("ram_total")
638 public Long ramTotal;
639 @SerializedName("ram_free")
641 @SerializedName("fs_size")
643 @SerializedName("fs_free")
650 public static class ShellySettingsInput {
651 @SerializedName("btn_type")
652 public String btnType;
654 // included attributes not yet processed
655 // public String name;
656 // @SerializedName("btn_reverse")
657 // public Integer btnReverse;
658 // @SerializedName("btn_on_url")
659 // public String btnOnUrl;
660 // @SerializedName("btn_off_url")
661 // public String btnOffUrl;
662 // @SerializedName("shortpush_url")
663 // public String shortpushUrl;
664 // @SerializedName("longpush_url")
665 // public String longpushUrl;
666 // @SerializedName("double_shortpush_url")
667 // public String doubleShortpushUrl;
668 // @SerializedName("triple_shortpush_url")
669 // public String tripleShortpushUrl;
670 // @SerializedName("shortpush_longpush_url")
671 // public String shortpushLongpushUrl;
672 // @SerializedName("longpush_shortpush_url")
673 // public String longpushShortpushUrl;
676 public static class ShellyControlRelay {
677 // https://shelly-api-docs.shelly.cloud/#shelly1-1pm-settings-relay-0
678 @SerializedName("is_valid")
679 public Boolean isValid;
680 @SerializedName("has_timer")
681 public Boolean hasTimer; // Whether a timer is currently armed for this channel
682 @SerializedName("timer_remaining")
683 public Integer timerRemaining; // FW 1.6+
684 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
686 public String turn; // Accepted values are on and off. This will turn ON/OFF the respective output
687 // channel when request is sent .
688 public Integer timer; // A one-shot flip-back timer in seconds.
691 public static class ShellyShortStatusRelay {
692 public String name; // FW 1.8+: Channel could now have a logical name
693 @SerializedName("is_valid")
694 public Boolean isValid;
695 public Boolean ison; // Whether output channel is on or off
696 @SerializedName("has_timer")
697 public Boolean hasTimer; // Whether a timer is currently armed for this channel
698 @SerializedName("timer_remaining")
699 public Integer timerRemaining;
700 public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
701 public Double temperature; // Internal device temperature
702 public Boolean overtemperature; // Device over heated
705 public static class ShellyShortLightStatus {
706 public Boolean ison; // Whether output channel is on or off
707 public String mode; // color or white - valid only for Bulb and RGBW2 even Dimmer returns it also
708 public Integer brightness; // brightness: 0.100%
709 // @SerializedName("has_timer")
710 // public Boolean hasTimer; // Whether a timer is currently armed for this channel
711 // @SerializedName("timer_remaining")
712 // public Integer timerRemaining;
713 // public Integer wgite;
714 // public Integer temp; // light temp
717 public static class ShellyStatusRelay {
718 public String name; // FW 1.8: Symbolic channel name is configurable
720 @SerializedName("wifi_sta")
721 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
722 // public ShellyStatusCloud cloud; // Cloud status
723 // public ShellyStatusMqtt mqtt; // mqtt status
724 public ShellySettingsCoiot coiot; // Firmware 1.6+
725 // public String time; // current time
726 public Integer serial;
727 public String mac; // MAC
728 public ArrayList<ShellyShortStatusRelay> relays; // relay status
729 public ArrayList<ShellySettingsMeter> meters; // current meter value
731 @SerializedName("ext_temperature")
732 public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
733 @SerializedName("ext_humidity")
734 public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
736 public Double temperature; // device temp acc. on the selected temp unit
737 public ShellyStatusSensor.ShellySensorTmp tmp;
739 @SerializedName("has_update")
740 public Boolean hasUpdate; // If a newer firmware version is available
741 public ShellySettingsUpdate update; // /status/firmware value
743 @SerializedName("ram_total")
744 public Integer ramTotal; // Total and available amount of system memory in bytes
745 @SerializedName("ram_free")
746 public Integer ramFree;
747 @SerializedName("fs_size")
748 public Integer fsSize;
749 @SerializedName("fs_free")
750 public Integer fsFree; // Total and available amount of file system space in bytes
751 public Integer uptime; // econds elapsed since boot
754 public static class ShellyStatusDimmer {
755 @SerializedName("wifi_sta")
756 public ShellySettingsWiFiNetwork wifiSta; // WiFi status
757 // public ShellyStatusCloud cloud; // Cloud status
758 // public ShellyStatusMqtt mqtt; // mqtt status
759 public String time; // current time
760 public Integer serial;
761 public String mac; // MAC
762 public ArrayList<ShellyShortLightStatus> lights; // relay status
763 public ArrayList<ShellySettingsMeter> meters; // current meter value
765 public ShellyStatusSensor.ShellySensorTmp tmp;
766 public Boolean overtemperature;
768 public Boolean loaderror;
769 public Boolean overload;
771 @SerializedName("has_update")
772 public Boolean hasUpdate; // If a newer firmware version is available
773 public ShellySettingsUpdate update; // /status/firmware value
775 @SerializedName("ram_total")
776 public Integer ramTotal; // Total and available amount of system memory in
778 @SerializedName("ram_free")
779 public Integer ramFree;
780 @SerializedName("fs_size")
781 public Integer fsSize;
782 @SerializedName("fs_free")
783 public Integer fsFree; // Total and available amount of file system space in bytes
784 public Integer uptime; // seconds elapsed since boot
787 public static class ShellyControlRoller {
788 public String name; // FW 1.8: Symbolic name is configurable
790 @SerializedName("roller_pos")
791 public Integer rollerPos; // number Desired position in percent
792 public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
793 // value of maxtime in /settings/roller/N will be used.
794 public String state; // One of stop, open, close
795 public Double power; // Current power consumption in Watts
796 @SerializedName("is_valid")
797 public Boolean isValid; // If the power meter functions properly
798 @SerializedName("safety_switch")
799 public Boolean safetySwitch; // Whether the safety input is currently triggered
800 public Boolean overtemperature;
801 @SerializedName("stop_reason")
802 public String stopReason; // Last cause for stopping: normal, safety_switch, obstacle
803 @SerializedName("last_direction")
804 public String lastDirection; // Last direction of motion, open or close
805 public Boolean calibrating;
806 public Boolean positioning; // true when calibration was performed
807 @SerializedName("current_pos")
808 public Integer currentPos; // current position 0..100, 100=open
811 public class ShellySensorSleepMode {
812 public Integer period;
816 public static class ShellyStatusSensor {
817 // https://shelly-api-docs.shelly.cloud/#h-amp-t-settings
818 public static class ShellySensorTmp {
819 public Double value; // Temperature in configured unites
820 public String units; // 'C' or 'F'
821 public Double tC; // temperature in deg C
822 public Double tF; // temperature in deg F
823 @SerializedName("is_valid")
824 public Boolean isValid; // whether the internal sensor is operating properly
827 public static class ShellySensorHum {
828 public Double value; // relative humidity in %
831 public static class ShellySensorBat {
832 public Double value; // estimated remaining battery capacity in %
833 public Double voltage; // battery voltage
836 // Door/Window sensor
837 public static class ShellySensorState {
838 @SerializedName("is_valid")
839 public Boolean isValid; // whether the internal sensor is operating properly
840 public String state; // Shelly Door/Window
843 public static class ShellySensorLux {
844 @SerializedName("is_valid")
845 public Boolean isValid; // whether the internal sensor is operating properly
848 public String illumination;
851 public static class ShellySensorAccel {
852 public Integer tilt; // Tilt in °
853 public Integer vibration; // Whether vibration is detected
856 public static class ShellyExtTemperature {
857 public static class ShellyShortTemp {
858 public Double tC; // temperature in deg C
859 public Double tF; // temperature in deg F
862 // Shelly 1/1PM have up to 3 sensors
863 // for whatever reasons it's not an array, but 3 independent elements
865 public ShellyShortTemp sensor1;
867 public ShellyShortTemp sensor2;
869 public ShellyShortTemp sensor3;
872 public static class ShellyExtHumidity {
873 public static class ShellyShortHum {
874 public Double hum; // Humidity reading of sensor 0, percent
877 // Shelly 1/1PM have up to 3 sensors
878 // for whatever reasons it's not an array, but 3 independent elements
880 public ShellyShortHum sensor1;
883 public ShellySensorTmp tmp;
884 public ShellySensorHum hum;
885 public ShellySensorLux lux;
886 public ShellySensorAccel accel;
887 public ShellySensorBat bat;
888 @SerializedName("sensor")
889 public ShellySensorState contact;
890 public Boolean smoke; // SHelly Smoke
891 public Boolean flood; // Shelly Flood: true = flood condition detected
892 @SerializedName("rain_sensor")
893 public Boolean rainSensor; // Shelly Flood: true=in rain mode
895 public Boolean motion; // Shelly Sense: true=motion detected
896 public Boolean charger; // Shelly Sense: true=charger connected
897 @SerializedName("external_power")
898 public Integer externalPower; // H&T FW 1.6, seems to be the same like charger for the Sense
900 @SerializedName("act_reasons")
901 public List<Object> actReasons; // HT/Smoke/Flood: list of reasons which woke up the device
903 @SerializedName("sensor_error")
904 public String sensorError; // 1.5.7: Only displayed in case of error
906 // FW 1.7: Shelly Gas
907 @SerializedName("gas_sensor")
908 public ShellyStatusGasSensor gasSensor;
909 @SerializedName("concentration")
910 public ShellyStatusGasConcentration concentration;
911 public ArrayList<ShellyStatusValve> valves;
914 @SerializedName("connect_retries")
915 public Integer connectRetries;
916 public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
919 public static class ShellySettingsSmoke {
920 @SerializedName("temperature_units")
921 public String temperatureUnits; // Either 'C' or 'F'
922 @SerializedName("temperature_threshold")
923 public Integer temperatureThreshold; // Temperature delta (in configured degree units) which triggers an update
924 @SerializedName("sleep_mode_period")
925 public Integer sleepModePeriod; // Periodic update period in hours, between 1 and 24
929 // "gas_sensor":{"sensor_state":"normal","self_test_state":"not_completed","alarm_state":"none"},
930 // "concentration":{"ppm":0,"is_valid":true},
931 public static class ShellyStatusGasSensor {
932 @SerializedName("sensor_state")
933 public String sensorState;
934 @SerializedName("self_test_state")
935 public String selfTestState;
936 @SerializedName("alarm_state")
937 public String alarmState;
940 public static class ShellyStatusGasConcentration {
942 @SerializedName("is_valid")
943 public Boolean isValid;
946 public static class ShellyStatusValve {
947 public String state; // closed/opened/not_connected/failure/closing/opening/checking
950 public static class ShellySettingsLight {
951 public Integer red; // red brightness, 0..255, applies in mode="color"
952 public Integer green; // green brightness, 0..255, applies in mode="color"
953 public Integer blue; // blue brightness, 0..255, applies in mode="color"
954 public Integer white; // white brightness, 0..255, applies in mode="color"
955 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
956 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
957 public Integer brightness; // brightness, 0..100, applies in mode="white"
958 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
959 // Change, 3: Breath,
960 // 4: Flash, 5: On/Off Gradual, 6: Red/Green Change
961 @SerializedName("default_state")
962 public String defaultState; // one of on, off or last
963 @SerializedName("auto_on")
964 public Double autoOn; // see above
965 @SerializedName("auto_off")
966 public Double autoOff; // see above
968 public Integer dcpower; // RGW2:Set to true for 24 V power supply, false for 12 V
975 public static class ShellySettingsNightMode { // FW1.5.7+
976 public Integer enabled;
977 @SerializedName("start_time")
978 public String startTime;
979 @SerializedName("end_time")
980 public String endTime;
981 public Integer brightness;
984 public static class ShellyStatusLightChannel {
987 public Boolean overpower;
988 @SerializedName("auto_on")
989 public Double autoOn; // see above
990 @SerializedName("auto_off")
991 public Double autoOff; // see above
993 public Integer red; // red brightness, 0..255, applies in mode="color"
994 public Integer green; // green brightness, 0..255, applies in mode="color"
995 public Integer blue; // blue brightness, 0..255, applies in mode="color"
996 public Integer white; // white brightness, 0..255, applies in mode="color"
997 public Integer gain; // gain for all channels, 0..100, applies in mode="color"
998 public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
999 public Integer brightness; // brightness, 0..100, applies in mode="white"
1000 public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1001 // Change, 3: Breath,
1004 public static class ShellyStatusLight {
1005 public Boolean ison; // Whether output channel is on or off
1006 public ArrayList<ShellyStatusLightChannel> lights;
1007 public ArrayList<ShellySettingsMeter> meters;
1008 public Integer input;
1011 // public String mode; // COLOR or WHITE
1012 // public Boolean has_update;
1013 // public ShellySettingsUpdate update;
1014 // public ShellySettingsWiFiNetwork wifi_sta; // WiFi client configuration. See
1015 // /settings/sta for details
1016 // public ShellyStatusCloud cloud;
1017 // public ShellyStatusMqtt mqtt;
1020 public static class ShellySenseKeyCode {
1021 String id; // ID of the stored IR code into Shelly Sense.
1022 String name; // Short description or name of the stored IR code.
1025 public static class ShellySendKeyList {
1026 @SerializedName("key_codes")
1027 public ArrayList<ShellySenseKeyCode> keyCodes;
1031 * Shelly Dimmer returns light[]. However, the structure doesn't match the lights[] of a Bulb/RGBW2.
1032 * The tag lights[] will be replaced with dimmers[] so this could be mapped to a different Gson structure.
1033 * The function requires that it's only called when the device is a dimmer - on get settings and get status
1035 * @param json Input Json as received by the API
1036 * @return Modified Json
1038 public static String fixDimmerJson(String json) {
1039 return !json.contains("\"lights\":[") ? json
1040 : json.replaceFirst(java.util.regex.Pattern.quote("\"lights\":["), "\"dimmers\":[");
1044 * Convert Shelly Button events into OH button states
1046 * @param eventType S/SS/SSS or L
1047 * @return OH button states
1049 public static String mapButtonEvent(String eventType) {
1050 // decode different codings
1052 // S/SS/SSS/L: CoAP for Button and xi3
1053 // shortpush/double_shortpush/triple_shortpush/longpush: REST
1054 switch (eventType) {
1056 return CommonTriggerEvents.RELEASED;
1058 case SHELLY_BTNEVENT_1SHORTPUSH:
1059 case SHELLY_EVENT_SHORTPUSH:
1060 return CommonTriggerEvents.SHORT_PRESSED;
1061 case SHELLY_BTNEVENT_2SHORTPUSH:
1062 case SHELLY_EVENT_DOUBLE_SHORTPUSH:
1063 return CommonTriggerEvents.DOUBLE_PRESSED;
1064 case SHELLY_BTNEVENT_3SHORTPUSH:
1065 case SHELLY_EVENT_TRIPLE_SHORTPUSH:
1066 return "TRIPLE_PRESSED";
1068 case SHELLY_BTNEVENT_LONGPUSH:
1069 case SHELLY_EVENT_LONGPUSH:
1070 return CommonTriggerEvents.LONG_PRESSED;
1071 case SHELLY_BTNEVENT_SHORTLONGPUSH:
1072 case SHELLY_EVENT_SHORT_LONGTPUSH:
1073 return "SHORT_LONG_PRESSED";
1074 case SHELLY_BTNEVENT_LONGSHORTPUSH:
1075 case SHELLY_EVENT_LONG_SHORTPUSH:
1076 return "LONG_SHORT_PRESSED";