2 * Copyright (c) 2010-2023 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.api2;
15 import java.util.ArrayList;
17 import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult;
18 import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RpcBaseMessage.Shelly2RpcMessageError;
20 import com.google.gson.annotations.SerializedName;
23 * {@link Shelly2ApiJsonDTO} wraps the Shelly REST API and provides various low level function to access the device api
27 * @author Markus Michels - Initial contribution
29 public class Shelly2ApiJsonDTO {
30 public static final String SHELLYRPC_METHOD_CLASS_SHELLY = "Shelly";
31 public static final String SHELLYRPC_METHOD_CLASS_SWITCH = "Switch";
33 public static final String SHELLYRPC_METHOD_GETDEVCONFIG = "GetDeviceInfo";
34 public static final String SHELLYRPC_METHOD_GETSYSCONFIG = "GetSysConfig"; // only sys
35 public static final String SHELLYRPC_METHOD_GETCONFIG = "GetConfig"; // sys + components
36 public static final String SHELLYRPC_METHOD_GETSYSSTATUS = "GetSysStatus"; // only sys
37 public static final String SHELLYRPC_METHOD_GETSTATUS = "GetStatus"; // sys + components
38 public static final String SHELLYRPC_METHOD_REBOOT = "Shelly.Reboot";
39 public static final String SHELLYRPC_METHOD_RESET = "Shelly.FactoryReset";
40 public static final String SHELLYRPC_METHOD_CHECKUPD = "Shelly.CheckForUpdate";
41 public static final String SHELLYRPC_METHOD_UPDATE = "Shelly.Update";
42 public static final String SHELLYRPC_METHOD_AUTHSET = "Shelly.SetAuth";
43 public static final String SHELLYRPC_METHOD_SWITCH_STATUS = "Switch.GetStatus";
44 public static final String SHELLYRPC_METHOD_SWITCH_SET = "Switch.Set";
45 public static final String SHELLYRPC_METHOD_SWITCH_SETCONFIG = "Switch.SetConfig";
46 public static final String SHELLYRPC_METHOD_COVER_SETPOS = "Cover.GoToPosition";
47 public static final String SHELLY2_COVER_CMD_OPEN = "Open";
48 public static final String SHELLY2_COVER_CMD_CLOSE = "Close";
49 public static final String SHELLY2_COVER_CMD_STOP = "Stop";
50 public static final String SHELLYRPC_METHOD_WIFIGETCONG = "Wifi.GetConfig";
51 public static final String SHELLYRPC_METHOD_WIFISETCONG = "Wifi.SetConfig";
52 public static final String SHELLYRPC_METHOD_ETHGETCONG = "Eth.GetConfig";
53 public static final String SHELLYRPC_METHOD_ETHSETCONG = "Eth.SetConfig";
54 public static final String SHELLYRPC_METHOD_BLEGETCONG = "BLE.GetConfig";
55 public static final String SHELLYRPC_METHOD_BLESETCONG = "BLE.SetConfig";
56 public static final String SHELLYRPC_METHOD_CLOUDSET = "Cloud.SetConfig";
57 public static final String SHELLYRPC_METHOD_WSGETCONFIG = "WS.GetConfig";
58 public static final String SHELLYRPC_METHOD_WSSETCONFIG = "WS.SetConfig";
60 public static final String SHELLYRPC_METHOD_NOTIFYSTATUS = "NotifyStatus"; // inbound status
61 public static final String SHELLYRPC_METHOD_NOTIFYFULLSTATUS = "NotifyFullStatus"; // inbound status from bat device
62 public static final String SHELLYRPC_METHOD_NOTIFYEVENT = "NotifyEvent"; // inbound event
65 public static final String SHELLY2_PROFILE_RELAY = "switch";
66 public static final String SHELLY2_PROFILE_ROLLER = "cover";
69 public static final String SHELLY2_BTNT_MOMENTARY = "momentary";
70 public static final String SHELLY2_BTNT_FLIP = "flip";
71 public static final String SHELLY2_BTNT_FOLLOW = "follow";
72 public static final String SHELLY2_BTNT_DETACHED = "detached";
75 public static final String SHELLY2_INPUTT_SWITCH = "switch";
76 public static final String SHELLY2_INPUTT_BUTTON = "button";
77 public static final String SHELLY2_INPUTT_ANALOG = "analog"; // Shelly Addon: analogous input
80 public static final String SHELLY2_API_MODE_DETACHED = "detached";
81 public static final String SHELLY2_API_MODE_FOLLOW = "follow";
83 // Initial switch states
84 public static final String SHELLY2_API_ISTATE_ON = "on";
85 public static final String SHELLY2_API_ISTATE_OFF = "off";
86 public static final String SHELLY2_API_ISTATE_FOLLOWLAST = "restore_last";
87 public static final String SHELLY2_API_ISTATE_MATCHINPUT = "match_input";
90 public static final String SHELLY2_RMODE_SINGLE = "single";
91 public static final String SHELLY2_RMODE_DUAL = "dual";
92 public static final String SHELLY2_RMODE_DETACHED = "detached";
94 public static final String SHELLY2_RSTATE_OPENING = "opening";
95 public static final String SHELLY2_RSTATE_OPEN = "open";
96 public static final String SHELLY2_RSTATE_CLOSING = "closing";
97 public static final String SHELLY2_RSTATE_CLOSED = "closed";
98 public static final String SHELLY2_RSTATE_STOPPED = "stopped";
99 public static final String SHELLY2_RSTATE_CALIB = "calibrating";
101 // Event notifications
102 public static final String SHELLY2_EVENT_BTNUP = "btn_up";
103 public static final String SHELLY2_EVENT_BTNDOWN = "btn_down";
104 public static final String SHELLY2_EVENT_1PUSH = "single_push";
105 public static final String SHELLY2_EVENT_2PUSH = "double_push";
106 public static final String SHELLY2_EVENT_3PUSH = "triple_push";
107 public static final String SHELLY2_EVENT_LPUSH = "long_push";
108 public static final String SHELLY2_EVENT_SLPUSH = "short_long_push";
109 public static final String SHELLY2_EVENT_LSPUSH = "long_short_push";
111 public static final String SHELLY2_EVENT_SLEEP = "sleep";
112 public static final String SHELLY2_EVENT_CFGCHANGED = "config_changed";
113 public static final String SHELLY2_EVENT_OTASTART = "ota_begin";
114 public static final String SHELLY2_EVENT_OTAPROGRESS = "ota_progress";
115 public static final String SHELLY2_EVENT_OTADONE = "ota_success";
116 public static final String SHELLY2_EVENT_WIFICONNFAILED = "sta_connect_fail";
117 public static final String SHELLY2_EVENT_WIFIDISCONNECTED = "sta_disconnected";
120 public static final String SHELLY2_ERROR_OVERPOWER = "overpower";
121 public static final String SHELLY2_ERROR_OVERTEMP = "overtemp";
122 public static final String SHELLY2_ERROR_OVERVOLTAGE = "overvoltage";
124 // Wakeup reasons (e.g. Plus HT)
125 public static final String SHELLY2_WAKEUPO_BOOT_POWERON = "poweron";
126 public static final String SHELLY2_WAKEUPO_BOOT_RESTART = "software_restart";
127 public static final String SHELLY2_WAKEUPO_BOOT_WAKEUP = "deepsleep_wake";
128 public static final String SHELLY2_WAKEUPO_BOOT_INTERNAL = "internal";
129 public static final String SHELLY2_WAKEUPO_BOOT_UNKNOWN = "unknown";
131 public static final String SHELLY2_WAKEUPOCAUSE_BUTTON = "button";
132 public static final String SHELLY2_WAKEUPOCAUSE_USB = "usb";
133 public static final String SHELLY2_WAKEUPOCAUSE_PERIODIC = "periodic";
134 public static final String SHELLY2_WAKEUPOCAUSE_UPDATE = "status_update";
135 public static final String SHELLY2_WAKEUPOCAUSE_UNDEFINED = "undefined";
137 public class Shelly2DevConfigBle {
138 public Boolean enable;
141 public class Shelly2DevConfigEth {
142 public Boolean enable;
143 public String ipv4mode;
145 public String netmask;
147 public String nameserver;
150 public static class Shelly2DeviceSettings {
156 @SerializedName("fw_id")
157 public String firmware;
160 @SerializedName("auth_en")
161 public Boolean authEnable;
162 @SerializedName("auth_domain")
163 public String authDomain;
166 public static class Shelly2DeviceConfigAp {
167 public static class Shelly2DeviceConfigApRE {
168 public Boolean enable;
171 public Boolean enable;
173 public String password;
174 @SerializedName("is_open")
175 public Boolean isOpen;
176 @SerializedName("range_extender")
177 Shelly2DeviceConfigApRE rangeExtender;
180 public static class Shelly2DeviceConfig {
181 public class Shelly2DeviceConfigSys {
182 public class Shelly2DeviceConfigDevice {
185 @SerializedName("fw_id")
187 public String profile;
188 @SerializedName("eco_mode")
189 public Boolean ecoMode;
190 public Boolean discoverable;
193 public class Shelly2DeviceConfigLocation {
199 public class Shelly2DeviceConfigSntp {
200 public String server;
203 public class Shelly2DeviceConfigSleep {
204 @SerializedName("wakeup_period")
205 public Integer wakeupPeriod;
208 public class Shelly2DeviceConfigDebug {
209 public class Shelly2DeviceConfigDebugMqtt {
210 public Boolean enable;
213 public class Shelly2DeviceConfigDebugWebSocket {
214 public Boolean enable;
217 public class Shelly2DeviceConfigDebugUdp {
221 public Shelly2DeviceConfigDebugMqtt mqtt;
222 public Shelly2DeviceConfigDebugWebSocket websocket;
223 public Shelly2DeviceConfigDebugUdp udp;
226 public class Shelly2DeviceConfigUiData {
227 public String cover; // hold comma seperated list of roller favorites
230 public class Shelly2DeviceConfigRpcUdp {
231 @SerializedName("dst_addr")
232 public String dstAddr;
233 @SerializedName("listenPort")
234 public String listenPort;
237 @SerializedName("cfg_rev")
238 public Integer cfgRevision;
239 public Shelly2DeviceConfigDevice device;
240 public Shelly2DeviceConfigLocation location;
241 public Shelly2DeviceConfigSntp sntp;
242 public Shelly2DeviceConfigSleep sleep;
243 public Shelly2DeviceConfigDebug debug;
244 @SerializedName("ui_data")
245 public Shelly2DeviceConfigUiData uiData;
246 @SerializedName("rpc_udp")
247 public Shelly2DeviceConfigRpcUdp rpcUdp;
250 public class Shelly2DevConfigInput {
254 public Boolean invert;
255 @SerializedName("factory_reset")
256 public Boolean factoryReset;
257 @SerializedName("report_thr")
258 public Double reportTreshold; // only for type analog
261 public class Shelly2DevConfigSwitch {
265 @SerializedName("in_mode")
268 @SerializedName("initial_state")
269 public String initialState;
270 @SerializedName("auto_on")
271 public Boolean autoOn;
272 @SerializedName("auto_on_delay")
273 public Double autoOnDelay;
274 @SerializedName("auto_off")
275 public Boolean autoOff;
276 @SerializedName("auto_off_delay")
277 public Double autoOffDelay;
278 @SerializedName("power_limit")
279 public Integer powerLimit;
280 @SerializedName("voltage_limit")
281 public Integer voltageLimit;
282 @SerializedName("current_limit")
283 public Double currentLimit;
286 public class Shelly2DevConfigCover {
287 public class Shelly2DeviceConfigCoverMotor {
288 @SerializedName("idle_power_thr")
289 public Double idle_powerThr;
292 public class Shelly2DeviceConfigCoverSafetySwitch {
293 public Boolean enable;
294 public String direction;
295 public String action;
296 @SerializedName("allowed_move")
297 public String allowedMove;
300 public class Shelly2DeviceConfigCoverObstructionDetection {
301 public Boolean enable;
302 public String direction;
303 public String action;
304 @SerializedName("power_thr")
305 public Integer powerThr;
306 public Double holdoff;
311 public Shelly2DeviceConfigCoverMotor motor;
312 @SerializedName("maxtime_open")
313 public Double maxtimeOpen;
314 @SerializedName("maxtime_close")
315 public Double maxtimeClose;
316 @SerializedName("initial_state")
317 public String initialState;
318 @SerializedName("invert_directions")
319 public Boolean invertDirections;
320 @SerializedName("in_mode")
321 public String inMode;
322 @SerializedName("swap_inputs")
323 public Boolean swapInputs;
324 @SerializedName("safety_switch")
325 public Shelly2DeviceConfigCoverSafetySwitch safetySwitch;
326 @SerializedName("power_limit")
327 public Integer powerLimit;
328 @SerializedName("voltage_limit")
329 public Integer voltageLimit;
330 @SerializedName("current_limit")
331 public Double currentLimit;
332 @SerializedName("obstruction_detection")
333 public Shelly2DeviceConfigCoverObstructionDetection obstructionDetection;
336 public static class Shelly2GetConfigResult {
338 public class Shelly2DevConfigCloud {
339 public Boolean enable;
340 public String server;
343 public class Shelly2DevConfigMqtt {
344 public Boolean enable;
345 public String server;
347 @SerializedName("topic_prefix:0")
348 public String topicPrefix;
349 @SerializedName("rpc_ntf")
350 public String rpcNtf;
351 @SerializedName("status_ntf")
352 public String statusNtf;
355 public Shelly2DevConfigBle ble;
356 public Shelly2DevConfigEth eth;
357 public Shelly2DevConfigCloud cloud;
358 public Shelly2DevConfigMqtt mqtt;
359 public Shelly2DeviceConfigSys sys;
360 public Shelly2DeviceConfigWiFi wifi;
362 @SerializedName("input:0")
363 public Shelly2DevConfigInput input0;
364 @SerializedName("input:1")
365 public Shelly2DevConfigInput input1;
366 @SerializedName("input:2")
367 public Shelly2DevConfigInput input2;
368 @SerializedName("input:3")
369 public Shelly2DevConfigInput input3;
371 @SerializedName("switch:0")
372 public Shelly2DevConfigSwitch switch0;
373 @SerializedName("switch:1")
374 public Shelly2DevConfigSwitch switch1;
375 @SerializedName("switch:2")
376 public Shelly2DevConfigSwitch switch2;
377 @SerializedName("switch:3")
378 public Shelly2DevConfigSwitch switch3;
380 @SerializedName("cover:0")
381 public Shelly2DevConfigCover cover0;
384 public class Shelly2DeviceConfigSta {
386 public String password;
387 @SerializedName("is_open")
388 public Boolean isOpen;
389 public Boolean enable;
390 public String ipv4mode;
392 public String netmask;
394 public String nameserver;
397 public class Shelly2DeviceConfigRoam {
398 @SerializedName("rssi_thr")
399 public Integer rssiThr;
400 public Integer interval;
403 public class Shelly2DeviceConfigWiFi {
404 public Shelly2DeviceConfigAp ap;
405 public Shelly2DeviceConfigSta sta;
406 public Shelly2DeviceConfigSta sta1;
407 public Shelly2DeviceConfigRoam roam;
412 public Shelly2GetConfigResult result;
415 public static class Shelly2DeviceStatus {
416 public class Shelly2InputStatus {
418 public Boolean state;
419 public Double percent; // analog input only
420 public ArrayList<String> errors;// shown only if at least one error is present.
423 public static class Shelly2DeviceStatusResult {
424 public class Shelly2DeviceStatusBle {
428 public class Shelly2DeviceStatusCloud {
429 public Boolean connected;
432 public class Shelly2DeviceStatusMqqt {
433 public Boolean connected;
436 public class Shelly2CoverStatus {
438 public String source;
440 public Double apower;
441 public Double voltage;
442 public Double current;
444 public Shelly2Energy aenergy;
445 @SerializedName("current_pos")
446 public Integer currentPos;
447 @SerializedName("target_pos")
448 public Integer targetPos;
449 @SerializedName("move_timeout")
450 public Double moveTimeout;
451 @SerializedName("move_started_at")
452 public Double moveStartedAt;
453 @SerializedName("pos_control")
454 public Boolean posControl;
455 public Shelly2DeviceStatusTemp temperature;
456 public ArrayList<String> errors;
459 public class Shelly2DeviceStatusHumidity {
464 public class Shelly2DeviceStatusVoltage {
466 public Double voltage;
469 public class Shelly2DeviceStatusTempId extends Shelly2DeviceStatusTemp {
473 public static class Shelly2DeviceStatusPower {
474 public static class Shelly2DeviceStatusBattery {
477 public Double percent;
480 public static class Shelly2DeviceStatusCharger {
481 public Boolean present;
485 public Shelly2DeviceStatusBattery battery;
486 public Shelly2DeviceStatusCharger external;
489 public Shelly2DeviceStatusBle ble;
490 public Shelly2DeviceStatusCloud cloud;
491 public Shelly2DeviceStatusMqqt mqtt;
492 public Shelly2DeviceStatusSys sys;
493 public Shelly2DeviceStatusSysWiFi wifi;
495 @SerializedName("input:0")
496 public Shelly2InputStatus input0;
497 @SerializedName("input:1")
498 public Shelly2InputStatus input1;
499 @SerializedName("input:2")
500 public Shelly2InputStatus input2;
501 @SerializedName("input:3")
502 public Shelly2InputStatus input3;
503 @SerializedName("input:100")
504 public Shelly2InputStatus input100; // Digital Input from Add-On
506 @SerializedName("switch:0")
507 public Shelly2RelayStatus switch0;
508 @SerializedName("switch:1")
509 public Shelly2RelayStatus switch1;
510 @SerializedName("switch:2")
511 public Shelly2RelayStatus switch2;
512 @SerializedName("switch:3")
513 public Shelly2RelayStatus switch3;
515 @SerializedName("cover:0")
516 public Shelly2CoverStatus cover0;
518 @SerializedName("temperature:0")
519 public Shelly2DeviceStatusTempId temperature0;
520 @SerializedName("temperature:100")
521 public Shelly2DeviceStatusTempId temperature100;
522 @SerializedName("temperature:101")
523 public Shelly2DeviceStatusTempId temperature101;
524 @SerializedName("temperature:102")
525 public Shelly2DeviceStatusTempId temperature102;
526 @SerializedName("temperature:103")
527 public Shelly2DeviceStatusTempId temperature103;
528 @SerializedName("temperature:104")
529 public Shelly2DeviceStatusTempId temperature104;
531 @SerializedName("humidity:0")
532 public Shelly2DeviceStatusHumidity humidity0;
533 @SerializedName("humidity:100")
534 public Shelly2DeviceStatusHumidity humidity100;
536 @SerializedName("voltmeter:100")
537 public Shelly2DeviceStatusVoltage voltmeter100;
539 @SerializedName("devicepower:0")
540 public Shelly2DeviceStatusPower devicepower0;
543 public class Shelly2DeviceStatusSys {
544 public class Shelly2DeviceStatusSysAvlUpdate {
545 public class Shelly2DeviceStatusSysUpdate {
546 public String version;
549 public Shelly2DeviceStatusSysUpdate stable;
550 public Shelly2DeviceStatusSysUpdate beta;
553 public class Shelly2DeviceStatusWakeup {
559 @SerializedName("restart_required")
560 public Boolean restartRequired;
562 public Long unixtime;
564 @SerializedName("ram_size")
566 @SerializedName("ram_free")
568 @SerializedName("fs_size")
570 @SerializedName("fs_free")
572 @SerializedName("cfg_rev")
573 public Integer cfg_rev;
574 @SerializedName("available_updates")
575 public Shelly2DeviceStatusSysAvlUpdate availableUpdates;
576 @SerializedName("webhook_rev")
577 public Integer webHookRev;
578 @SerializedName("wakeup_reason")
579 public Shelly2DeviceStatusWakeup wakeUpReason;
580 @SerializedName("wakeup_period")
581 public Integer wakeupPeriod;
584 public class Shelly2DeviceStatusSysWiFi {
585 @SerializedName("sta_ip")
587 public String status;
590 @SerializedName("ap_client_count")
591 public Integer apClientCount;
596 public Shelly2DeviceStatusResult result;
599 public static class Shelly2RelayStatus {
601 public String source;
602 public Boolean output;
603 @SerializedName("timer_started_at")
604 public Double timerStartetAt;
605 @SerializedName("timer_duration")
606 public Integer timerDuration;
607 public Double apower;
608 public Double voltage;
609 public Double current;
611 public Shelly2Energy aenergy;
612 public Shelly2DeviceStatusTemp temperature;
613 public String[] errors;
616 public static class Shelly2DeviceStatusTemp {
621 public static class Shelly2Energy {
622 // "switch:1":{"id":1,"aenergy":{"total":0.003,"by_minute":[0.000,0.000,0.000],"minute_ts":1619910239}}}}
624 @SerializedName("by_minute")
625 public Double[] byMinute;
626 @SerializedName("minute_ts")
627 public Long minuteTs;
630 public static class Shelly2ConfigParms {
632 public Boolean enable;
633 public String server;
634 @SerializedName("ssl_ca")
638 public Shelly2DeviceConfigAp ap;
641 @SerializedName("auto_on")
642 public Boolean autoOn;
643 @SerializedName("auto_on_delay")
644 public Double autoOnDelay;
645 @SerializedName("auto_off")
646 public Boolean autoOff;
647 @SerializedName("auto_off_delay")
648 public Double autoOffDelay;
651 public static class Shelly2RpcRequest {
652 public Integer id = 0;
653 public String method;
655 public static class Shelly2RpcRequestParams {
656 public Integer id = 1;
672 public Shelly2ConfigParms config;
674 public Shelly2RpcRequestParams withConfig() {
675 config = new Shelly2ConfigParms();
680 public Shelly2RpcRequestParams params = new Shelly2RpcRequestParams();
682 public Shelly2RpcRequest() {
685 public Shelly2RpcRequest withMethod(String method) {
686 this.method = method;
690 public Shelly2RpcRequest withId(int id) {
695 public Shelly2RpcRequest withPos(int pos) {
701 public static class Shelly2WsConfigResponse {
705 public static class Shelly2WsConfigResult {
706 @SerializedName("restart_required")
707 public Boolean restartRequired;
710 public Shelly2WsConfigResult result;
713 public static class Shelly2RpcBaseMessage {
714 // Basic message format, e.g.
715 // {"id":1,"src":"localweb528","method":"Shelly.GetConfig"}
716 public class Shelly2RpcMessageError {
718 public String message;
724 public String method;
725 public Object params;
726 public Object result;
727 public Shelly2AuthRequest auth;
728 public Shelly2RpcMessageError error;
731 public static class Shelly2RpcNotifyStatus {
732 public static class Shelly2NotifyStatus extends Shelly2DeviceStatusResult {
739 public String method;
740 public Shelly2NotifyStatus params;
741 public Shelly2NotifyStatus result;
742 public Shelly2RpcMessageError error;
745 public static String SHELLY2_AUTHTTYPE_DIGEST = "digest";
746 public static String SHELLY2_AUTHTTYPE_STRING = "string";
747 public static String SHELLY2_AUTHALG_SHA256 = "SHA-256";
748 // = ':auth:'+HexHash("dummy_method:dummy_uri");
749 public static String SHELLY2_AUTH_NOISE = "6370ec69915103833b5222b368555393393f098bfbfbb59f47e0590af135f062";
751 public static class Shelly2AuthRequest {
752 public String username;
757 public String algorithm;
758 public String response;
759 @SerializedName("auth_type")
760 public String authType;
763 public static class Shelly2AuthResponse { // on 401 message contains the auth info
764 @SerializedName("auth_type")
765 public String authType;
769 public String algorithm;
772 public class Shelly2NotifyEvent {
775 public String component;
778 public Integer reason;
779 @SerializedName("cfg_rev")
780 public Integer cfgRev;
783 public class Shelly2NotifyEventData {
785 public ArrayList<Shelly2NotifyEvent> events;
788 public static class Shelly2RpcNotifyEvent {
790 Shelly2NotifyEventData params;