Skip to content

Commit

Permalink
v5.12.0j - Add Sunrise/set timer option
Browse files Browse the repository at this point in the history
5.12.0j
 * Add optional Sunrise and Sunset timers with commands Latitide
and Longitude to be enabled with define USE_SUNRISE in user_config.h
(#2317)
  • Loading branch information
arendst committed Apr 5, 2018
1 parent f205a68 commit 524979a
Show file tree
Hide file tree
Showing 23 changed files with 388 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Sonoff-Tasmota
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.

Current version is **5.12.0i** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
Current version is **5.12.0j** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.

### Quick install

Expand Down
5 changes: 4 additions & 1 deletion sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* 5.12.0i
/* 5.12.0j
* Add optional Sunrise and Sunset timers with commands Latitide and Longitude to be enabled with define USE_SUNRISE in user_config.h (#2317)
*
* 5.12.0i
* Add 16 timers using commands Timer and Timers (#1091)
* Add commands Timer 0 to clear timer and Timer 1..16 to copy timer
* Add optional Timer configuration webpage to be enabled in user_config.h with define USE_TIMERS_WEB
Expand Down
11 changes: 8 additions & 3 deletions sonoff/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
#define D_JSON_STARTUPUTC "StartupUTC"
#define D_JSON_SUBNETMASK "Subnetmask"
#define D_JSON_SUCCESSFUL "Successful"
#define D_JSON_SUNRISE "Sunrise"
#define D_JSON_SUNSET "Sunset"
#define D_JSON_SWITCH "Switch"
#define D_JSON_SYNC "Sync"
#define D_JSON_TEMPERATURE "Temperature"
Expand Down Expand Up @@ -270,9 +272,9 @@
#define D_CMND_IRSEND "IRSend"
#define D_JSON_INVALID_JSON "Invalid JSON"
#define D_JSON_PROTOCOL_NOT_SUPPORTED "Protocol not supported"
#define D_JSON_IR_PROTOCOL "PROTOCOL"
#define D_JSON_IR_BITS "BITS"
#define D_JSON_IR_DATA "DATA"
#define D_JSON_IR_PROTOCOL "Protocol"
#define D_JSON_IR_BITS "Bits"
#define D_JSON_IR_DATA "Data"
#define D_CMND_IRHVAC "IRHVAC"
#define D_JSON_IRHVAC_VENDOR "VENDOR"
#define D_JSON_IRHVAC_POWER "POWER"
Expand Down Expand Up @@ -354,13 +356,16 @@
// Commands xdrv_09_timers.ino
#define D_CMND_TIMER "Timer"
#define D_JSON_TIMER_ARM "Arm"
#define D_JSON_TIMER_MODE "Mode"
#define D_JSON_TIMER_TIME "Time"
#define D_JSON_TIMER_DAYS "Days"
#define D_JSON_TIMER_REPEAT "Repeat"
#define D_JSON_TIMER_OUTPUT "Output"
#define D_JSON_TIMER_POWER "Power"
#define D_JSON_TIMER_NO_DEVICE "No GPIO as output configured"
#define D_CMND_TIMERS "Timers"
#define D_CMND_LATITUDE "Latitude"
#define D_CMND_LONGITUDE "Longitude"

/********************************************************************************************/

Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/cs-CZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Maska podsítě"
#define D_SUBSCRIBE_TO "Přihlaš se do"
#define D_SUCCESSFUL "úspěšné."
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "Teplota"
#define D_TO "do"
#define D_TOGGLE "Přepni"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/de-DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Subnetzmaske"
#define D_SUBSCRIBE_TO "subscribe to"
#define D_SUCCESSFUL "erfolgreich"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "Temperatur"
#define D_TO "zu"
#define D_TOGGLE "An/Aus"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/en-GB.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Subnet Mask"
#define D_SUBSCRIBE_TO "Subscribe to"
#define D_SUCCESSFUL "Successful"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "Temperature"
#define D_TO "to"
#define D_TOGGLE "Toggle"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/es-AR.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Máscara Subred"
#define D_SUBSCRIBE_TO "Suscribir a"
#define D_SUCCESSFUL "Exitosa"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "Temperatura"
#define D_TO "a"
#define D_TOGGLE "Conmutar"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/fr-FR.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Masque sous réseau"
#define D_SUBSCRIBE_TO "Souscrire à"
#define D_SUCCESSFUL "Réussi"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "Temperature"
#define D_TO "à"
#define D_TOGGLE "Bascule"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/hu-HU.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Subnet Mask"
#define D_SUBSCRIBE_TO "Feliratkozás a"
#define D_SUCCESSFUL "Sikeres"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "Hőmérséklet"
#define D_TO "-nak"
#define D_TOGGLE "Toggle"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/it-IT.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Maschera sottorete"
#define D_SUBSCRIBE_TO "Sottoscrivi a"
#define D_SUCCESSFUL "Riuscito"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "Temperatura"
#define D_TO "a"
#define D_TOGGLE "Toggle"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/nl-NL.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Subnet Masker"
#define D_SUBSCRIBE_TO "Abonneer op"
#define D_SUCCESSFUL "Gelukt"
#define D_SUNRISE "Zonsopgang"
#define D_SUNSET "Zonsondergang"
#define D_TEMPERATURE "Temperatuur"
#define D_TO "naar"
#define D_TOGGLE "Toggle" // Wissel, Tuimel
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/pl-PL.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Maska podsieci"
#define D_SUBSCRIBE_TO "Subskrybuj do"
#define D_SUCCESSFUL "Powodzenie"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "Temperatura"
#define D_TO "do"
#define D_TOGGLE "Przełącz"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/pt-PT.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Mascara sub rede"
#define D_SUBSCRIBE_TO "Subescrever para"
#define D_SUCCESSFUL "Successo"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "Temperatura"
#define D_TO "para"
#define D_TOGGLE "Pressionar"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/ru-RU.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "Маска Подсети"
#define D_SUBSCRIBE_TO "Подписаться на"
#define D_SUCCESSFUL "Успешно"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "Температура"
#define D_TO "до"
#define D_TOGGLE "Переключить"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/zh-CN.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "子网掩码"
#define D_SUBSCRIBE_TO "订阅"
#define D_SUCCESSFUL "成功"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "温度"
#define D_TO "to"
#define D_TOGGLE "切换"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/zh-TW.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define D_SUBNET_MASK "子網遮罩"
#define D_SUBSCRIBE_TO "訂閱"
#define D_SUCCESSFUL "成功"
#define D_SUNRISE "Sunrise"
#define D_SUNSET "Sunset"
#define D_TEMPERATURE "溫度"
#define D_TO "to"
#define D_TOGGLE "切換"
Expand Down
7 changes: 4 additions & 3 deletions sonoff/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ typedef union {
uint32_t data;
struct {
uint32_t time : 11; // bits 0 - 10 = minutes in a day
uint32_t mday : 5; // bits 11 - 15 = 32 days in a month
uint32_t mode : 5; // bits 11 - 15 = timer modes - Scheduler, Sunrise, Sunset
uint32_t days : 7; // bits 16 - 22 = week day mask
uint32_t device : 4; // bits 23 - 26 = 16 devices
uint32_t power : 2; // bits 27 - 28 = 4 power states - Off, On, Toggle, Blink
Expand Down Expand Up @@ -253,8 +253,9 @@ struct SYSCFG {
byte free_66d[3]; // 66D

Timer timer[MAX_TIMERS]; // 670

// 6B0 - FFF free locations
int latitude; // 6B0
int longitude; // 6B4
// 6B8 - FFF free locations
} Settings;

struct RTCMEM {
Expand Down
14 changes: 14 additions & 0 deletions sonoff/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
#define HOME_ASSISTANT_DISCOVERY_ENABLE 0
#endif

#ifndef LATITUDE
#define LATITUDE 48.858360 // [Latitude] Your location to be used with sunrise and sunset
#endif
#ifndef LONGITUDE
#define LONGITUDE 2.294442 // [Longitude] Your location to be used with sunrise and sunset
#endif

/*********************************************************************************************\
* RTC memory
\*********************************************************************************************/
Expand Down Expand Up @@ -597,6 +604,9 @@ void SettingsDefaultSet2()

// 5.10.1
SettingsDefaultSet_5_10_1();

Settings.latitude = (int)((double)LATITUDE * 1000000);
Settings.longitude = (int)((double)LONGITUDE * 1000000);
}

/********************************************************************************************/
Expand Down Expand Up @@ -913,6 +923,10 @@ void SettingsDelta()
if (Settings.version < 0x050C0009) {
memset(&Settings.timer, 0x00, sizeof(Timer) * MAX_TIMERS);
}
if (Settings.version < 0x050C000A) {
Settings.latitude = (int)((double)LATITUDE * 1000000);
Settings.longitude = (int)((double)LONGITUDE * 1000000);
}

Settings.version = VERSION;
SettingsSave(1);
Expand Down
13 changes: 8 additions & 5 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@
- Select IDE Tools - Flash Size: "1M (no SPIFFS)"
====================================================*/

#define VERSION 0x050C0009 // 5.12.0i
#define VERSION 0x050C000A // 5.12.0j

// Location specific includes
#include <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0)
#include "sonoff.h" // Enumeration used in user_config.h
#include "user_config.h" // Fixed user configurable options

#ifdef USE_CONFIG_OVERRIDE
#include "user_config_override.h" // Configuration overrides for user_config.h
#endif

#include "sonoff_post.h" // Configuration overrides for all previous includes
#include "i18n.h" // Language support configured by user_config.h
#include "sonoff_template.h" // Hardware configuration
#include "sonoff_post.h" // Configuration overrides for all previous includes

#ifdef ARDUINO_ESP8266_RELEASE_2_4_0
#include "lwip/init.h"
Expand Down Expand Up @@ -1036,7 +1034,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
}
}
else if (CMND_TIMEZONE == command_code) {
if ((data_len > 0) && (((payload >= -13) && (payload <= 13)) || (99 == payload))) Settings.timezone = payload;
if ((data_len > 0) && (((payload >= -13) && (payload <= 14)) || (99 == payload))) Settings.timezone = payload;
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.timezone);
}
else if (CMND_ALTITUDE == command_code) {
Expand Down Expand Up @@ -1307,8 +1305,13 @@ void PublishStatus(uint8_t payload)
}

if ((0 == payload) || (7 == payload)) {
#ifdef USE_SUNRISE
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS7_TIME "\":{\"" D_JSON_UTC_TIME "\":\"%s\",\"" D_JSON_LOCAL_TIME "\":\"%s\",\"" D_JSON_STARTDST "\":\"%s\",\"" D_JSON_ENDDST "\":\"%s\",\"" D_CMND_TIMEZONE "\":%d,\"" D_JSON_SUNRISE "\":\"%s\",\"" D_JSON_SUNSET "\":\"%s\"}}"),
GetTime(0).c_str(), GetTime(1).c_str(), GetTime(2).c_str(), GetTime(3).c_str(), Settings.timezone, GetSun(0).c_str(), GetSun(1).c_str());
#else
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS7_TIME "\":{\"" D_JSON_UTC_TIME "\":\"%s\",\"" D_JSON_LOCAL_TIME "\":\"%s\",\"" D_JSON_STARTDST "\":\"%s\",\"" D_JSON_ENDDST "\":\"%s\",\"" D_CMND_TIMEZONE "\":%d}}"),
GetTime(0).c_str(), GetTime(1).c_str(), GetTime(2).c_str(), GetTime(3).c_str(), Settings.timezone);
#endif // USE_SUNRISE
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "7"));
}

Expand Down
3 changes: 3 additions & 0 deletions sonoff/sonoff_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ void WifiWpsStatusCallback(wps_cb_status status);
#ifdef USE_TIMERS
#undef USE_TIMERS // Disable support for up to 16 timers
#endif
#ifdef USE_SUNRISE
#undef USE_SUNRISE // Disable support for Sunrise and sunset tools
#endif
#ifdef USE_PZEM004T
#undef USE_PZEM004T // Disable PZEM004T energy sensor
#endif
Expand Down
43 changes: 37 additions & 6 deletions sonoff/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,35 @@ size_t strchrspn(const char *str1, int character)
return ret;
}

double AtoD(char *str)
{
// simple ascii to double, because atof or strtod are too large
char strbuf[24];

strcpy(strbuf, str);
char *pt;
double left = atoi(strbuf);
double right = 0;
short len = 0;
pt = strtok (strbuf, ".");
if (pt) {
pt = strtok (NULL, ".");
if (pt) {
right = atoi(pt);
len = strlen(pt);
double fac = 1;
while (len) {
fac /= 10.0;
len--;
}
// pow is also very large
//double fac=pow(10,-len);
right *= fac;
}
}
return left + right;
}

char* dtostrfd(double number, unsigned char prec, char *s)
{
return dtostrf(number, 1, prec, s);
Expand Down Expand Up @@ -1077,6 +1106,7 @@ uint32_t standard_time = 0;
uint32_t ntp_time = 0;
uint32_t midnight = 1451602800;
uint32_t restart_time = 0;
int16_t time_timezone = 0; // Timezone * 10
uint8_t midnight_now = 0;
uint8_t ntp_sync_minute = 0;

Expand Down Expand Up @@ -1325,8 +1355,8 @@ boolean MidnightNow()

void RtcSecond()
{
uint32_t stdoffset;
uint32_t dstoffset;
int32_t stdoffset;
int32_t dstoffset;
TIME_T tmpTime;

if ((ntp_sync_minute > 59) && (RtcTime.minute > 2)) ntp_sync_minute = 1; // If sync prepare for a new cycle
Expand All @@ -1353,6 +1383,7 @@ void RtcSecond()
utc_time++;
local_time = utc_time;
if (local_time > 1451602800) { // 2016-01-01
int32_t time_offset = Settings.timezone * SECS_PER_HOUR;
if (99 == Settings.timezone) {
if (DaylightSavingTime.hemis) {
dstoffset = StandardTime.offset * SECS_PER_MIN; // Southern hemisphere
Expand All @@ -1362,13 +1393,13 @@ void RtcSecond()
stdoffset = StandardTime.offset * SECS_PER_MIN;
}
if ((utc_time >= (daylight_saving_time - stdoffset)) && (utc_time < (standard_time - dstoffset))) {
local_time += dstoffset; // Daylight Saving Time
time_offset = dstoffset; // Daylight Saving Time
} else {
local_time += stdoffset; // Standard Time
time_offset = stdoffset; // Standard Time
}
} else {
local_time += Settings.timezone * SECS_PER_HOUR;
}
local_time += time_offset;
time_timezone = time_offset / (SECS_PER_HOUR / 10);
}
BreakTime(local_time, RtcTime);
if (!RtcTime.hour && !RtcTime.minute && !RtcTime.second && RtcTime.valid) {
Expand Down
3 changes: 3 additions & 0 deletions sonoff/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@

#define USE_TIMERS // Add support for up to 16 timers (+2k2 code)
#define USE_TIMERS_WEB // Add timer webpage support (+4k5 code)
#define USE_SUNRISE // Add support for Sunrise and sunset tools (+16k)
#define LATITUDE 48.858360 // [Latitude] Your location to be used with sunrise and sunset
#define LONGITUDE 2.294442 // [Longitude] Your location to be used with sunrise and sunset

// -- Time - Start Daylight Saving Time and timezone offset from UTC in minutes
#define TIME_DST North, Last, Sun, Mar, 2, +120 // Northern Hemisphere, Last sunday in march at 02:00 +120 minutes
Expand Down
Loading

0 comments on commit 524979a

Please sign in to comment.