From 57ffb8c3bb34b0630063a30750022e4c2a07db52 Mon Sep 17 00:00:00 2001 From: philipostli <55027973+philipostli@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:59:09 +0100 Subject: [PATCH 1/3] Add setting for showing 1/3 phases - Pulse --- app.json | 13 +++++++++++++ drivers/pulse/device.ts | 15 +++++++++++++++ drivers/pulse/driver.compose.json | 13 +++++++++++++ 3 files changed, 41 insertions(+) diff --git a/app.json b/app.json index acd59bce..11b0c77a 100644 --- a/app.json +++ b/app.json @@ -1430,6 +1430,19 @@ ] } ] + }, + { + "id": "phase_mode", + "type": "checkbox", + "label": { + "en": "Show 3 phases", + "no": "Vis 3 faser" + }, + "hint": { + "en": "Enables 3 phase mode\nDefault: true\n\nWill show current on separate phases 1, 2 and 3/nTurn off to show only one phase", + "no": "Aktiverer 3-fase modus\nDefault: true\n\nViser strøm på fase 1, 2 og 3 separat/nSlå av for å vise kun én fase." + }, + "value": true } ], "id": "pulse" diff --git a/drivers/pulse/device.ts b/drivers/pulse/device.ts index 85f6df41..c71e1b73 100644 --- a/drivers/pulse/device.ts +++ b/drivers/pulse/device.ts @@ -15,6 +15,7 @@ class PulseDevice extends Device { #currency?: string; #cachedNordPoolPrice: { hour: number; price: number } | null = null; #area?: string; + #phaseMode!: boolean; #prevPowerProduction?: number; #prevUpdate?: moment.Moment; #prevPower?: number; @@ -40,6 +41,7 @@ class PulseDevice extends Device { this.#api = new TibberApi(this.log, this.homey.settings, id, token); this.#deviceId = id; this.#throttle = this.getSetting('pulse_throttle') || 30; + this.#phaseMode = this.getSetting('phase_mode') || true; this.#powerChangedTrigger = this.homey.flow.getDeviceTriggerCard('power_changed'); @@ -107,6 +109,19 @@ class PulseDevice extends Device { this.#area = newSettings.pulse_area; this.#cachedNordPoolPrice = null; } + if (changedKeys.includes('phase_mode')) { + this.log('Updated 3-phase mode value: ', Boolean(newSettings.phase_mode)); + this.#phaseMode = Boolean(newSettings.phase_mode); + if (this.#phaseMode) { + this.log('3-phase mode enabled'); + await this.addCapability('measure_current.L2'); + await this.addCapability('measure_current.L3'); + } else { + this.log('3-phase mode disabled'); + await this.removeCapability('measure_current.L2'); + await this.removeCapability('measure_current.L3'); + } + } } async #subscribeToLive() { diff --git a/drivers/pulse/driver.compose.json b/drivers/pulse/driver.compose.json index 08d6b685..24e02f07 100644 --- a/drivers/pulse/driver.compose.json +++ b/drivers/pulse/driver.compose.json @@ -232,6 +232,19 @@ ] } ] + }, + { + "id": "phase_mode", + "type": "checkbox", + "label": { + "en": "Show 3 phases", + "no": "Vis 3 faser" + }, + "hint": { + "en": "Enables 3 phase mode\nDefault: true\n\nWill show current on separate phases 1, 2 and 3/nTurn off to show only one phase", + "no": "Aktiverer 3-fase modus\nDefault: true\n\nViser strøm på fase 1, 2 og 3 separat/nSlå av for å vise kun én fase." + }, + "value": true } ] } From 64fe540a07f0031cef78aa20f2b37b5be017d68f Mon Sep 17 00:00:00 2001 From: philipostli <55027973+philipostli@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:04:12 +0100 Subject: [PATCH 2/3] Add setting for showing 1/3 phases - Watty --- app.json | 13 +++++++++++++ drivers/watty/device.ts | 15 +++++++++++++++ drivers/watty/driver.compose.json | 15 ++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app.json b/app.json index 11b0c77a..0a4b5746 100644 --- a/app.json +++ b/app.json @@ -1686,6 +1686,19 @@ ] } ] + }, + { + "id": "phase_mode", + "type": "checkbox", + "label": { + "en": "Show 3 phases", + "no": "Vis 3 faser" + }, + "hint": { + "en": "Enables 3 phase mode\nDefault: true\n\nWill show current on separate phases 1, 2 and 3/nTurn off to show only one phase", + "no": "Aktiverer 3-fase modus\nDefault: true\n\nViser strøm på fase 1, 2 og 3 separat/nSlå av for å vise kun én fase." + }, + "value": true } ], "id": "watty" diff --git a/drivers/watty/device.ts b/drivers/watty/device.ts index a1ea5def..99d749e0 100644 --- a/drivers/watty/device.ts +++ b/drivers/watty/device.ts @@ -15,6 +15,7 @@ class WattyDevice extends Device { #currency?: string; #cachedNordPoolPrice: { hour: number; price: number } | null = null; #area?: string; + #phaseMode!: boolean; #prevPowerProduction?: number; #prevUpdate?: moment.Moment; #prevPower?: number; @@ -40,6 +41,7 @@ class WattyDevice extends Device { this.#api = new TibberApi(this.log, this.homey.settings, id, token); this.#deviceId = id; this.#throttle = this.getSetting('pulse_throttle') || 30; + this.#phaseMode = this.getSetting('phase_mode') || true; this.#powerChangedTrigger = this.homey.flow.getDeviceTriggerCard( 'watty_power_changed', @@ -106,6 +108,19 @@ class WattyDevice extends Device { this.#area = newSettings.pulse_area; this.#cachedNordPoolPrice = null; } + if (changedKeys.includes('phase_mode')) { + this.log('Updated 3-phase mode value: ', Boolean(newSettings.phase_mode)); + this.#phaseMode = Boolean(newSettings.phase_mode); + if (this.#phaseMode) { + this.log('3-phase mode enabled'); + await this.addCapability('measure_current.L2'); + await this.addCapability('measure_current.L3'); + } else { + this.log('3-phase mode disabled'); + await this.removeCapability('measure_current.L2'); + await this.removeCapability('measure_current.L3'); + } + } } async #subscribeToLive() { diff --git a/drivers/watty/driver.compose.json b/drivers/watty/driver.compose.json index a1d74ea8..e41c660a 100644 --- a/drivers/watty/driver.compose.json +++ b/drivers/watty/driver.compose.json @@ -231,7 +231,20 @@ } ] } - ] + ] + }, + { + "id": "phase_mode", + "type": "checkbox", + "label": { + "en": "Show 3 phases", + "no": "Vis 3 faser" + }, + "hint": { + "en": "Enables 3 phase mode\nDefault: true\n\nWill show current on separate phases 1, 2 and 3/nTurn off to show only one phase", + "no": "Aktiverer 3-fase modus\nDefault: true\n\nViser strøm på fase 1, 2 og 3 separat/nSlå av for å vise kun én fase." + }, + "value": true } ] } From 331ef9509f4885e23bf9e3ca6262ed973e2c6e79 Mon Sep 17 00:00:00 2001 From: philipostli <55027973+philipostli@users.noreply.github.com> Date: Sat, 7 Jun 2025 14:16:46 +0200 Subject: [PATCH 3/3] Refactor phase visibility settings for Watty and Pulse drivers. Replace single phase mode checkbox with individual checkboxes for each phase (L1, L2, L3) in the configuration. Update device logic to handle visibility changes accordingly. --- app.json | 92 +++++++++++++++++++++++++------ drivers/pulse/device.ts | 33 ++++++----- drivers/pulse/driver.compose.json | 50 +++++++++++++---- drivers/watty/device.ts | 33 ++++++----- drivers/watty/driver.compose.json | 50 +++++++++++++---- 5 files changed, 192 insertions(+), 66 deletions(-) diff --git a/app.json b/app.json index 0a4b5746..c790dcf5 100644 --- a/app.json +++ b/app.json @@ -1432,17 +1432,45 @@ ] }, { - "id": "phase_mode", - "type": "checkbox", + "type": "group", "label": { - "en": "Show 3 phases", - "no": "Vis 3 faser" - }, - "hint": { - "en": "Enables 3 phase mode\nDefault: true\n\nWill show current on separate phases 1, 2 and 3/nTurn off to show only one phase", - "no": "Aktiverer 3-fase modus\nDefault: true\n\nViser strøm på fase 1, 2 og 3 separat/nSlå av for å vise kun én fase." + "en": "Show/hide phases" }, - "value": true + "children": [ + { + "id": "show_phase_current_L1", + "type": "checkbox", + "label": { + "en": "Show current phase 1" + }, + "value": true, + "hint": { + "en": "Show phase 1 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + }, + { + "id": "show_phase_current_L2", + "type": "checkbox", + "label": { + "en": "Show current phase 2" + }, + "value": true, + "hint": { + "en": "Show phase 2 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + }, + { + "id": "show_phase_current_L3", + "type": "checkbox", + "label": { + "en": "Show current phase 3" + }, + "value": true, + "hint": { + "en": "Show phase 3 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + } + ] } ], "id": "pulse" @@ -1688,17 +1716,45 @@ ] }, { - "id": "phase_mode", - "type": "checkbox", + "type": "group", "label": { - "en": "Show 3 phases", - "no": "Vis 3 faser" - }, - "hint": { - "en": "Enables 3 phase mode\nDefault: true\n\nWill show current on separate phases 1, 2 and 3/nTurn off to show only one phase", - "no": "Aktiverer 3-fase modus\nDefault: true\n\nViser strøm på fase 1, 2 og 3 separat/nSlå av for å vise kun én fase." + "en": "Show/hide phases" }, - "value": true + "children": [ + { + "id": "show_phase_current_L1", + "type": "checkbox", + "label": { + "en": "Show current phase 1" + }, + "value": true, + "hint": { + "en": "Show phase 1 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + }, + { + "id": "show_phase_current_L2", + "type": "checkbox", + "label": { + "en": "Show current phase 2" + }, + "value": true, + "hint": { + "en": "Show phase 2 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + }, + { + "id": "show_phase_current_L3", + "type": "checkbox", + "label": { + "en": "Show current phase 3" + }, + "value": true, + "hint": { + "en": "Show phase 3 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + } + ] } ], "id": "watty" diff --git a/drivers/pulse/device.ts b/drivers/pulse/device.ts index c71e1b73..aa850629 100644 --- a/drivers/pulse/device.ts +++ b/drivers/pulse/device.ts @@ -15,7 +15,6 @@ class PulseDevice extends Device { #currency?: string; #cachedNordPoolPrice: { hour: number; price: number } | null = null; #area?: string; - #phaseMode!: boolean; #prevPowerProduction?: number; #prevUpdate?: moment.Moment; #prevPower?: number; @@ -41,7 +40,6 @@ class PulseDevice extends Device { this.#api = new TibberApi(this.log, this.homey.settings, id, token); this.#deviceId = id; this.#throttle = this.getSetting('pulse_throttle') || 30; - this.#phaseMode = this.getSetting('phase_mode') || true; this.#powerChangedTrigger = this.homey.flow.getDeviceTriggerCard('power_changed'); @@ -109,17 +107,26 @@ class PulseDevice extends Device { this.#area = newSettings.pulse_area; this.#cachedNordPoolPrice = null; } - if (changedKeys.includes('phase_mode')) { - this.log('Updated 3-phase mode value: ', Boolean(newSettings.phase_mode)); - this.#phaseMode = Boolean(newSettings.phase_mode); - if (this.#phaseMode) { - this.log('3-phase mode enabled'); - await this.addCapability('measure_current.L2'); - await this.addCapability('measure_current.L3'); - } else { - this.log('3-phase mode disabled'); - await this.removeCapability('measure_current.L2'); - await this.removeCapability('measure_current.L3'); + // Handle phase current visibility settings + const phases = ['L1', 'L2', 'L3']; + for (const phase of phases) { + const settingKey = `show_phase_current_${phase}`; + if (changedKeys.includes(settingKey)) { + this.log(`Updated show phase current ${phase} value: `, Boolean(newSettings[settingKey])); + const showPhase = Boolean(newSettings[settingKey]); + + if (showPhase) { + this.log(`Adding measure_current.${phase} capability to dashboard`); + await this.setCapabilityOptions(`measure_current.${phase}`, { + uiComponent: 'sensor' + }); + } else { + this.log(`Removing measure_current.${phase} capability from dashboard`); + await this.setCapabilityOptions(`measure_current.${phase}`, { + uiComponent: 'none' + }); + } + } } } diff --git a/drivers/pulse/driver.compose.json b/drivers/pulse/driver.compose.json index 24e02f07..da127efb 100644 --- a/drivers/pulse/driver.compose.json +++ b/drivers/pulse/driver.compose.json @@ -234,17 +234,45 @@ ] }, { - "id": "phase_mode", - "type": "checkbox", - "label": { - "en": "Show 3 phases", - "no": "Vis 3 faser" - }, - "hint": { - "en": "Enables 3 phase mode\nDefault: true\n\nWill show current on separate phases 1, 2 and 3/nTurn off to show only one phase", - "no": "Aktiverer 3-fase modus\nDefault: true\n\nViser strøm på fase 1, 2 og 3 separat/nSlå av for å vise kun én fase." - }, - "value": true + "type": "group", + "label": { + "en": "Show/hide phases" + }, + "children": [ + { + "id": "show_phase_current_L1", + "type": "checkbox", + "label": { + "en": "Show current phase 1" + }, + "value": true, + "hint": { + "en": "Show phase 1 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + }, + { + "id": "show_phase_current_L2", + "type": "checkbox", + "label": { + "en": "Show current phase 2" + }, + "value": true, + "hint": { + "en": "Show phase 2 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + }, + { + "id": "show_phase_current_L3", + "type": "checkbox", + "label": { + "en": "Show current phase 3" + }, + "value": true, + "hint": { + "en": "Show phase 3 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + } + ] } ] } diff --git a/drivers/watty/device.ts b/drivers/watty/device.ts index 99d749e0..2350bb42 100644 --- a/drivers/watty/device.ts +++ b/drivers/watty/device.ts @@ -15,7 +15,6 @@ class WattyDevice extends Device { #currency?: string; #cachedNordPoolPrice: { hour: number; price: number } | null = null; #area?: string; - #phaseMode!: boolean; #prevPowerProduction?: number; #prevUpdate?: moment.Moment; #prevPower?: number; @@ -41,7 +40,6 @@ class WattyDevice extends Device { this.#api = new TibberApi(this.log, this.homey.settings, id, token); this.#deviceId = id; this.#throttle = this.getSetting('pulse_throttle') || 30; - this.#phaseMode = this.getSetting('phase_mode') || true; this.#powerChangedTrigger = this.homey.flow.getDeviceTriggerCard( 'watty_power_changed', @@ -108,17 +106,26 @@ class WattyDevice extends Device { this.#area = newSettings.pulse_area; this.#cachedNordPoolPrice = null; } - if (changedKeys.includes('phase_mode')) { - this.log('Updated 3-phase mode value: ', Boolean(newSettings.phase_mode)); - this.#phaseMode = Boolean(newSettings.phase_mode); - if (this.#phaseMode) { - this.log('3-phase mode enabled'); - await this.addCapability('measure_current.L2'); - await this.addCapability('measure_current.L3'); - } else { - this.log('3-phase mode disabled'); - await this.removeCapability('measure_current.L2'); - await this.removeCapability('measure_current.L3'); + // Handle phase current visibility settings + const phases = ['L1', 'L2', 'L3']; + for (const phase of phases) { + const settingKey = `show_phase_current_${phase}`; + if (changedKeys.includes(settingKey)) { + this.log(`Updated show phase current ${phase} value: `, Boolean(newSettings[settingKey])); + const showPhase = Boolean(newSettings[settingKey]); + + if (showPhase) { + this.log(`Adding measure_current.${phase} capability to dashboard`); + await this.setCapabilityOptions(`measure_current.${phase}`, { + uiComponent: 'sensor' + }); + } else { + this.log(`Removing measure_current.${phase} capability from dashboard`); + await this.setCapabilityOptions(`measure_current.${phase}`, { + uiComponent: 'none' + }); + } + } } } diff --git a/drivers/watty/driver.compose.json b/drivers/watty/driver.compose.json index e41c660a..f52484a9 100644 --- a/drivers/watty/driver.compose.json +++ b/drivers/watty/driver.compose.json @@ -234,17 +234,45 @@ ] }, { - "id": "phase_mode", - "type": "checkbox", - "label": { - "en": "Show 3 phases", - "no": "Vis 3 faser" - }, - "hint": { - "en": "Enables 3 phase mode\nDefault: true\n\nWill show current on separate phases 1, 2 and 3/nTurn off to show only one phase", - "no": "Aktiverer 3-fase modus\nDefault: true\n\nViser strøm på fase 1, 2 og 3 separat/nSlå av for å vise kun én fase." - }, - "value": true + "type": "group", + "label": { + "en": "Show/hide phases" + }, + "children": [ + { + "id": "show_phase_current_L1", + "type": "checkbox", + "label": { + "en": "Show current phase 1" + }, + "value": true, + "hint": { + "en": "Show phase 1 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + }, + { + "id": "show_phase_current_L2", + "type": "checkbox", + "label": { + "en": "Show current phase 2" + }, + "value": true, + "hint": { + "en": "Show phase 2 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + }, + { + "id": "show_phase_current_L3", + "type": "checkbox", + "label": { + "en": "Show current phase 3" + }, + "value": true, + "hint": { + "en": "Show phase 3 current\nDisable to hide value from dashboard\n\nRemoves relevant flow cards and tokens\nDefault: true" + } + } + ] } ] }