-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[P076] Added the ability to read reactive power, apparent power and energy #5169
base: mega
Are you sure you want to change the base?
Conversation
It seems you haven't formatted the source using Uncrustify. That's highly recommended, as it improves readability and alignment, and it also adds round braces where advisable. |
src/_P076_HLW8012.ino
Outdated
case 0: return F("Voltage_V"); | ||
case 1: return F("Current_A"); | ||
case 2: return F("Active Power_W"); | ||
case 3: return F("Reactive Power_VAR"); | ||
case 4: return F("Apparent Power_VA"); | ||
case 5: return F("Power_Factor_cosphi"); | ||
case 6: return F("Energy_Ws"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These strings are used as value names, but the rules parser doesn't handle/accept spaces in value names, so the remaining spaces should probably also be replaced by underscores.
And I'd expect the previous value names Voltage
, Current
, Power
and PowerFactor
, to be available, and preferably as the defaults (would require swapping case 3 and case 5, and also some other code adjustments), to not break existing installs and rules based on that.
Can you also add a short description of your changes to the Changelog, at the top of the file (newer entries on top of the list)? |
…actor) are now defaults again. For compatibility with old setups.
Hi, Okay forgot everything under this part. my current calibration value was wrong.
|
src/_P076_HLW8012.ino
Outdated
case 4: return F("Apparent Power_VA"); | ||
case 2: return F("Active_Power_W"); | ||
case 3: return F("Reactive_Power_VAR"); | ||
case 4: return F("Apparent_Power_VA"); | ||
case 5: return F("Power_Factor_cosphi"); | ||
case 6: return F("Energy_Ws"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See what I did for the P082_GPS in Plugin_082_valuename
There I have the display string and a task value string.
The display string is shown in the combobox when selecting the output value.
The non-display string is the shorter taskvalue name.
So maybe that's also more useful here as you would otherwise get really long strings for [taskname#taskvaluename]
which may be an issue when showing on some display as most line fields for display plugins have a limited string length.
Also it will probably mess up the layout on the "Devices" tab.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, that wouldn't look good on the overview. I have adapted the strings based on the P082 plugin.
I have found a problem with the device I am using for testing (Shelly Plus Plug S) . The BL0937 is located behind the relay. When I switch off the relay, the chip does not measure voltage, current or power. This is a problem because when PLUGIN_READ is executed all functions return a valid=false. This means that incorrect values are displayed. I would remove all the "if (valid)"-blocks and set success=true directly. This way a 0 is displayed for the values. What do you think? |
I think that returning 0 for these values when the relay is off is a bit silly, but probably a deliberate design choice to indicate you're measuring the output values, not the input values. And only Voltage would be valid anyway when the relay is off. (AFAIR, the Sonoff POWR3xxD/THR3xxD has a similar behavior) You can add a setting, and also add a default for that setting when fetching the presets, so the checks can optionally be ignored to show 0 for the values. That would make it most flexible. |
That's a good idea. I hope I can implement it next week. |
As I understand it, each option that is saved must be linked to a PCONFIG() number. There are 8 of these per plugin (0-7). Unfortunately, all 8 are already used here. 0 = output value 1 How or where could I save the information whether 0 is displayed for a non-valid measurement? |
Well, yes and no 😃 For this use-case I suggest to go the PCONFIG_ULONG route, as they have the same availability as the PCONFIG variables. |
Hi,
I added some new functions to the plugin:
I also fixed a bug that prevented the plugin from being built with PLUGIN_076_DEBUG enabled.