Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shelly Plug US support #1211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +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 ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI
.SUFFIXES:
Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlugUS ShellyPlus1 ShellyPlus1PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI

MOS ?= mos
# Build locally by default if Docker is available.
Expand All @@ -27,7 +26,7 @@ ifneq "$(VERBOSE)$(V)" "00"
MOS_BUILD_FLAGS_FINAL += --verbose
endif

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

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

ShellyPlugUS: build-ShellyPlugUS
@true

ShellyPlus1: PLATFORM=esp32
ShellyPlus1: build-ShellyPlus1
@true
Expand Down
32 changes: 32 additions & 0 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,38 @@ 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 == "ShellyPlugUS"
apply:
name: shelly-plug-u1
libs:
- location: https://github.com/mongoose-os-libs/mongoose
variant: esp8266-nossl
build_vars:
FLASH_SIZE: 2097152
FS_SIZE: 262144
BOOT_CONFIG_ADDR: 0x7000
MGOS_ROOT_FS_TYPE: SPIFFS
cdefs:
LED_GPIO: 2 # Blue, 0 red.
LED_ON: 0
BTN_GPIO: 13
BTN_DOWN: 0
PRODUCT_HW_REV: '"1.0"'
STOCK_FW_MODEL: '"SHPLG-U1"'
MG_ENABLE_SSL: 0
config_schema:
- ["device.id", "shellyplugu1-??????"]
- ["shelly.name", "shellyplugu1-??????"]
- ["wifi.ap.ssid", "shellyplugu1-??????"]
- ["sw1", "sw", {title: "Plug settings"}]
- ["sw1.name", "Shelly Plug US"]
- ["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] # Same as ShellyPlugS

- when: build_vars.MODEL == "ShellyPlus1"
apply:
name: Plus1
Expand Down
53 changes: 53 additions & 0 deletions src/ShellyPlugUS/shelly_init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 "shelly_main.hpp"
#include "shelly_output.hpp"
#include "shelly_pm_bl0937.hpp"
#include "shelly_temp_sensor_ntc.hpp"

namespace shelly {

static OutputPin *s_led_out = nullptr;

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, 15, 1));
s_led_out = new OutputPin(99, 0, 0); // Red LED.
std::unique_ptr<PowerMeter> pm(
new BL0937PowerMeter(1, 5 /* CF */, 14 /* CF1 */, 12 /* 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(0, 3.3f, 33000.0f));
}

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 */, s_led_out);
}

} // namespace shelly