Add a module to retrieve electricity use from Linky


#21

Hi everyone !

I’ve worked with this interesting script to retrieve data from Linky, and builded some template sensors based on the raw data. I’ve also build a custom card for the new Lovelace UI, that shows some informations about your Linky stats (in French, of course).

image

I don’t know if some people can be interested in this type of resources, but I can share it if needed :slight_smile:

Feel free to ask some questions about it !


#22

Hey! I am really interested in it, can you share your project?


#23

Très intéressé aussi ! :wink:


#24

Très intéressé aussi !


#25

very nice, interested too :wink:


#26

Very interested too ! Can you share it plz ?
Merci !


#27

@lmbuzi

Now that the sensor is out, we’re gonna need your custom card for Lovelace ! :slight_smile:

Bien joué pour cette carte, et merci !


#28

Hi !

Since this update, I can’t have my Enedis data anymore (it prompts “Login error: Please check your username/password.”). My username and password hasn’t changed, I don’t really understand the bug.
For the card, I used some template sensors I’ll need to update. Some config variables must be exposed to the user config, and the one that I wrote in my code won’t be the same for everyone. I need to adapt it, but I can’t because Linky isn’t working anymore.

When I’ll have it working again, I’ll send it to you all :slight_smile:

Stay tuned :wink:


#29

I can’t connect either.
Strange because I can with the plugin PyLink directly…


#30

Hi guys,

I get this error when I restart HA:
2018-10-01 16:06:53 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform linky is taking over 10 seconds.
2018-10-01 16:06:58 ERROR (Thread-9) [homeassistant.components.sensor.linky] Can not get data

Do you have any idea what’s going on ?


#31

I have this error with the official component:

ERROR (SyncWorker_9) [homeassistant.components.sensor.linky] Login error: Please check your username/password.

And I know that my username/password is good as it is working with the custom_component.

Also, it seems that the official component can only get the data from yesterday only…


#32

Hi
I have the same problem. Did you solve it??


#33

I am too, but can’t login like all…


#34

I am still using the Custom component developed by Pirionfr
and have no problems at all.


#35

Oh ok, I’ll try this one too then.


#36

@lmbuzi

Can you share it now ? :slight_smile:
The connector from Pirionfr is working, so we really appreciate your card !


#37

I’d like to share it, but I have to adjust some things. First, for me, the sensor isn’t working without PrionFr patch.
Also, to give you “Heures creuses” and “Heures pleines”, I’ll need to get half hourly consumptions. I’ll also need monthly consumption for the previous month, and daily consumptions for the past week.

When I’ll get that, I’ll start to edit the card to integrate it properly with the new sensor.

If you really want, I can send it to you, but you won’t be able to get it working (I am not able to get it working too :slight_smile:).


#38

You can get all that from Prionfir Custom Component. Just activate the sensors that you need in order to get the data.


#39

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 :slight_smile:


#40

Thanks for sharing !
I just changed:

resources:
  - url: /local/custom_ui/linky-card.js?v=1
    type: module

To make it work (and downloading a linky.png into www/images).

Unfortunately, I am not able to get the hourly metering any more (besides it is enabled), even with pylink. I will check later on.
Edit: Hourly metering is now OK.