# P1 smartmeter (API)

**URL:** <https://community.homey.app/t/p1-smartmeter-api/6150>\
**Category:** Apps\
**Created:** [January 1, 2019, 12:22pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150 "2019-01-01T12:22:22Z")\
**Posts on this page:** 1\
**Showing post:** 140

<div class="post-metadata">

**Author:** ![lucasvdh](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lucasvdh/32/54915_2.png) [@lucasvdh](https://community.homey.app/u/lucasvdh)\
**Post date:** [October 30, 2023, 10:37am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/140 "2023-10-30T10:37:44Z")

</div>

Hi @Koktail,

I’ve just addressed an edge-case issue in the DSMR reader. This fix resolves a recent problem I faced with duplicated registered generated power when transitioning from single-phase to triple-phase power.

> <https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader/pull/27>
>
> \# Fix for incorrectly defaulted values
> 
> \## Summary
> This pull request addresse…s an issue related to the reporting of electricity consumption and production values for triple-phase power.
> 
> \## Context
> After installing a new power meter, I transitioned from single-phase to triple-phase power. However, the existing reader began reporting incorrect values. The issue arises from a unique edge-case scenario: most of my home is connected to the first phase, while solar panels are connected to the second phase. This results in power consumption on the first phase and power generation on the second phase.
> 
> \## Problem
> The discrepancy occurs in the calculation of \`electricity.instantaneous.power.negative.L1\` due to the defaulting behavior of \`output.power.instantaneousProducedElectricityL1\`:
> 
> \`\`\`node
> output.power.instantaneousProducedElectricityL1 || output.power.actualProduced || 0,
> \`\`\`
> 
> This defaulting behavior should only apply when \`output.power.instantaneousProducedElectricityL1\` is \`undefined\`, not when it is \`0\`.
> 
> \## Solution
> A new function \`getDefaultedValue\` has been introduced to handle the defaulting behavior. It iterates through provided arguments and returns the first non-undefined value or 0 if all provided arguments are undefined:
> 
> \`\`\`node
> function getDefaultedValue(...args) {
> for (let arg of args) {
> if (arg !== undefined) {
> return arg;
> }
> }
> return 0;
> }
> \`\`\`
> 
> \## Example
> \`\`\`node
> const output = {
> power: {
> actualProduced: 123,
> instantaneousProducedElectricityL1: 0
> }
> }
> 
> // Incorrectly outputs 123
> console.log(output.power.instantaneousProducedElectricityL1 || output.power.actualProduced || 0)
> 
> // Correctly outputs 0 
> console.log(getDefaultedValue(output.power.instantaneousProducedElectricityL1, output.power.actualProduced))
> \`\`\`
> 
> This change ensures that the defaulting behavior operates as intended, addressing the reported discrepancies.

---

_[View the full topic](https://community.homey.app/t/p1-smartmeter-api/6150)._
