Created
August 11, 2026 14:58
-
-
Save housemaister/231ead28c208220437642cf95ab76921 to your computer and use it in GitHub Desktop.
Proposed JSCPD duplicate-code cleanup for dashboards/forecast.yaml and scripts/00_core.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/dashboards/forecast.yaml b/dashboards/forecast.yaml | |
| index e8d8a92..e0003f2 100644 | |
| --- a/dashboards/forecast.yaml | |
| +++ b/dashboards/forecast.yaml | |
| @@ -240,7 +240,7 @@ views: | |
| curve: straight | |
| color: "#9e9e9e" | |
| extend_to: false | |
| - data_generator: | | |
| + data_generator: &cumulativeForecastGenerator | | |
| const ids = [ | |
| 'input_number.energy_forecast_baseline_00_03', | |
| 'input_number.energy_forecast_baseline_03_06', | |
| @@ -256,15 +256,13 @@ views: | |
| dayStart.setHours(0, 0, 0, 0); | |
| let sum = 0; | |
| - const points = [[dayStart.getTime(), 0]]; | |
| - ids.forEach((entityId, i) => { | |
| + return ids.map((entityId, i) => { | |
| const v = Number(hass.states[entityId]?.state); | |
| const add = Number.isFinite(v) && v > 0 ? v : 0; | |
| sum += add; | |
| const ts = dayStart.getTime() + (i + 1) * 3 * 60 * 60 * 1000; | |
| - points.push([ts, sum]); | |
| + return [ts, sum]; | |
| }); | |
| - return points; | |
| - entity: sensor.ha_energy_forecast_today_00_00_03_00 | |
| name: Forecast cumulative | |
| type: line | |
| @@ -276,30 +274,7 @@ views: | |
| color: "#ff6b00" | |
| float_precision: 2 | |
| extend_to: false | |
| - data_generator: | | |
| - const ids = [ | |
| - 'sensor.ha_energy_forecast_today_00_00_03_00', | |
| - 'sensor.ha_energy_forecast_today_03_00_06_00', | |
| - 'sensor.ha_energy_forecast_today_06_00_09_00', | |
| - 'sensor.ha_energy_forecast_today_09_00_12_00', | |
| - 'sensor.ha_energy_forecast_today_12_00_15_00', | |
| - 'sensor.ha_energy_forecast_today_15_00_18_00', | |
| - 'sensor.ha_energy_forecast_today_18_00_21_00', | |
| - 'sensor.ha_energy_forecast_today_21_00_24_00', | |
| - ]; | |
| - const dayStart = new Date(); | |
| - dayStart.setHours(0, 0, 0, 0); | |
| - | |
| - let sum = 0; | |
| - const points = [[dayStart.getTime(), 0]]; | |
| - ids.forEach((entityId, i) => { | |
| - const v = Number(hass.states[entityId]?.state); | |
| - const add = Number.isFinite(v) && v > 0 ? v : 0; | |
| - sum += add; | |
| - const ts = dayStart.getTime() + (i + 1) * 3 * 60 * 60 * 1000; | |
| - points.push([ts, sum]); | |
| - }); | |
| - return points; | |
| + data_generator: *cumulativeForecastGenerator | |
| - entity: sensor.daily_consumed_energy | |
| name: Real consumed (today) | |
| type: line | |
| diff --git a/scripts/00_core.yaml b/scripts/00_core.yaml | |
| index a4074a3..7170cfa 100644 | |
| --- a/scripts/00_core.yaml | |
| +++ b/scripts/00_core.yaml | |
| @@ -234,26 +234,6 @@ evaluateheatingelementautomode: | |
| - action: script.switchoffallheatingelement | |
| metadata: {} | |
| data: {} | |
| - - conditions: | |
| - - condition: state | |
| - entity_id: binary_sensor.pv_surplus_without_charging_delay | |
| - state: 'on' | |
| - - condition: state | |
| - entity_id: binary_sensor.heating_element_temperature_comfort_blocked | |
| - state: 'off' | |
| - - condition: state | |
| - entity_id: binary_sensor.heating_element_forecast_eligible | |
| - state: 'on' | |
| - - condition: template | |
| - value_template: '{{ states(''sensor.effective_battery_level'')|float(0) > states(''input_number.heating_element_battery_cutoff_threshold'')|float(20) }}' | |
| - - condition: state | |
| - entity_id: binary_sensor.effective_importing_power_delay | |
| - state: 'off' | |
| - sequence: | |
| - - action: script.switchonheatingelement | |
| - metadata: {} | |
| - data: | |
| - surplus_power: '{{ states(''sensor.surplus_power_without_charging_and_heating_element'')|int }}' | |
| - conditions: | |
| - condition: state | |
| entity_id: binary_sensor.pv_surplus_delay | |
| @@ -270,17 +250,12 @@ evaluateheatingelementautomode: | |
| - condition: time | |
| after: 04:00:00 | |
| before: '22:00:00' | |
| - - condition: state | |
| - entity_id: binary_sensor.heating_element_temperature_comfort_blocked | |
| - state: 'off' | |
| - - condition: state | |
| - entity_id: binary_sensor.heating_element_forecast_eligible | |
| - state: 'on' | |
| - condition: template | |
| - value_template: '{{ states(''sensor.effective_battery_level'')|float(0) > states(''input_number.heating_element_battery_cutoff_threshold'')|float(20) }}' | |
| - - condition: state | |
| - entity_id: binary_sensor.effective_importing_power_delay | |
| - state: 'off' | |
| + value_template: >- | |
| + {{ is_state('binary_sensor.heating_element_temperature_comfort_blocked','off') | |
| + and is_state('binary_sensor.heating_element_forecast_eligible','on') | |
| + and states('sensor.effective_battery_level')|float(0) > states('input_number.heating_element_battery_cutoff_threshold')|float(20) | |
| + and is_state('binary_sensor.effective_importing_power_delay','off') }} | |
| sequence: | |
| - action: script.switchonheatingelement | |
| metadata: {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment