Hi everyone !
So, as I promised you, I give you the code for my linky card. It’s really ugly and not adaptative, I did it with my own configuration.
I used the custom Linky sensor from PrionFr instead of the laggy one included in the home assistant official release (https://github.com/Pirionfr/Home-AssistantConfig/blob/master/custom_components/sensor/linky.py).
In configuration.yaml file, just paste your credentials and the list of monitored variables given here.
sensor:
- platform: linky
username: !secret linky_username
password: !secret linky_password
monitored_variables:
- halfhourly_00_00_consumption
- halfhourly_00_30_consumption
- halfhourly_01_00_consumption
- halfhourly_01_30_consumption
- halfhourly_02_00_consumption
- halfhourly_02_30_consumption
- halfhourly_03_00_consumption
- halfhourly_03_30_consumption
- halfhourly_04_00_consumption
- halfhourly_04_30_consumption
- halfhourly_05_00_consumption
- halfhourly_05_30_consumption
- halfhourly_06_00_consumption
- halfhourly_06_30_consumption
- halfhourly_07_00_consumption
- halfhourly_07_30_consumption
- halfhourly_08_00_consumption
- halfhourly_08_30_consumption
- halfhourly_09_00_consumption
- halfhourly_09_30_consumption
- halfhourly_10_00_consumption
- halfhourly_10_30_consumption
- halfhourly_11_00_consumption
- halfhourly_11_30_consumption
- halfhourly_12_00_consumption
- halfhourly_12_30_consumption
- halfhourly_13_00_consumption
- halfhourly_13_30_consumption
- halfhourly_14_00_consumption
- halfhourly_14_30_consumption
- halfhourly_15_00_consumption
- halfhourly_15_30_consumption
- halfhourly_16_00_consumption
- halfhourly_16_30_consumption
- halfhourly_17_00_consumption
- halfhourly_17_30_consumption
- halfhourly_18_00_consumption
- halfhourly_18_30_consumption
- halfhourly_19_00_consumption
- halfhourly_19_30_consumption
- halfhourly_20_00_consumption
- halfhourly_20_30_consumption
- halfhourly_21_00_consumption
- halfhourly_21_30_consumption
- halfhourly_22_00_consumption
- halfhourly_22_30_consumption
- halfhourly_23_00_consumption
- halfhourly_23_30_consumption
- daily_1d_consumption
- daily_2d_consumption
- daily_3d_consumption
- daily_4d_consumption
- daily_5d_consumption
- daily_6d_consumption
- daily_7d_consumption
- daily_8d_consumption
- daily_9d_consumption
- daily_10d_consumption
- daily_11d_consumption
- daily_12d_consumption
- daily_13d_consumption
- daily_14d_consumption
- daily_15d_consumption
- daily_16d_consumption
- daily_17d_consumption
- daily_18d_consumption
- daily_19d_consumption
- daily_20d_consumption
- daily_21d_consumption
- daily_22d_consumption
- daily_23d_consumption
- daily_24d_consumption
- daily_25d_consumption
- daily_26d_consumption
- daily_27d_consumption
- daily_28d_consumption
- daily_29d_consumption
- monthly_1m_consumption
Then, if you restart HA, you’ll get all these raw sensors in your list of entities.
Then, I created new template sensors based on my custom parameters (heures pleines, heures creuses, cost for each period, etc …).
The formulas are the following ones, you just have to adapt them to fit your needs (be careful : for “conso_hp” and “conso_hc”, you’ll need to divide the sum by 2, because the data is given in kWh every 1/2h, so you need to divide by 2 in order to get your real consumption) :
- platform: template
sensors:
conso_hp:
friendly_name: "Consommation de la veille en heures pleines"
unit_of_measurement: 'kWh'
value_template: "{{(float(states.sensor.linky_halfhourly_00_00_consumption.state)+float(states.sensor.linky_halfhourly_01_00_consumption.state)+float(states.sensor.linky_halfhourly_07_00_consumption.state)+float(states.sensor.linky_halfhourly_08_00_consumption.state)+float(states.sensor.linky_halfhourly_09_00_consumption.state)+float(states.sensor.linky_halfhourly_10_00_consumption.state)+float(states.sensor.linky_halfhourly_11_00_consumption.state)+float(states.sensor.linky_halfhourly_12_00_consumption.state)+float(states.sensor.linky_halfhourly_13_00_consumption.state)+float(states.sensor.linky_halfhourly_17_00_consumption.state)+float(states.sensor.linky_halfhourly_18_00_consumption.state)+float(states.sensor.linky_halfhourly_19_00_consumption.state)+float(states.sensor.linky_halfhourly_20_00_consumption.state)+float(states.sensor.linky_halfhourly_21_00_consumption.state)+float(states.sensor.linky_halfhourly_22_00_consumption.state)+float(states.sensor.linky_halfhourly_23_00_consumption.state)+float(states.sensor.linky_halfhourly_00_30_consumption.state)+float(states.sensor.linky_halfhourly_01_30_consumption.state)+float(states.sensor.linky_halfhourly_07_30_consumption.state)+float(states.sensor.linky_halfhourly_08_30_consumption.state)+float(states.sensor.linky_halfhourly_09_30_consumption.state)+float(states.sensor.linky_halfhourly_10_30_consumption.state)+float(states.sensor.linky_halfhourly_11_30_consumption.state)+float(states.sensor.linky_halfhourly_12_30_consumption.state)+float(states.sensor.linky_halfhourly_13_30_consumption.state)+float(states.sensor.linky_halfhourly_17_30_consumption.state)+float(states.sensor.linky_halfhourly_18_30_consumption.state)+float(states.sensor.linky_halfhourly_19_30_consumption.state)+float(states.sensor.linky_halfhourly_20_30_consumption.state)+float(states.sensor.linky_halfhourly_21_30_consumption.state)+float(states.sensor.linky_halfhourly_22_30_consumption.state)+float(states.sensor.linky_halfhourly_23_30_consumption.state)) / 2}}"
conso_hc:
friendly_name: "Consommation de la veille en heures creuses"
unit_of_measurement: 'kWh'
value_template: '{{(float(states.sensor.linky_halfhourly_02_00_consumption.state)+float(states.sensor.linky_halfhourly_04_00_consumption.state)+float(states.sensor.linky_halfhourly_05_00_consumption.state)+float(states.sensor.linky_halfhourly_06_00_consumption.state)+float(states.sensor.linky_halfhourly_14_00_consumption.state)+float(states.sensor.linky_halfhourly_15_00_consumption.state)+float(states.sensor.linky_halfhourly_16_00_consumption.state)+float(states.sensor.linky_halfhourly_02_30_consumption.state)+float(states.sensor.linky_halfhourly_04_30_consumption.state)+float(states.sensor.linky_halfhourly_05_30_consumption.state)+float(states.sensor.linky_halfhourly_06_30_consumption.state)+float(states.sensor.linky_halfhourly_14_30_consumption.state)+float(states.sensor.linky_halfhourly_15_30_consumption.state)+float(states.sensor.linky_halfhourly_16_30_consumption.state))/2}}'
conso_mensuelle_glissante:
friendly_name: "Consommation sur 1 mois glissant"
unit_of_measurement: "kWh"
value_template: "{{(float(states.sensor.linky_daily_1d_consumption.state) + float(states.sensor.linky_daily_2d_consumption.state) + float(states.sensor.linky_daily_3d_consumption.state) + float(states.sensor.linky_daily_4d_consumption.state) + float(states.sensor.linky_daily_5d_consumption.state) + float(states.sensor.linky_daily_6d_consumption.state) + float(states.sensor.linky_daily_7d_consumption.state) + float(states.sensor.linky_daily_8d_consumption.state) + float(states.sensor.linky_daily_9d_consumption.state) + float(states.sensor.linky_daily_10d_consumption.state) + float(states.sensor.linky_daily_11d_consumption.state) + float(states.sensor.linky_daily_12d_consumption.state) + float(states.sensor.linky_daily_13d_consumption.state) + float(states.sensor.linky_daily_14d_consumption.state) + float(states.sensor.linky_daily_15d_consumption.state) + float(states.sensor.linky_daily_16d_consumption.state) + float(states.sensor.linky_daily_17d_consumption.state) + float(states.sensor.linky_daily_18d_consumption.state) + float(states.sensor.linky_daily_19d_consumption.state) + float(states.sensor.linky_daily_20d_consumption.state) + float(states.sensor.linky_daily_21d_consumption.state) + float(states.sensor.linky_daily_22d_consumption.state) + float(states.sensor.linky_daily_23d_consumption.state) + float(states.sensor.linky_daily_24d_consumption.state) + float(states.sensor.linky_daily_25d_consumption.state) + float(states.sensor.linky_daily_26d_consumption.state) + float(states.sensor.linky_daily_27d_consumption.state) + float(states.sensor.linky_daily_28d_consumption.state) + float(states.sensor.linky_daily_29d_consumption.state))}}"
cout:
friendly_name: "Coût de la veille"
unit_of_measurement: '€'
value_template: "{{((float(states.sensor.conso_hc.state) * float(0.1244)) + (float(states.sensor.conso_hp.state) * float(0.1593)))}}"
rapport_hc_hp:
friendly_name: "Taux de consommation en heures creuses"
unit_of_measurement: '%'
value_template: "{%- set conso_totale = float(states.sensor.conso_hc.state) + float(states.sensor.conso_hp.state) -%}{% if conso_totale > 0 %}{{(float(states.sensor.conso_hc.state) / conso_totale * 100)}}{% else %}N/A{% endif %}"
evolution_conso_mensuelle:
friendly_name: "Évolution de la consommation mensuelle"
unit_of_measurement: '%'
value_template: "{{((float(states.sensor.conso_mensuelle_glissante.state) - float(states.sensor.linky_monthly_1m_consumption.state)) / float(states.sensor.linky_monthly_1m_consumption.state) * 100)}}"
When you have all your templates sensors (restart again if you want to control there is no error), just add the linky card (.JS and .CSS files are needed).
https://pastebin.com/uqVp3Bwq
https://pastebin.com/FjhG8xMe
To import it, just add these lines to the top of your ui-lovelace.yaml :
resources:
- url: /local/custom_ui/linky-card.js?v=1
type: js
And to add your card, just type these lines :
- type: custom:linky-card
cons_2d: sensor.linky_daily_2d_consumption
cons_3d: sensor.linky_daily_3d_consumption
cons_4d: sensor.linky_daily_4d_consumption
cons_5d: sensor.linky_daily_5d_consumption
cons_6d: sensor.linky_daily_6d_consumption
hp_cons: sensor.conso_hp
hc_cons: sensor.conso_hc
hc_hp_percent: sensor.rapport_hc_hp
daily_cost: sensor.cout
monthly_cons_evol: sensor.evolution_conso_mensuelle
I know this post seems a little like a draft, but if needed I’ll update it to include now features.
Feel free to use it for your house, and to ask questions if needed. For thoses who noticed my english isn’t perfect, I’m sorry I’m french