Skip to content

Commit

Permalink
Support for Shelly Plus Plug S (#1305)
Browse files Browse the repository at this point in the history
* split build and format into 2 workflows

* use build matrix

* Add basic support for Shelly Plus Plug S

- No LED support

* Update support matrix

* add model to github action build; fix upgradability from newer stock fws; fix pinning, remove neopixel as output, they are not a relay

* fix github actions; fix encrypted partition extra

* use neopixel as state led

* Readme support

---------

Co-authored-by: Timo Schilling <timo@schilling.io>
Co-authored-by: Markus Kirberg <markus@flobby.met>
Co-authored-by: Markus Kirberg <markus@flobby.net>
  • Loading branch information
4 people authored Jun 10, 2024
1 parent beb1b62 commit 8ccdc21
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 12 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@ jobs:
strategy:
fail-fast: false
matrix:
model: [Shelly1, Shelly1L, Shelly1PM, Shelly25, Shelly2, ShellyColorBulb, ShellyDuo, ShellyI3, ShellyPlug, ShellyPlugS, ShellyPlus1, ShellyPlus1PM, ShellyPlus2PM, ShellyPlusI4, ShellyRGBW2, ShellyVintage, ShellyUNI]
model:
- Shelly1
- Shelly1L
- Shelly1PM
- Shelly2
- Shelly25
- ShellyColorBulb
- ShellyDuo
- ShellyI3
- ShellyPlug
- ShellyPlugS
- ShellyPlus1
- ShellyPlus1PM
- ShellyPlus2PM
- ShellyPlusI4
- ShellyPlusPlugS
- ShellyRGBW2
- ShellyUNI
- ShellyVintage
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
8 changes: 6 additions & 2 deletions 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 ShellyPlus1 ShellyPlus1PM ShellyPlus2PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI
Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlusPlugS ShellyPlus1 ShellyPlus1PM ShellyPlus2PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI
.SUFFIXES:

MOS ?= mos
Expand All @@ -27,7 +27,7 @@ ifneq "$(VERBOSE)$(V)" "00"
MOS_BUILD_FLAGS_FINAL += --verbose
endif

build: Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlus1 ShellyPlus1PM ShellyPlus2PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyURGBW2 ShellyUNI
build: Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlusPlugS ShellyPlus1 ShellyPlus1PM ShellyPlus2PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyURGBW2 ShellyUNI

release:
$(MAKE) build CLEAN=1 RELEASE=1
Expand Down Expand Up @@ -64,6 +64,10 @@ ShellyPlug: build-ShellyPlug
ShellyPlugS: build-ShellyPlugS
@true

ShellyPlusPlugS: PLATFORM=esp32
ShellyPlusPlugS: build-ShellyPlusPlugS
@true

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

## Supported devices and features


### Plus devices

| |[+1]|[+1PM]|[+2PM]|+i4 [AC]/[DC]|
|- |- |- |- |- |
|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]|[+1PM]|[+2PM]|+i4 [AC]/[DC]|[+Plug S]
|- |- |- |- |- |-
|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>|✓ |✓ |✓ |✓ |

### Pro devices

Expand Down
33 changes: 33 additions & 0 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,39 @@ conds:
- ["bl0937.power_coeff", "f", 0, {title: "BL0937 counts -> watts conversion coefficient"}]
- ["bl0937.power_coeff", 1.64358469] # (16 + 1010 + 1935) / (9.55 + 617 + 1175)

- when: build_vars.MODEL == "ShellyPlusPlugS"
apply:
name: PlusPlugS
build_vars:
MGOS_ROOT_FS_TYPE: LFS
MGOS_ROOT_FS_SIZE: 458752
ESP_IDF_EXTRA_PARTITION: "aux,0x55,0x00,0x3f0000,48K"
ESP_IDF_EXTRA_PARTITION_2: "shelly,data,0x88,0x3fc000,16K,encrypted"
ESP_IDF_SDKCONFIG_OPTS: >
${build_vars.ESP_IDF_SDKCONFIG_OPTS}
CONFIG_FREERTOS_UNICORE=y
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
cdefs:
LED_GPIO: 25
LED_ON: 1
BTN_GPIO: 9
BTN_DOWN: 1
PRODUCT_HW_REV: "2.0.0"
STOCK_FW_MODEL: SHPPLG-S
MAX_NUM_HAP_SESSIONS: 16
config_schema:
- ["device.id", "shellyplusplug-s-??????"]
- ["shelly.name", "shellyplusplug-s-??????"]
- ["wifi.ap.ssid", "shellyplusplug-s-??????"]
- ["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]
- ["bl0937.power_coeff", "f", 0, {title: "BL0937 counts -> watts conversion coefficient"}]
- ["bl0937.power_coeff", 1.64358469] # (16 + 1010 + 1935) / (9.55 + 617 + 1175)

- when: build_vars.MODEL == "ShellyPlus1"
apply:
name: Plus1
Expand Down
61 changes: 61 additions & 0 deletions src/ShellyPlusPlugS/shelly_init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) Shelly-HomeKit Contributors
* All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "mgos_gpio.h"
#include "shelly_main.hpp"
#include "shelly_output.hpp"
#include "shelly_pm_bl0937.hpp"
#include "shelly_sys_led_btn.hpp"
#include "shelly_temp_sensor_ntc.hpp"

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));

// 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));

std::unique_ptr<PowerMeter> pm(
new BL0937PowerMeter(1, 10 /* CF */, 22 /* CF1 */, 19 /* SEL */, 2,
mgos_sys_config_get_bl0937_power_coeff()));
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));

InitSysLED(LED_GPIO, LED_ON);
InitSysBtn(BTN_GPIO, BTN_DOWN);
}

void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
std::vector<std::unique_ptr<mgos::hap::Accessory>> *accs,
HAPAccessoryServerRef *svr) {
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), nullptr, comps, accs, svr,
true /* to_pri_acc */, FindOutput(3));
}

} // namespace shelly
1 change: 1 addition & 0 deletions tools/shelly_update_server/stock_model_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ models:
shellyix3: ShellyI3
shellyplug: ShellyPlug
shellyplug-s: ShellyPlugS
PlusPlugS: ShellyPlusPlugS
shellyplus1: ShellyPlus1
ShellyPlus1: ShellyPlus1
shellyplus1pm: ShellyPlus1PM
Expand Down

0 comments on commit 8ccdc21

Please sign in to comment.