Skip to content

Commit

Permalink
feat: separate energy cost for buy and sell
Browse files Browse the repository at this point in the history
  • Loading branch information
slipx06 committed Aug 25, 2023
1 parent 012da62 commit e6312a7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions dist/sunsynk-power-flow-card.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ See the [WIKI](https://github.com/slipx06/sunsynk-power-flow-card/wiki/Sensor-Ma
|prog6_time:| Optional | `sensor.sunsynk_time_slot_6` | Program 6 start time (`HH:MM`)
|prog6_capacity:| Optional | `number.sunsynk_system_mode_soc_time6` | Program 6 capacity (SOC) setting
|prog6_charge:| Optional | `switch.sunsynk_system_mode_grid_charge_time6` | Program 6 charge options (`on/off`, `1/0`, `No Grid or Gen`)
|energy_cost:| Optional | | Sensor that provides current energy cost per kWh
|energy_cost_buy:| Optional | | Sensor that provides current buy energy cost per kWh
|energy_cost_sell:| Optional | | Sensor that provides current sell energy cost per kWh
|solar_sell_247:|Optional | `switch.sunsynk_toggle_solar_sell` | Displays icons to indicate if sell solar is active or not. The switch can be toggled by clicking on the icon (`on/off`, `1/0`)

The card calculates the sensors below based on supplied attributes in the config so you dont need to define them in Home Assistant. NOTE if your essential and non-essential readings are innacurate replace sensor 169 with 167. Alternatively provide the card with sensors that calculate this data i.e essential_power: and nonessential_power:
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/sunsynk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,6 @@ Full Configuration (All Options)
prog6_time: sensor.sunsynk_time_slot_6
prog6_capacity: number.sunsynk_system_mode_soc_time6
prog6_charge: switch.sunsynk_system_mode_grid_charge_time6
energy_cost: sensor.tibber_energy_cost
energy_cost_buy: sensor.tibber_energy_cost_buy
energy_cost_sell: sensor.tibber_energy_cost_sell
solar_sell_247: switch.sunsynk_toggle_solar_sell
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sunsynk-power-flow-card",
"version": "2.1.2",
"version": "2.2.0",
"description": "A customizable Home Assistant card to emulate the Sunsynk System flow that's displayed on the Inverter screen.",
"main": "sunsynk-power-flow-card.js",
"scripts": {
Expand Down
25 changes: 18 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ export class SunsynkPowerFlowCard extends LitElement {
const stateObj40 = this.hass.states[config.entities.non_essential_load1] || { state: '0' };
const stateObj41 = this.hass.states[config.entities.non_essential_load2] || { state: '0' };
const stateObj42 = this.hass.states[config.entities.essential_load1] || { state: '0' };
const stateObj43 = this.hass.states[config.entities.energy_cost] || { state: '', attributes: { unit_of_measurement: '' } };
const stateObj43 = this.hass.states[config.entities.energy_cost_buy] || { state: '', attributes: { unit_of_measurement: '' } };
const stateObj44 = this.hass.states[config.entities.solar_sell_247] || { state: 'undefined' };
const stateObj45 = this.hass.states[config.entities.essential_load2] || { state: '0' };
const stateObj46 = this.hass.states[config.entities.pv_total] || { state: '0' };
const stateObj47 = this.hass.states[config.entities.aux_connected_status] || { state: 'on' };
const stateObj48 = this.hass.states[config.entities.aux_load1] || { state: '0' };
const stateObj49 = this.hass.states[config.entities.aux_load2] || { state: '0' };
const stateObj50 = this.hass.states[config.entities.day_aux_energy] || { state: '0' };
const stateObj51 = this.hass.states[config.entities.energy_cost_sell] || { state: '', attributes: { unit_of_measurement: '' } };

//Set defaults
let { invert_aux } = config.load;
Expand Down Expand Up @@ -196,6 +197,8 @@ export class SunsynkPowerFlowCard extends LitElement {
let height = config.card_height;
let bat_full = config.battery?.full_capacity
let bat_empty = config.battery?.empty_capacity
let energy_cost = grid_power >= 0 ? parseFloat(stateObj43.state).toFixed(2) : parseFloat(stateObj51.state).toFixed(2);

//let width = config.card_width || '100%'

//totalsolar = pv1_power_186 + pv2_power_187 + pv3_power_188 + pv4_power_189
Expand Down Expand Up @@ -966,6 +969,13 @@ export class SunsynkPowerFlowCard extends LitElement {
<text id="ess_load2_value" x="${show_aux !== true ? '430' : '427'}" y="${show_aux !== true ? '42' : '154'}" display="${additional_load === 2 ? '' : 'none'}" class="st3" fill="${load_colour}">${isNaN(parseFloat(stateObj45.state)) ? '0' : parseFloat(stateObj45.state).toFixed(0)} W</text>
</a>`
: svg`<text id="ess_load2_value" x="${show_aux !== true ? '430' : '427'}" y="${show_aux !== true ? '42' : '154'}" display="${additional_load === 2 ? '' : 'none'}" class="st3" fill="${load_colour}">${isNaN(parseFloat(stateObj45.state)) ? '0' : parseFloat(stateObj45.state).toFixed(0)} W</text>`}
${grid_power >= 0
? svg`<a href="#" @click=${(e) => this.handlePopup(e, config.entities.energy_cost_buy)}>
<text id="energy_cost" x="427" y="257" class="st3 left-align" fill="${grid_colour}" display="${config.entities?.energy_cost_buy ? '' : 'none'}" >${energy_cost} ${stateObj43.attributes.unit_of_measurement}</text>
</a>`
: svg`<a href="#" @click=${(e) => this.handlePopup(e, config.entities.energy_cost_sell)}>
<text id="energy_cost" x="427" y="257" class="st3 left-align" fill="${grid_colour}" display="${config.entities?.energy_cost_sell ? '' : 'none'}" >${energy_cost} ${stateObj51.attributes.unit_of_measurement}</text>
</a>`}
<a href="#" @click=${(e) => this.handlePopup(e, config.entities.inverter_voltage_154)}>
<text id="inverter_voltage_154" x="270" y="170.4" display="${config.entities.inverter_voltage_154 === 'none' || !config.entities.inverter_voltage_154 ? 'none' : ''}" class="${font !== true ? 'st14' : 'st4'} st8" fill="${grid_colour}" >${inverter_voltage} V</text>
Expand Down Expand Up @@ -1030,9 +1040,6 @@ export class SunsynkPowerFlowCard extends LitElement {
<a href="#" @click=${(e) => this.handlePopup(e, config.entities.dc_transformer_temp_90)}>
<text id="dc_temp" x="110" y="266" class="st3 left-align" fill="${inverter_colour}" display="${config.entities?.dc_transformer_temp_90 ? '' : 'none'}" >DC: ${stateObj38.state}°</text>
</a>
<a href="#" @click=${(e) => this.handlePopup(e, config.entities.energy_cost)}>
<text id="energy_cost" x="427" y="257" class="st3 left-align" fill="${grid_colour}" display="${config.entities?.energy_cost ? '' : 'none'}" >${parseFloat(stateObj43.state).toFixed(2)} ${stateObj43.attributes.unit_of_measurement}</text>
</a>
</svg>
</div>
</ha-card>
Expand Down Expand Up @@ -1309,9 +1316,13 @@ export class SunsynkPowerFlowCard extends LitElement {
<a href="#" @click=${(e) => this.handlePopup(e, config.entities.dc_transformer_temp_90)}>
<text id="dc_temp" x="173" y="180.4" class="st3 left-align" fill="${inverter_colour}" display="${config.entities?.dc_transformer_temp_90 ? '' : 'none'}" >DC: ${stateObj38.state}°</text>
</a>
<a href="#" @click=${(e) => this.handlePopup(e, config.entities.energy_cost)}>
<text id="energy_cost" x="105" y="195" class="st3 left-align" fill="${grid_colour}" display="${config.entities?.energy_cost ? '' : 'none'}" >${parseFloat(stateObj43.state).toFixed(2)} ${stateObj43.attributes.unit_of_measurement}</text>
</a>
${grid_power >= 0
? svg`<a href="#" @click=${(e) => this.handlePopup(e, config.entities.energy_cost_buy)}>
<text id="energy_cost" x="105" y="195" class="st3 left-align" fill="${grid_colour}" display="${config.entities?.energy_cost_buy ? '' : 'none'}" >${energy_cost} ${stateObj43.attributes.unit_of_measurement}</text>
</a>`
: svg`<a href="#" @click=${(e) => this.handlePopup(e, config.entities.energy_cost_sell)}>
<text id="energy_cost" x="105" y="195" class="st3 left-align" fill="${grid_colour}" display="${config.entities?.energy_cost_sell ? '' : 'none'}" >${energy_cost} ${stateObj51.attributes.unit_of_measurement}</text>
</a>`}
${config.entities?.pv_total
? svg`<a href="#" @click=${(e) => this.handlePopup(e, config.entities.pv_total)}>
<text id="pvtotal_power" x="238.8" y="133.9" class="${font !== true ? 'st14' : 'st4'} st8" display="${config.show_solar === false ? 'none' : ''}" fill="${solar_colour}">${total_pv || 0} W</text>
Expand Down

0 comments on commit e6312a7

Please sign in to comment.