From 92d4001c0c000a104c461f0c008aef1256c3d5a6 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Thu, 17 May 2018 01:42:51 -0300 Subject: [PATCH 1/3] Add Energy Information for KNX Add Energy Information for KNX --- sonoff/sonoff.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index a2eecea4fc8a..47fec4645bcb 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -131,6 +131,18 @@ typedef unsigned long power_t; // Power (Relay) type #define DAWN_NAUTIC -12.0 #define DAWN_ASTRONOMIC -18.0 +// Sensor definition for KNX Driver +#define KNX_TEMPERATURE 17 +#define KNX_HUMIDITY 18 +#define KNX_ENERGY_VOLTAGE 19 +#define KNX_ENERGY_CURRENT 20 +#define KNX_ENERGY_POWER 21 +#define KNX_ENERGY_POWERFACTOR 22 +#define KNX_ENERGY_DAILY 23 +#define KNX_ENERGY_START 24 +#define KNX_ENERGY_TOTAL 25 +#define KNX_MAX_device_param 25 + /*********************************************************************************************\ * Enumeration \*********************************************************************************************/ @@ -180,4 +192,4 @@ const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, extern uint8_t light_device; // Light device number -#endif // _SONOFF_H_ \ No newline at end of file +#endif // _SONOFF_H_ From 187b7ac3756e9123a8fa5d733384b0a38c1cceb7 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Thu, 17 May 2018 01:44:46 -0300 Subject: [PATCH 2/3] Add Energy Information for KNX Add Energy Information for KNX --- sonoff/xdrv_03_energy.ino | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index c41af56a4517..8eca675f3f0e 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -1113,6 +1113,17 @@ void EnergyShow(boolean json) DomoticzSensor(DZ_CURRENT, energy_current_chr); // Current } #endif // USE_DOMOTICZ +#ifdef USE_KNX + if (show_energy_period) { + KnxSensor(KNX_ENERGY_VOLTAGE, energy_voltage); + KnxSensor(KNX_ENERGY_CURRENT, energy_current); + KnxSensor(KNX_ENERGY_POWER, energy_power); + KnxSensor(KNX_ENERGY_POWERFACTOR, energy_power_factor); + KnxSensor(KNX_ENERGY_DAILY, energy_daily); + KnxSensor(KNX_ENERGY_TOTAL, energy_total); + KnxSensor(KNX_ENERGY_START, energy_start); + } +#endif // USE_KNX #ifdef USE_WEBSERVER } else { snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_ENERGY_SNS, mqtt_data, energy_voltage_chr, energy_current_chr, energy_power_chr, energy_power_factor_chr, energy_daily_chr, energy_yesterday_chr, energy_total_chr); @@ -1176,4 +1187,4 @@ boolean Xsns03(byte function) return result; } -#endif // USE_ENERGY_SENSOR \ No newline at end of file +#endif // USE_ENERGY_SENSOR From b381408312b349a294a44a365ee5b6360068e20d Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Thu, 17 May 2018 01:46:10 -0300 Subject: [PATCH 3/3] Add Energy Information for KNX Add Energy Information for KNX --- sonoff/xdrv_11_knx.ino | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino index b5eef6989d13..4379efad42d0 100644 --- a/sonoff/xdrv_11_knx.ino +++ b/sonoff/xdrv_11_knx.ino @@ -57,10 +57,8 @@ address_t KNX_physs_addr; // Physical KNX address of this device address_t KNX_addr; // KNX Address converter variable #define KNX_Empty 255 -#define KNX_TEMPERATURE 17 -#define KNX_HUMIDITY 18 -#define KNX_MAX_device_param 18 -#define TOGGLE_INHIBIT_TIME 10 // 10*50mseg = 500mseg + +#define TOGGLE_INHIBIT_TIME 10 // 10*50mseg = 500mseg (inhibit time for not toggling again relays) float last_temp; float last_hum; @@ -105,6 +103,13 @@ device_parameters_t device_param[] = { { 16, false, false, KNX_Empty }, // device_param[15] = Button 8 { KNX_TEMPERATURE, false, false, KNX_Empty }, // device_param[16] = Temperature { KNX_HUMIDITY , false, false, KNX_Empty }, // device_param[17] = humidity + { KNX_ENERGY_VOLTAGE , false, false, KNX_Empty }, + { KNX_ENERGY_CURRENT , false, false, KNX_Empty }, + { KNX_ENERGY_POWER , false, false, KNX_Empty }, + { KNX_ENERGY_POWERFACTOR , false, false, KNX_Empty }, + { KNX_ENERGY_DAILY , false, false, KNX_Empty }, + { KNX_ENERGY_START , false, false, KNX_Empty }, + { KNX_ENERGY_TOTAL , false, false, KNX_Empty }, { KNX_Empty, false, false, KNX_Empty} }; @@ -128,6 +133,13 @@ const char * device_param_ga[] = { D_SENSOR_BUTTON " 8", // Button 8 D_TEMPERATURE , // Temperature D_HUMIDITY , // Humidity + D_VOLTAGE , + D_CURRENT , + D_POWERUSAGE , + D_POWER_FACTOR , + D_ENERGY_TODAY , + D_ENERGY_YESTERDAY , + D_ENERGY_TOTAL , nullptr }; @@ -151,6 +163,13 @@ const char *device_param_cb[] = { D_TIMER_OUTPUT " 8 " D_BUTTON_TOGGLE, D_REPLY " " D_TEMPERATURE, // Reply Temperature D_REPLY " " D_HUMIDITY, // Reply Humidity + D_REPLY " " D_VOLTAGE , + D_REPLY " " D_CURRENT , + D_REPLY " " D_POWERUSAGE , + D_REPLY " " D_POWER_FACTOR , + D_REPLY " " D_ENERGY_TODAY , + D_REPLY " " D_ENERGY_YESTERDAY , + D_REPLY " " D_ENERGY_TOTAL , nullptr }; @@ -413,6 +432,21 @@ void KNX_INIT() if (GetUsedInModule(GPIO_DHT22, my_module.gp.io)) { device_param[KNX_HUMIDITY-1].show = true; } if (GetUsedInModule(GPIO_SI7021, my_module.gp.io)) { device_param[KNX_HUMIDITY-1].show = true; } + // Sonoff 31 or Sonoff Pow or any HLW8012 based device or Sonoff POW R2 or Any device with a Pzem004T + if ( ( SONOFF_S31 == Settings.module ) || + ( (GetUsedInModule(GPIO_HLW_SEL, my_module.gp.io)) && (GetUsedInModule(GPIO_HLW_CF1, my_module.gp.io)) && (GetUsedInModule(GPIO_HLW_CF, my_module.gp.io)) ) || + ( SONOFF_POW_R2 == Settings.module ) || + ( (GetUsedInModule(GPIO_PZEM_RX, my_module.gp.io)) && (GetUsedInModule(GPIO_PZEM_TX, my_module.gp.io)) ) ) + { + device_param[KNX_ENERGY_POWER-1].show = true; + device_param[KNX_ENERGY_DAILY-1].show = true; + device_param[KNX_ENERGY_START-1].show = true; + device_param[KNX_ENERGY_TOTAL-1].show = true; + device_param[KNX_ENERGY_VOLTAGE-1].show = true; + device_param[KNX_ENERGY_CURRENT-1].show = true; + device_param[KNX_ENERGY_POWERFACTOR-1].show = true; + } + // Delete from KNX settings all configuration is not anymore related to this device if (KNX_CONFIG_NOT_MATCH()) { Settings.knx_GA_registered = 0;