Skip to content

Commit

Permalink
Merge pull request #79 from vingerha/main
Browse files Browse the repository at this point in the history
Manually add ecowatt and fix calculations
  • Loading branch information
vingerha authored Aug 20, 2023
2 parents 589cef8 + 0904b34 commit a0f3776
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 26 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

**Cette carte est compatible avec l'integration : [MyElectricalData](https://github.com/MyElectricalData/myelectricaldata)**

A noter: avec le changement vers MyElectricalData, cette carte **n'est plus garanti d'être compatible** avec l'integration : [MyEnedis](https://github.com/saniho/apiEnedis)
Depuis Aout 2023: avec le changement vers MyElectricalData, cette carte **n'est plus garanti d'être compatible** avec l'integration : [MyEnedis](https://github.com/saniho/apiEnedis)

**Un question ? Un problème ? Une demande ? Venez en parler sur le [forum HACF](https://forum.hacf.fr/).**

Expand Down Expand Up @@ -62,7 +62,7 @@ resources:

````
type: 'custom:content-card-linky'
entity: sensor.myenedis
entity: sensor.xxx_myelctricaldata_xxxx
````
</details>

Expand All @@ -74,7 +74,10 @@ entity: sensor.myenedis
type: custom:content-card-linky Type de la carte
nbJoursAffichage: '7' Nombre de jour historique
titleName: Consommation d'hier Titre
entity: sensor.myelectricaldata_09145007157315 Sensor de l'integration MyElectricalData
entity: sensor.myelectricaldata_123456 Sensor de l'integration MyElectricalData
ewEntity: sensor.myelectricaldata_123456 Sensor de l'intégration Ecowatt J0 via (!) MyElectricalData
ewEntityJ1: sensor.myelectricaldata_123456_J1 Sensor de l'intégration Ecowatt J+1 via (!) MyElectricalData (dd. 20 Aout: en attendant release MED)
ewEntityJ2: sensor.myelectricaldata_123456_J2 Sensor de l'intégration Ecowatt J+2 (!) MyElectricalData (dd. 20 Aout: en attendant release MED)
showIcon: false Affiche l'icon Linky
showHistory: true Affiche l'historique sur plusieurs jours
showInTableUnit: false
Expand All @@ -91,6 +94,7 @@ showDayName: short Affichage des jours de la semain
showDayMaxPower: true Affichage MaxPower avec indication si dépassé
showTitreLigne: true
showEcoWatt: true Affichage EcoWatt pour ajourd'hui
showEcoWattJ12: false Affichage EcoWatt pour demains et après (dd. 20 Aout: en attendant release MED)
````

![image](https://github.com/saniho/content-card-linky/assets/44190435/bed36123-de76-4ba9-bbeb-4a3a2ddf9fe3)
Expand Down
19 changes: 14 additions & 5 deletions dist/content-card-linky-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const fireEvent = (node, type, detail, options) => {
return event;
};


if (
!customElements.get("ha-switch") &&
customElements.get("paper-toggle-button")
Expand Down Expand Up @@ -113,6 +114,9 @@ export class contentCardLinkyEditor extends LitElement {
get _showEcoWatt() {
return this._config.showEcoWatt !== false;
}
get _showEcoWattJ12() {
return this._config.showEcoWattJ12 !== false;
}

get _title() {
return this._config.showTitle !== false;
Expand Down Expand Up @@ -160,7 +164,10 @@ export class contentCardLinkyEditor extends LitElement {
.configValue="${"titleName"}"
@value-changed="${this._valueChanged}"
></paper-input>
${this.renderLinkyPicker("Entity", this._entity, "entity")}
${this.renderSensorPicker("Entity", this._entity, "entity")}
${this.renderSensorPicker("EcoWatt", this._ewEntity, "ewEntity")}
${this.renderSensorPicker("EcoWattJ1", this._ewEntityJ1, "ewEntityJ1")}
${this.renderSensorPicker("EcoWattJ2", this._ewEntityJ2, "ewEntityJ2")}
<!-- Switches -->
<ul class="switches">
${this.renderSwitchOption("Show icon", this._showIcon, "showIcon")}
Expand All @@ -181,7 +188,8 @@ export class contentCardLinkyEditor extends LitElement {
${this.renderSwitchOption("Show titre ligne", this._showTitreLigne, "showTitreLigne")}
${this.renderSwitchOption("Show error", this._showError, "showError")}
${this.renderSwitchOption("Show header", this._showHeader, "showHeader")}
${this.renderSwitchOption("Show echo Watt", this._showEcoWatt, "showEcoWatt")}
${this.renderSwitchOption("Show EcoWatt J", this._showEcoWatt, "showEcoWatt")}
${this.renderSwitchOption("Show EcoWatt J+1 et J+2", this._showEcoWattJ12, "showEcoWattJ12")}
</ul>
<!-- -->
<paper-input
Expand All @@ -203,9 +211,9 @@ export class contentCardLinkyEditor extends LitElement {
</div>
`;
}

renderLinkyPicker(label, entity, configAttr) {
return this.renderPicker(label, entity, configAttr, "sensor.myenedis");
renderSensorPicker(label, entity, configAttr) {
return this.renderPicker(label, entity, configAttr, "sensor");
}

renderPicker(label, entity, configAttr, domain) {
Expand All @@ -221,6 +229,7 @@ export class contentCardLinkyEditor extends LitElement {
></ha-entity-picker>
`
}

renderSwitchOption(label, state, configAttr) {
return html`
<li class="switch">
Expand Down
112 changes: 94 additions & 18 deletions dist/content-card-linky.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ const LitElement = Object.getPrototypeOf(
const html = LitElement.prototype.html;
const css = LitElement.prototype.css;


window.customCards = window.customCards || [];
window.customCards.push({
type: "content-card-linky",
name: "Carte Enedis par saniho",
description: "Carte pour l'intégration myEnedis.",
name: "Carte Enedis1",
description: "Carte pour l'intégration myElectricalData.",
preview: true,
documentationURL: "https://github.com/saniho/content-card-linky",
});
Expand Down Expand Up @@ -100,12 +101,12 @@ class ContentCardLinky extends LitElement {
? html `
<span class="variations-linky">
<span class="ha-icon">
<ha-icon icon="mdi:arrow-right" style="display: inline-block; transform: rotate(${(attributes.year_evolution < 0) ? '45' : ((attributes.year_evolution == 0) ? "0" : "-45")}deg)">
<ha-icon icon="mdi:arrow-right" style="display: inline-block; transform: rotate(${(attributes.yearly_evolution < 0) ? '45' : ((attributes.yearly_evolution == 0) ? "0" : "-45")}deg)">
</ha-icon>
</span>
<div class="tooltip">
${Math.round(attributes.year_evolution)}<span class="unit"> %</span><span class="year">par rapport à ${this.previousYear()}</span>
<span class="tooltiptext">A-1 : ${attributes.last_year}<br>A : ${attributes.current_year}</span>
${Math.round(attributes.yearly_evolution)}<span class="unit"> %</span><span class="year">par rapport à ${this.previousYear()}</span>
<span class="tooltiptext">A-1 : ${attributes.current_year_last_year}<br>A : ${attributes.current_year}</span>
</div>
</span>`
: html ``
Expand Down Expand Up @@ -160,8 +161,8 @@ class ContentCardLinky extends LitElement {
</ha-icon>
</span>
<div class="tooltip">
${Math.round(attributes.yesterday_evolution)}<span class="unit"> %</span><span class="previous-month">par rapport à ${this.yesterdayPreviousYear()}</span>
<span class="tooltiptext">Hier A-1 : ${attributes.yesterdayLastYear}<br>Hier : ${attributes.yesterday}</span>
${Math.round(attributes.yesterday_evolution)}<span class="unit"> %</span><span class="previous-month">par rapport à ${this.dayBeforeYesterday()}</span>
<span class="tooltiptext">Avant-hier : ${attributes.day_2}<br>Hier : ${attributes.yesterday}</span>
</div>
</span>`
: html ``
Expand All @@ -180,6 +181,7 @@ class ContentCardLinky extends LitElement {
</div>
${this.renderHistory(attributes.daily, attributes.unit_of_measurement, attributes.dailyweek, attributes.dailyweek_cost, attributes.dailyweek_costHC, attributes.dailyweek_costHP, attributes.dailyweek_HC, attributes.dailyweek_HP, attributes.dailyweek_MP, attributes.dailyweek_MP_over, attributes.dailyweek_MP_time, this.config)}
${this.renderEcoWatt(attributes, this.config)}
${this.renderEcoWattJ12(attributes, this.config)}
${this.renderError(attributes.errorLastCall, this.config)}
${this.renderVersion(attributes.versionUpdateAvailable, attributes.versionGit)}
${this.renderInformation(attributes, this.config)}
Expand Down Expand Up @@ -568,17 +570,21 @@ class ContentCardLinky extends LitElement {
let ecoWattForecastStartTime = ecoWattForecastTimeRefBegin.toLocaleTimeString([], { hour: '2-digit'});
let ecoWattForecastEndTime = ecoWattForecastTimeRefEnd.toLocaleTimeString([], { hour: '2-digit' });

return [ecoWattForecastStartTime, ecoWattForecastEndTime];
return [ecoWattForecastStartTime, ecoWattForecastEndTime, ecoWattForecast.attributes["begin"], ecoWattForecast.attributes["end"] ];
}

getOneDayNextEcoWattText(ecoWattForecastEntity) {
let beginDate = new Date(ecoWattForecastEntity.attributes["begin"]);
for (let [time, value] of Object.entries(
ecoWattForecastEntity.attributes["forecast"]
)) {
if (time != undefined && ecoWattForecastValues.get(value) > 0.1) {
let timeStr = time.replace(/([345])5/g, "$10");
return value + ((time == "0 min") ? " actuellement." : " dans " + timeStr + ".");
}
if ( time != undefined && ecoWattForecastValues.get(value) !== "green" ) {
let timeStr = time.replace(/([345])5/g, "$10");
return html `Actuellement: ${ecoWattForecastValues.get(value)}`;
} else
{
return html `Ecowatt ${ beginDate.toLocaleDateString('fr-FR', {weekday: 'long', day: 'numeric'}) }`;
}
}
return ""
}
Expand Down Expand Up @@ -608,21 +614,21 @@ class ContentCardLinky extends LitElement {
if (this.config.showEcoWatt === false ){
return html ``;
}
let sensorName = config.entity + "_ecowatt" ;
let sensorName = this.config.ewEntity;
const ecoWattForecast = this.hass.states[sensorName];

if (!ecoWattForecast || ecoWattForecast.length === 0) {
return html``;
return html ``;
}

this.numberElements++;

let [startTime, endTime] = this.getOneDayForecastTime(ecoWattForecast);
let [startTime, endTime, begin, end ] = this.getOneDayForecastTime(ecoWattForecast);

return html`
<ul class="flow-row oneHourHeader ${this.numberElements > 1 ? " spacer" : ""}">
<li> ${startTime} </li>
<li>${this.getOneDayNextEcoWattText(ecoWattForecast)}</li>
<li> ${this.getOneDayNextEcoWattText(ecoWattForecast)}</li>
<li> ${endTime} </li>
</ul>
<ul class="flow-row oneHour">
Expand All @@ -642,6 +648,76 @@ class ContentCardLinky extends LitElement {
`}
</ul>`;
}

renderEcoWattJ12(attributes, config) {
if (attributes.serviceEnedis === undefined ){
return html ``;
}
if ( attributes.serviceEnedis !== "myElectricalData" ){
return html `EcoWatt : uniquement disponible avec myElectricData`;
}
if (this.config.showEcoWattJ12 === false ){
return html ``;
}
let sensorNameJ1 = this.config.ewEntityJ1;
const ecoWattForecastJ1 = this.hass.states[sensorNameJ1];
let sensorNameJ2 = this.config.ewEntityJ2;
const ecoWattForecastJ2 = this.hass.states[sensorNameJ2];

if (!ecoWattForecastJ1 || ecoWattForecastJ1.length === 0 || !ecoWattForecastJ2 || ecoWattForecastJ2.length === 0) {
return html `EcoWatt: sensor J+1 ou J+2 indisponible ou incorrecte`;
}

this.numberElements++;

let [startTime1, endTime1, begin1, end1 ] = this.getOneDayForecastTime(ecoWattForecastJ1);
let [startTime2, endTime2, begin2, end2 ] = this.getOneDayForecastTime(ecoWattForecastJ2);

return html`
<ul class="flow-row oneHourHeader ${this.numberElements > 1 ? " spacer" : ""}">
<li> ${startTime1} </li>
<li> Ecowatt ${ (new Date(begin1)).toLocaleDateString('fr-FR', {weekday: 'long', day: 'numeric'})} </li>
<li> ${endTime2} </li>
</ul>
<ul class="flow-row oneHour">
${html`
${this.getOneDayNextEcoWatt(ecoWattForecastJ1).map(
(forecast) => html`
<li class="ecowatt-${forecast[0]}" style="background: ${forecast[1]}" title="${forecast[1]} - ${forecast[0]}" ></li>`
)}
`}
</ul>
<ul class="flow-row oneHourLabel">
${html`
${this.getOneDayNextEcoWatt(ecoWattForecastJ1).map(
(forecast) => html`
<li title="${forecast[0]}">${(forecast[0]%2==1) ? forecast[0] : ''}</li>`
)}
`}
</ul>
<ul class="flow-row oneHourHeader ${this.numberElements > 1 ? " spacer" : ""}">
<li> ${startTime2} </li>
<li> Ecowatt ${ (new Date(begin2)).toLocaleDateString('fr-FR', {weekday: 'long', day: 'numeric'})} </li>
<li> ${endTime2} </li>
</ul>
<ul class="flow-row oneHour">
${html`
${this.getOneDayNextEcoWatt(ecoWattForecastJ2).map(
(forecast) => html`
<li class="ecowatt-${forecast[0]}" style="background: ${forecast[1]}" title="${forecast[1]} - ${forecast[0]}" ></li>`
)}
`}
</ul>
<ul class="flow-row oneHourLabel">
${html`
${this.getOneDayNextEcoWatt(ecoWattForecastJ2).map(
(forecast) => html`
<li title="${forecast[0]}">${(forecast[0]%2==1) ? forecast[0] : ''}</li>`
)}
`}
</ul>`;
}

setConfig(config) {
if (!config.entity) {
Expand Down Expand Up @@ -720,8 +796,8 @@ class ContentCardLinky extends LitElement {
weekPreviousYear() {
return "semaine";
}
yesterdayPreviousYear() {
return "hier";
dayBeforeYesterday() {
return "avant-hier";
}


Expand Down

0 comments on commit a0f3776

Please sign in to comment.