Skip to content

Commit

Permalink
WIP Shelly Plug US support
Browse files Browse the repository at this point in the history
Stock calls it "us1", implying there may be 2 at som point, so we call it
ShellyPlugUS1 as well.

#749
  • Loading branch information
rojer authored and timoschilling committed Feb 1, 2023
1 parent 6492dd0 commit ec6cb68
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
6 changes: 4 additions & 2 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 ShellyPlugUS1 ShellyPlus1 ShellyPlus1PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI

MOS ?= mos
# Build locally by default if Docker is available.
Expand Down Expand Up @@ -64,6 +63,9 @@ ShellyPlug: build-ShellyPlug
ShellyPlugS: build-ShellyPlugS
@true

ShellyPlugUS1: build-ShellyPlugUS1
@true

ShellyPlus1: PLATFORM=esp32
ShellyPlus1: build-ShellyPlus1
@true
Expand Down
31 changes: 31 additions & 0 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,37 @@ 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 == "ShellyPlugUS1"
apply:
name: shelly-plug-us1
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", 1.64358469] # Same as ShellyPlugS

- when: build_vars.MODEL == "ShellyPlus1"
apply:
name: Plus1
Expand Down
52 changes: 52 additions & 0 deletions src/ShellyPlugUS1/shelly_init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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));
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

0 comments on commit ec6cb68

Please sign in to comment.