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

Add Energy Information for KNX #2750

Merged
merged 3 commits into from
May 17, 2018
Merged
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
14 changes: 13 additions & 1 deletion sonoff/sonoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
\*********************************************************************************************/
Expand Down Expand Up @@ -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_
#endif // _SONOFF_H_
13 changes: 12 additions & 1 deletion sonoff/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1176,4 +1187,4 @@ boolean Xsns03(byte function)
return result;
}

#endif // USE_ENERGY_SENSOR
#endif // USE_ENERGY_SENSOR
42 changes: 38 additions & 4 deletions sonoff/xdrv_11_knx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
};

Expand All @@ -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
};

Expand All @@ -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
};

Expand Down Expand Up @@ -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;
Expand Down