Skip to content

Commit

Permalink
Shelly PlugS G3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
markirb committed Dec 28, 2024
1 parent 9e2c75d commit 77fb283
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- Shelly1PMGen3
- Shelly1Gen3
- ShellyI4Gen3
- ShellyPlugSGen3
# - Shelly25
# - ShellyColorBulb
# - ShellyDuo
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MAKEFLAGS += --warn-undefined-variables --no-builtin-rules

.PHONY: build check-format format release upload \
Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlusPlugS ShellyPlus1 ShellyPlus1PM ShellyPlus2PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI ShellyPlus1Mini ShellyPlusRGBWPM ShellyMini1Gen3 ShellyMini1PMGen3 Shelly2PMGen3 Shelly1PMGen3 Shelly1Gen3 ShellyI4Gen3
Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlusPlugS ShellyPlus1 ShellyPlus1PM ShellyPlus2PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI ShellyPlus1Mini ShellyPlusRGBWPM ShellyMini1Gen3 ShellyMini1PMGen3 Shelly2PMGen3 Shelly1PMGen3 Shelly1Gen3 ShellyI4Gen3 ShellyPlugSGen3
.SUFFIXES:

MOS ?= mos
Expand Down Expand Up @@ -112,6 +112,10 @@ Shelly2PMGen3: PLATFORM=esp32c3
Shelly2PMGen3: build-Shelly2PMGen3
@true

ShellyPlugSGen3: PLATFORM=esp32c3
ShellyPlugSGen3: build-ShellyPlugSGen3
@true

ShellyMini1Gen3: PLATFORM=esp32c3
ShellyMini1Gen3: build-ShellyMini1Gen3
@true
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ Reverting to stock firmware is also possible [see here](https://github.com/mongo

### Gen 3 Devices

| |[1 G3] |[1PM G3] |[2PM G3] |[I4 G3] |[Mini1 G3]|[Mini1PM G3]
|- |- |- |- |- |- |-
|Switch & Co.<sup>1</sup> |✓ |✓ |✓ |✗ |✓ |✓
|Stateless Input<sup>2</sup> |✓ |✓ |✓ |✓ |✓ |✓
|Sensors<sup>3</sup> |✓ |✓ |✓ |✓ |✓ |✓
|Garage door opener |✓ |✓ |✓ |✗ |✓ |✓
|Roller shutter mode |✗ |✗ |- |✗ |✗ |✗
|Power measurement |✗ |✓ |- |✗ |✗ |✓
|Temperature/Humidity measurement<sup>4</sup>|- |- |- |- |✗ |✗
| |[1 G3] |[1PM G3] |[2PM G3] |[I4 G3] |[Mini1 G3]|[Mini1PM G3]|[PlugS G3]
|- |- |- |- |- |- |- |-
|Switch & Co.<sup>1</sup> |✓ |✓ |✓ |✗ |✓ |✓ |✓
|Stateless Input<sup>2</sup> |✓ |✓ |✓ |✓ |✓ |✓ |✗
|Sensors<sup>3</sup> |✓ |✓ |✓ |✓ |✓ |✓ |✗
|Garage door opener |✓ |✓ |✓ |✗ |✓ |✓ |✗
|Roller shutter mode |✗ |✗ |- |✗ |✗ |✗ |✗
|Power measurement |✗ |✓ |- |✗ |✗ |✓ |✓
|Temperature/Humidity measurement<sup>4</sup>|- |- |- |- |✗ |✗ |✗

### Plus devices

Expand Down Expand Up @@ -190,6 +190,7 @@ This firmware is free software and is distributed under [Apache 2.0 license](LIC
[1PM G3]: https://www.shelly.cloud/en/products/shop/shelly-1pm-gen3
[1 G3]: https://www.shelly.cloud/en/products/shop/shelly-1-gen3
[I4 G3]: https://www.shelly.cloud/en/products/shop/shelly-i4-gen3
[PlugS G3]: https://www.shelly.com/products/shelly-plug-s-gen3
[+1PM]: https://www.shelly.cloud/en/products/shop/shelly-plus-1-pm-2-pack/shelly-plus-1-pm
[+2PM]: https://www.shelly.cloud/en/products/shop/shelly-plus-2-pm
[+RGBWPM]: https://www.shelly.cloud/en/products/shop/shelly-plus-rgbw-pm
Expand Down
52 changes: 52 additions & 0 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ conds:
LED_ON: 1
BTN_GPIO: 9
BTN_DOWN: 0
RELAY_GPIO: 4
NEOPX_GPIO: 25
NEOPX1_GPIO: 26
ADC_GPIO: 33
PRODUCT_HW_REV: "2.0.0"
STOCK_FW_MODEL: PlusPlugS
MAX_NUM_HAP_SESSIONS: 16
Expand Down Expand Up @@ -893,6 +897,54 @@ conds:
- ["ts5", "ts", {title: "TS5 settings"}]
- ["ts5.name", "Shelly TS5"]

- when: build_vars.MODEL == "ShellyPlugSGen3"
apply:
name: PlugSG3
sources:
- src/ShellyPlusPlugS
- src/BL0942
libs:
- location: https://github.com/mongoose-os-libs/mongoose
build_vars:
OTA_DATA_ADDR: 0x10000
OTA_DATA_SIZE: 0x4000
NVS_ADDR: 0x14000
NVS_SIZE: 0xC000
APP_OFFSET: 0x20000
APP_SLOT_SIZE: 0x280000
MGOS_ROOT_FS_TYPE: LFS
MGOS_ROOT_FS_SIZE: 1048576
ESP_IDF_EXTRA_PARTITION: "scratch,data,0x80,0x720000,0x80000,encrypted"
ESP_IDF_EXTRA_PARTITION_2: "shelly,data,0x88,0x7F0000,64K,encrypted"
ESP_IDF_SDKCONFIG_OPTS: >
${build_vars.ESP_IDF_SDKCONFIG_OPTS}
CONFIG_FREERTOS_UNICORE=y
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
cdefs:
LED_GPIO: -1
LED_ON: 1
BTN_GPIO: 18
BTN_DOWN: 0
RELAY_GPIO: 5
NEOPX_GPIO: 4
ADC_GPIO: 3
UART_TX_GPIO: 6
UART_RX_GPIO: 7
PRODUCT_HW_REV: "?"
STOCK_FW_MODEL: PlusPlugS
MAX_NUM_HAP_SESSIONS: 16
config_schema:
- ["device.id", "ShellyPlugSG3-??????"]
- ["shelly.name", "ShellyPlugSG3-??????"]
- ["wifi.ap.ssid", "ShellyPlugSG3-??????"]
- ["sw1", "sw", {title: "Plug settings"}]
- ["sw1.name", "Shelly Plus Plug S"]
- ["sw1.in_mode", -1]
- ["sw1.svc_type", 1] # Outlet
- ["sw1.initial_state", 2]
- ["sw1.state_led_en", 1]

- when: build_vars.MODEL == "Shelly1PMGen3"
apply:
name: S1PMG3
Expand Down
22 changes: 16 additions & 6 deletions src/ShellyPlusPlugS/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,40 @@
#include "shelly_sys_led_btn.hpp"
#include "shelly_temp_sensor_ntc.hpp"

#ifdef UART_TX_GPIO
#include "shelly_pm_bl0942.hpp"
#endif

namespace shelly {

void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
std::vector<std::unique_ptr<Output>> *outputs,
std::vector<std::unique_ptr<PowerMeter>> *pms,
std::unique_ptr<TempSensor> *sys_temp) {
outputs->emplace_back(new OutputPin(1, 4, 1));
outputs->emplace_back(new OutputPin(1, RELAY_GPIO, 1));

// TODO: GPIO 25 and 26 are actually neopixel lights, and are not used as such
// currently
outputs->emplace_back(new OutputPin(2, 25, 1));
outputs->emplace_back(new OutputPin(3, 26, 1));
outputs->emplace_back(new OutputPin(2, NEOPX_GPIO, 1));
#ifdef NEOPX1_GPIO
outputs->emplace_back(new OutputPin(3, NEOPX1_GPIO, 1));
#endif

#ifndef UART_TX_GPIO
std::unique_ptr<PowerMeter> pm(
new BL0937PowerMeter(1, 10 /* CF */, 22 /* CF1 */, 19 /* SEL */, 2,
mgos_sys_config_get_bl0937_power_coeff()));
#else
std::unique_ptr<PowerMeter> pm(
new BL0942PowerMeter(1, UART_TX_GPIO, UART_RX_GPIO, 1, 1));
#endif

const Status &st = pm->Init();
if (st.ok()) {
pms->emplace_back(std::move(pm));
} else {
const std::string &s = st.ToString();
LOG(LL_ERROR, ("PM init failed: %s", s.c_str()));
}
sys_temp->reset(new TempSensorSDNT1608X103F3950(33, 3.3f, 10000.0f));
sys_temp->reset(new TempSensorSDNT1608X103F3950(ADC_GPIO, 3.3f, 10000.0f));

InitSysLED(LED_GPIO, LED_ON);
InitSysBtn(BTN_GPIO, BTN_DOWN);
Expand Down

0 comments on commit 77fb283

Please sign in to comment.