Skip to content

Commit

Permalink
Merge pull request letscontrolit#5010 from tonhuisman/feature/P029-C0…
Browse files Browse the repository at this point in the history
…02-Add-invert-on-off-value-option

[P029][C002] Add option Invert On/Off value
  • Loading branch information
TD-er authored Mar 24, 2024
2 parents cd21505 + c5be15b commit cf3dcfb
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 66 deletions.
3 changes: 3 additions & 0 deletions docs/source/Plugin/P029.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Relevant Settings:
* Plugin: Output - Domoticz MQTT Helper
* 1st GPIO: 12 (the relay)
* IDX: 475
* Invert On/Off value: To ease the use of this plugin, without the need for rules, an Invert option has been added. This will cause the GPIO pin (and ``Output`` value) to be set to 1 when the Domoticz device is in Off state, and 0 for the On state.


Rules
Expand Down Expand Up @@ -184,6 +185,8 @@ Change log
.. versionchanged:: 2.0
...

|added| 2024-03: Add Invert On/Off value option.

|added|
Major overhaul for 2.0 release.

Expand Down
Binary file modified docs/source/Plugin/P029_Domoticz_Helper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 28 additions & 17 deletions src/_C002.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
// ########################### Controller Plugin 002: Domoticz MQTT ######################################
// #######################################################################################################

/** Changelog:
* 2024-03-24 tonhuisman: Add support for 'Invert On/Off value' in P029 - Domoticz MQTT Helper
* 2024-03-24 tonhuisman: Start Changelog (newest on top)
*/

# define CPLUGIN_002
# define CPLUGIN_ID_002 2
# define CPLUGIN_NAME_002 "Domoticz MQTT"
Expand Down Expand Up @@ -85,23 +90,24 @@ bool CPlugin_002(CPlugin::Function function, struct EventStruct *event, String&
constexpr pluginID_t PLUGIN_ID_DOMOTICZ_HELPER(29);
# if defined(USES_P088)
constexpr pluginID_t PLUGIN_ID_HEATPUMP_IR(88);
# endif
# endif // if defined(USES_P088)

if (Settings.TaskDeviceEnabled[x] &&
(Settings.TaskDeviceSendData[ControllerID][x]
|| (Settings.getPluginID_for_task(x) == PLUGIN_ID_DOMOTICZ_HELPER) // Domoticz helper doesn't have controller checkboxes...
|| (Settings.getPluginID_for_task(x) == PLUGIN_ID_DOMOTICZ_HELPER) // Domoticz helper doesn't have controller checkboxes...
# if defined(USES_P088)
|| (Settings.getPluginID_for_task(x) == PLUGIN_ID_HEATPUMP_IR) // Heatpump IR doesn't have controller checkboxes...
|| (Settings.getPluginID_for_task(x) == PLUGIN_ID_HEATPUMP_IR) // Heatpump IR doesn't have controller checkboxes...
# endif // if defined(USES_P088)
) &&
(Settings.TaskDeviceID[ControllerID][x] == idx)) // get idx for our controller index
(Settings.TaskDeviceID[ControllerID][x] == idx)) // get idx for our controller index
{
String action;
bool mustSendEvent = false;

switch (Settings.getPluginID_for_task(x).value) {
case 1: // temp solution, if input switch, update state
{
action = strformat(F("inputSwitchState,%u,%.2f"), x, nvalue);
action = strformat(F("gpio,%d,%d"), x, static_cast<int>(nvalue));
break;
}
case 29: // temp solution, if plugin 029, set gpio
Expand All @@ -114,7 +120,7 @@ bool CPlugin_002(CPlugin::Function function, struct EventStruct *event, String&
switch (static_cast<int>(nvalue))
{
case 0: // Off
pwmValue = 0;
pwmValue = 0;
UserVar.setFloat(x, 0, pwmValue);
break;
case 1: // On
Expand All @@ -132,20 +138,25 @@ bool CPlugin_002(CPlugin::Function function, struct EventStruct *event, String&
action = strformat(F("pwm,%d,%d"), Settings.TaskDevicePin1[x], pwmValue);
}
} else {
mustSendEvent = true;
UserVar.setFloat(x, 0, nvalue);
mustSendEvent = true;
int ivalue = static_cast<int>(nvalue);

if (1 == Settings.TaskDevicePluginConfig[x][0]) { // PCONFIG(0) = Invert On/Off value
ivalue = (1 == ivalue ? 0 : 1);
}
UserVar.setFloat(x, 0, ivalue);

if (checkValidPortRange(PLUGIN_GPIO, Settings.TaskDevicePin1[x])) {
action = strformat(F("gpio,%d,%d"), Settings.TaskDevicePin1[x], static_cast<int>(nvalue));
action = strformat(F("gpio,%d,%d"), Settings.TaskDevicePin1[x], ivalue);
}
}
break;
}
# if defined(USES_P088) // || defined(USES_P115)
case 88: // Send heatpump IR (P088) if IDX matches
# if defined(USES_P088) // || defined(USES_P115)
case 88: // Send heatpump IR (P088) if IDX matches
// case 115: // Send heatpump IR (P115) if IDX matches
{
action = concat(F("heatpumpir,"),svalue1); // svalue1 is like 'gree,1,1,0,22,0,0'
action = concat(F("heatpumpir,"), svalue1); // svalue1 is like 'gree,1,1,0,22,0,0'
break;
}
# endif // USES_P088 || USES_P115
Expand All @@ -160,11 +171,11 @@ bool CPlugin_002(CPlugin::Function function, struct EventStruct *event, String&

// Try plugin and internal
ExecuteCommandArgs args(
x,
EventValueSource::Enum::VALUE_SOURCE_MQTT,
action.c_str(),
true,
true,
x,
EventValueSource::Enum::VALUE_SOURCE_MQTT,
action.c_str(),
true,
true,
false);
ExecuteCommand(std::move(args), true);
}
Expand Down
117 changes: 68 additions & 49 deletions src/_P029_Output.ino
Original file line number Diff line number Diff line change
@@ -1,74 +1,93 @@
#include "_Plugin_Helper.h"
#ifdef USES_P029
//#######################################################################################################
//#################################### Plugin 029: Output ###############################################
//#######################################################################################################

// #######################################################################################################
// #################################### Plugin 029: Output ###############################################
// #######################################################################################################

/** Changelog:
* 2024-03-24 tonhuisman: Reformat source (Uncrustify), add option 'Invert On/Off value'
* 2024-03-24 tonhuisman: Start Changelog (newest on top)
*/

# define PLUGIN_029
# define PLUGIN_ID_029 29
# define PLUGIN_NAME_029 "Output - Domoticz MQTT Helper"
# define PLUGIN_VALUENAME1_029 "Output"

# define P029_INVERTED PCONFIG(0)

#define PLUGIN_029
#define PLUGIN_ID_029 29
#define PLUGIN_NAME_029 "Output - Domoticz MQTT Helper"
#define PLUGIN_VALUENAME1_029 "Output"
boolean Plugin_029(uint8_t function, struct EventStruct *event, String& string)
{
boolean success = false;

switch (function)
{

case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_029;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE; // FIXME TD-er: Does this need a pin? Seems not to be used
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = false;
break;
}
{
Device[++deviceCount].Number = PLUGIN_ID_029;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = false;
break;
}

case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_029);
break;
}
{
string = F(PLUGIN_NAME_029);
break;
}

case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_029));
ExtraTaskSettings.TaskDeviceValueDecimals[0] = 0;
break;
}
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_029));
ExtraTaskSettings.TaskDeviceValueDecimals[0] = 0;
break;
}

case PLUGIN_WEBFORM_LOAD:
{
// We need the index of the controller we are: 0-CONTROLLER_MAX
uint8_t controllerNr = 0;
for (controllerIndex_t i=0; i < CONTROLLER_MAX; i++)
{
// if (Settings.Protocol[i] == CPLUGIN_ID_002) { controllerNr = i; } -> error: 'CPLUGIN_ID_002' was not declared in this scope
if (Settings.Protocol[i] == 2) { controllerNr = i; }
}
{
// We need the index of the controller we are: 0-CONTROLLER_MAX
uint8_t controllerNr = 0;

addRowLabel(F("IDX"));
addNumericBox(
concat(F("TDID"), controllerNr + 1), //="taskdeviceid"
Settings.TaskDeviceID[controllerNr][event->TaskIndex],
0,
DOMOTICZ_MAX_IDX);
success = true;
break;
for (controllerIndex_t i = 0; i < CONTROLLER_MAX; i++)
{
// if (Settings.Protocol[i] == CPLUGIN_ID_002) { controllerNr = i; } -> error: 'CPLUGIN_ID_002' was not declared in
// this scope
if (Settings.Protocol[i] == 2) { controllerNr = i; }
}

addRowLabel(F("IDX"));
addNumericBox(
concat(F("TDID"), controllerNr + 1), // ="taskdeviceid"
Settings.TaskDeviceID[controllerNr][event->TaskIndex],
0,
DOMOTICZ_MAX_IDX);

addFormCheckBox(F("Invert On/Off value"), F("inverted"), P029_INVERTED == 1);

success = true;
break;
}

case PLUGIN_WEBFORM_SAVE:
{
P029_INVERTED = isFormItemChecked(F("inverted")) ? 1 : 0;
success = true;
break;
}
case PLUGIN_INIT:
{
success = true;
break;
}
{
success = true;
break;
}
}
return success;
}

#endif // USES_P029

0 comments on commit cf3dcfb

Please sign in to comment.