Skip to content

Commit

Permalink
Merge pull request #20 from gurbyz/dev
Browse files Browse the repository at this point in the history
Release 0.0.13
  • Loading branch information
gurbyz authored Apr 14, 2019
2 parents e794655 + ac50230 commit ee89c4e
Show file tree
Hide file tree
Showing 15 changed files with 335 additions and 71 deletions.
7 changes: 3 additions & 4 deletions custom_updater.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"power-wheel-card": {
"updated_at": "2019-03-13",
"version": "0.0.12",
"changelog": "https://github.com/gurbyz/custom-cards-lovelace/blob/master/power-wheel-card/CHANGELOG.md",
"remote_location": "https://raw.githubusercontent.com/gurbyz/custom-cards-lovelace/master/power-wheel-card/power-wheel-card.js",
"visit_repo": "https://github.com/gurbyz/custom-cards-lovelace/tree/master/power-wheel-card",
"changelog": "https://github.com/gurbyz/custom-cards-lovelace/blob/master/power-wheel-card/CHANGELOG.md"
"version": "0.0.13",
"visit_repo": "https://github.com/gurbyz/custom-cards-lovelace/tree/master/power-wheel-card"
}
}
10 changes: 10 additions & 0 deletions power-wheel-card/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Changelog
====
## 0.0.13
### New features
* Split energy rates for consuming from the grid and producing to the grid.
* Use new card parameters `energy_consumption_rate` and optional `energy_production_rate`.
* **DEPRECATED.** Current card parameter `energy_price` is deprecated and its value will be used as value for `energy_consumption_rate` for a while.
Please replace `energy_price` by `energy_consumption_rate` in your setup.
### Improvements
* Hide values near arrows in more cases.
* Code improvements.

## 0.0.12
### Improvements
* Replaced ES6 *rest destructuring* language constructs to support iOS10.3 on iPad4.
Expand Down
17 changes: 11 additions & 6 deletions power-wheel-card/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Features of the custom power-wheel-card:
Input for the calculation is the energy that you consumed from the grid and the energy that you produced to the grid.
* Calculates the energy that your home is consuming: home energy.
Input for the calculation is the energy that your solar panels produced and the energy that you consumed from and produced to the grid.
* Calculates the costs/savings for all the energy values.
* Calculates the costs/savings for all the energy values. Takes into account different rates for consuming and producing energy from and to the grid.
* Displays the transition between these power, energy and money values as arrows.
E.g. if your solar power panels produce power, the arrow from solar to home turns active.
And if your solar power panels produce enough power to deliver some back to the grid, the arrow from solar to grid turns active.
Expand Down Expand Up @@ -150,9 +150,11 @@ The toggle functions to switch to the *money view* will be disabled.

But if you want the *money view*:
1. Comply to all the requirements of the *energy view* first.
2. Supply the card parameter `energy_price`.
1. Supply the card parameter `energy_consumption_rate`.
1. (Optional) If you have a different rate for producing energy back to the grid, you can also supply the card parameter `energy_production_rate`.

> The power-wheel-card has **one** price for the energy. If your energy price is depending on the (time of) day, please supply the average price for high and low tariff or choose to not use the *money view*.
> The power-wheel-card only has rates for the energy depending on whether you consume or produce it.
If your energy rate is depending on the (time of) day, please supply the average rates for high and low tariff or choose to not use the *money view*.


## Instructions
Expand Down Expand Up @@ -199,8 +201,10 @@ There are many more card parameters available, but it's advised to start with th
|solar_energy_entity|string|optional|Default the *energy view* will not be enabled.|Entity id of your solar energy sensor. E.g. `sensor.YOUR_SOLAR_ENERGY_SENSOR`. See requirements above.|
|grid_energy_consumption_entity (D)|string|optional, always together with E|Default the *energy view* will not be enabled.|Entity id of your sensor for energy that's consumed from the grid. E.g. `sensor.YOUR_GRID_ENERGY_CONSUMPTION_SENSOR`. See requirements above.|
|grid_energy_production_entity (E)|string|optional, always together with D|Default the *energy view* will not be enabled.|Entity id of your sensor for energy that's produced to the grid. E.g. `sensor.YOUR_GRID_ENERGY_PRODUCTION_SENSOR`. See requirements above.|
|energy_price|float|optional|Default the *money view* will not be enabled.|The price of your energy per unit of energy. E.g. `0.20`.|
|money_unit|string|optional|`"€"`|The unit of `energy_price`. This unit will be used for displaying all money values.|
|energy_consumption_rate|float|optional|Default the *money view* will not be enabled.|The rate of your energy consumed from the grid per unit of energy. E.g. `0.20`.|
|energy_production_rate|float|optional|The value of `energy_consumption_rate`.|The rate of your energy produced to the grid per unit of energy. E.g. `0.15`.|
|energy_price *(deprecated)*|float|optional| |Deprecated. Please use `energy_consumption_rate` and evt. the optional `energy_production_rate` as of version 0.0.13.|
|money_unit|string|optional|`"€"`|The unit of `energy_consumption_rate` and `energy_production_rate`. This unit will be used for displaying all money values.|
|solar_icon|string|optional|The icon of your own customized solar sensor(s). If not available, then `"mdi:weather-sunny"` will be used.|Icon for solar power and energy.|
|grid_icon|string|optional|The icon of your own customized grid sensor(s) if its entity parameter is set. If not available, then `"mdi:transmission-tower"` will be used.|Icon for grid power and energy.|
|home_icon|string|optional|The icon of your own customized home sensor(s) if its entity parameter is set. If not available, then `"mdi:home"` will be used.|Icon for home power and energy.|
Expand Down Expand Up @@ -265,7 +269,8 @@ A more advanced example for in the `ui-lovelace.yaml` file:
solar_energy_entity: sensor.YOUR_SOLAR_ENERGY_SENSOR
grid_energy_consumption_entity: sensor.YOUR_GRID_ENERGY_CONSUMPTION_SENSOR
grid_energy_production_entity: sensor.YOUR_GRID_ENERGY_PRODUCTION_SENSOR
energy_price: 0.20
energy_consumption_rate: 0.20
energy_production_rate: 0.15
money_unit: "$"
solar_icon: "mdi:white-balance-sunny"
grid_icon: "mdi:flash"
Expand Down
55 changes: 38 additions & 17 deletions power-wheel-card/power-wheel-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
*/

const __VERSION = "0.0.12";
const __VERSION = "0.0.13";

const LitElement = Object.getPrototypeOf(customElements.get("home-assistant-main"));
const html = LitElement.prototype.html;
Expand Down Expand Up @@ -121,7 +121,7 @@ class PowerWheelCard extends LitElement {

/* Card functions */

_generateClass(value) {
static _generateClass(value) {
return value > 0 ? 'producing' : ((value < 0) ? 'consuming' : 'inactive');
}

Expand All @@ -133,7 +133,7 @@ class PowerWheelCard extends LitElement {
const valueStr = typeof val === 'undefined' ? 'unavailable' : this._generateValueStr(val, decimals);
const stateObj = this.hass.states[entity];
const icon = configIcon ? configIcon : (stateObj && stateObj.attributes.icon ? stateObj.attributes.icon : defaultIcon);
const classValue = this._generateClass(val);
const classValue = PowerWheelCard._generateClass(val);

return {
stateObj,
Expand Down Expand Up @@ -224,7 +224,7 @@ class PowerWheelCard extends LitElement {
}
}

_logConsole(message) {
static _logConsole(message) {
// if (this.config.debug) {
console.info(`%cpower-wheel-card%c\n${message}`, "color: green; font-weight: bold", "");
// }
Expand Down Expand Up @@ -313,14 +313,14 @@ class PowerWheelCard extends LitElement {
}
}

firstUpdated() {
firstUpdated(changedProperties) {
if (this.config.debug) {
let line = `Version: ${__VERSION}\nLovelace resource: ${this._lovelaceResource()}\nHA version: ${this.hass.config.version}`;
line += `\nAgent: ${navigator.userAgent}`;
line += `\nReport issues here: https://github.com/gurbyz/custom-cards-lovelace/issues`;
line += `\nProcessed config: ${JSON.stringify(this.config, '', ' ')}\nRegistered sensors: ${JSON.stringify(this.sensors, '', ' ')}`;
line += `\nViews object: ${JSON.stringify(this.views, '', ' ')}`;
this._logConsole(line);
line += `\nProcessed config: ${JSON.stringify(this.config, null, ' ')}\nRegistered sensors: ${JSON.stringify(this.sensors, null, ' ')}`;
line += `\nViews object: ${JSON.stringify(this.views, null, ' ')}`;
PowerWheelCard._logConsole(line);
this._addMessage('warn', `[${__VERSION}] Debug mode is on.`);
}
this._validateSensors();
Expand All @@ -330,6 +330,9 @@ class PowerWheelCard extends LitElement {
this.config.grid_energy_consumption_entity, this.config.grid_energy_production_entity);
this.views.money.unit = this.config.money_unit;
this.views = Object.assign({}, this.views);
// if (this.config.energy_price) {
// this._addMessage('warn', 'Deprecated card parameter \'energy_price\' is used.');
// }
}

_sensorChangeDetected(oldValue) {
Expand All @@ -354,12 +357,22 @@ class PowerWheelCard extends LitElement {

render() {
if (this.view === 'money' && this.views.money.capable) {
this.data.solar.val = this.config.energy_price * this._calculateSolarValue(this.config.solar_energy_entity);
this.data.grid2home.val = this.config.energy_price * this._calculateGrid2HomeValue(this.config.grid_energy_consumption_entity, this.config.grid_energy_entity);
this.data.solar2grid.val = this.config.energy_price * this._calculateSolar2GridValue(this.config.grid_energy_production_entity, this.config.grid_energy_entity);
// Calculate energy values first
this.data.solar.val = this._calculateSolarValue(this.config.solar_energy_entity);
this.data.grid2home.val = this._calculateGrid2HomeValue(this.config.grid_energy_consumption_entity, this.config.grid_energy_entity);
this.data.solar2grid.val = this._calculateSolar2GridValue(this.config.grid_energy_production_entity, this.config.grid_energy_entity);
this.data.grid.val = this._calculateGridValue(this.config.grid_energy_entity);
this.data.home.val = this._calculateHomeValue(this.config.home_energy_entity);
this.data.solar2home.val = this._calculateSolar2HomeValue();

// Convert energy values into money values
this.data.solar2grid.val *= this.config.energy_production_rate;
this.data.grid2home.val *= this.config.energy_consumption_rate;
this.data.solar2home.val *= this.config.energy_consumption_rate;
this.data.solar.val = this.data.solar2grid.val + this.data.solar2home.val;
this.data.grid.val = this.data.solar2grid.val - this.data.grid2home.val;
this.data.home.val = - this.data.grid2home.val - this.data.solar2home.val;

this.data.solar = this._makePositionObject(this.data.solar.val, this.config.solar_energy_entity, this.config.solar_icon,
'mdi:weather-sunny', this.config.money_decimals);
this.data.grid = this._makePositionObject(this.data.grid.val, this.config.grid_energy_entity, this.config.grid_icon,
Expand All @@ -376,6 +389,7 @@ class PowerWheelCard extends LitElement {
this.data.grid.val = this._calculateGridValue(this.config.grid_energy_entity);
this.data.home.val = this._calculateHomeValue(this.config.home_energy_entity);
this.data.solar2home.val = this._calculateSolar2HomeValue();

this.data.solar = this._makePositionObject(this.data.solar.val, this.config.solar_energy_entity, this.config.solar_icon,
'mdi:weather-sunny', this.config.energy_decimals);
this.data.grid = this._makePositionObject(this.data.grid.val, this.config.grid_energy_entity, this.config.grid_icon,
Expand All @@ -392,6 +406,7 @@ class PowerWheelCard extends LitElement {
this.data.grid.val = this._calculateGridValue(this.config.grid_power_entity);
this.data.home.val = this._calculateHomeValue();
this.data.solar2home.val = this._calculateSolar2HomeValue();

this.data.solar = this._makePositionObject(this.data.solar.val, this.config.solar_power_entity, this.config.solar_icon,
'mdi:weather-sunny', this.config.power_decimals);
this.data.grid = this._makePositionObject(this.data.grid.val, this.config.grid_power_entity, this.config.grid_icon,
Expand Down Expand Up @@ -434,12 +449,12 @@ class PowerWheelCard extends LitElement {
${this._cell('solar', this.data.solar, 'position')}
</div>
<div class="row">
${this._cell('solar2grid', this.data.solar2grid, 'arrow', this.data.solar.val)}
${this._cell('solar2home', this.data.solar2home, 'arrow', this.data.solar.val)}
${this._cell('solar2grid', this.data.solar2grid, 'arrow', this.data.solar.val, this.data.grid.val)}
${this._cell('solar2home', this.data.solar2home, 'arrow', this.data.solar.val, this.data.home.val)}
</div>
<div class="row">
${this._cell('grid', this.data.grid, 'position')}
${this._cell('grid2home', this.data.grid2home, 'arrow', this.data.grid.val)}
${this._cell('grid2home', this.data.grid2home, 'arrow', this.data.grid.val, this.data.home.val)}
${this._cell('home', this.data.home, 'position')}
</div>
</div>
Expand All @@ -449,14 +464,14 @@ class PowerWheelCard extends LitElement {

/* Template functions */

_cell(id, cellObj, cellType, hideValue) {
_cell(id, cellObj, cellType, hideValue1, hideValue2) {
return html`
<div id="cell-${id}"
class="cell ${cellType} ${cellObj.hasSensor ? 'sensor' : ''}"
@click="${cellObj.hasSensor ? () => this._handleClick(cellObj.stateObj) : () => {}}"
title="${cellObj.hasSensor ? `More info${cellObj.stateObj.attributes.friendly_name ? ':\n' + cellObj.stateObj.attributes.friendly_name : ''}` : ''}">
<ha-icon id="icon-${id}" class="${cellObj.classValue}" icon="${cellObj.icon}"></ha-icon>
<div id="value-${id}" class="value">${cellType === 'arrow' && (cellObj.val === 0 || cellObj.val === Math.abs(hideValue)) ? '' : cellObj.valueStr}</div>
<div id="value-${id}" class="value">${cellType === 'arrow' && (cellObj.val === 0 || Math.abs(cellObj.val) === Math.abs(hideValue1) || Math.abs(cellObj.val) === Math.abs(hideValue2)) ? '' : cellObj.valueStr}</div>
</div>
`;
}
Expand Down Expand Up @@ -575,6 +590,12 @@ class PowerWheelCard extends LitElement {
}
config.auto_toggle_view_period = config.auto_toggle_view_period ? config.auto_toggle_view_period : 10;
config.debug = config.debug ? config.debug : false;
if (config.energy_price && config.energy_consumption_rate === undefined) {
config.energy_consumption_rate = config.energy_price;
}
if (config.energy_production_rate === undefined && config.energy_consumption_rate) {
config.energy_production_rate = config.energy_consumption_rate;
}

this.views.power = {
title: config.title_power,
Expand All @@ -592,7 +613,7 @@ class PowerWheelCard extends LitElement {
title: config.title_money,
oneGridSensor: this.views.energy.oneGridSensor,
twoGridSensors: this.views.energy.twoGridSensors,
capable: this.views.energy.capable && !!config.energy_price,
capable: this.views.energy.capable && !!config.energy_consumption_rate,
};
this.autoToggleView = config.initial_auto_toggle_view;
this.sensors = this._getSensors(config);
Expand Down
2 changes: 1 addition & 1 deletion power-wheel-card/test/auto_toggle.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
solar_energy_entity: "sensor.solar_energy",
grid_energy_consumption_entity: "sensor.grid_energy_consumption",
grid_energy_production_entity: "sensor.grid_energy_production",
energy_price: 1.00,
energy_consumption_rate: 1.00,
initial_auto_toggle_view: true,
auto_toggle_view_period: 1,
};
Expand Down
6 changes: 3 additions & 3 deletions power-wheel-card/test/basic_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@
assert.equal(card.shadowRoot.querySelector('#value-solar').innerText, '500', 'Solar should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-grid').innerText, '50', 'Grid should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-home').innerText, '-450', 'Home should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-solar2grid').innerText, '50', 'Solar2Grid arrow should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-solar2home').innerText, '450', 'Solar2Home arrow should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-solar2grid').innerText, '', 'Solar2Grid arrow should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-solar2home').innerText, '', 'Solar2Home arrow should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-grid2home').innerText, '', 'Grid2Home arrow shouldn\'t have a value');
done();
});
Expand Down Expand Up @@ -259,7 +259,7 @@
assert.equal(card.shadowRoot.querySelector('#value-grid').innerText, '-5', 'Grid should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-home').innerText, '0', 'Home should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-solar2grid').innerText, '', 'Solar2Grid arrow shouldn\'t have a value');
assert.equal(card.shadowRoot.querySelector('#value-solar2home').innerText, '5', 'Solar2Home arrow should have a value');
assert.equal(card.shadowRoot.querySelector('#value-solar2home').innerText, '', 'Solar2Home arrow should have a value');
assert.equal(card.shadowRoot.querySelector('#value-grid2home').innerText, '', 'Grid2Home arrow shouldn\'t have a value');
done();
});
Expand Down
6 changes: 3 additions & 3 deletions power-wheel-card/test/basic_one_grid_sensor.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@
assert.equal(card.shadowRoot.querySelector('#value-solar').innerText, '500', 'Solar should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-grid').innerText, '50', 'Grid should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-home').innerText, '-450', 'Home should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-solar2grid').innerText, '50', 'Solar2Grid arrow should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-solar2home').innerText, '450', 'Solar2Home arrow should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-solar2grid').innerText, '', 'Solar2Grid arrow should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-solar2home').innerText, '', 'Solar2Home arrow should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-grid2home').innerText, '', 'Grid2Home arrow shouldn\'t have a value');
done();
});
Expand Down Expand Up @@ -204,7 +204,7 @@
assert.equal(card.shadowRoot.querySelector('#value-grid').innerText, '-5', 'Grid should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-home').innerText, '0', 'Home should have correct value');
assert.equal(card.shadowRoot.querySelector('#value-solar2grid').innerText, '', 'Solar2Grid arrow shouldn\'t have a value');
assert.equal(card.shadowRoot.querySelector('#value-solar2home').innerText, '5', 'Solar2Home arrow should have a value');
assert.equal(card.shadowRoot.querySelector('#value-solar2home').innerText, '', 'Solar2Home arrow should have a value');
assert.equal(card.shadowRoot.querySelector('#value-grid2home').innerText, '', 'Grid2Home arrow shouldn\'t have a value');
done();
});
Expand Down
Loading

0 comments on commit ee89c4e

Please sign in to comment.