Smart-Me energy montiroing template sensors

Hi all!
This post might just serve as a sanity check for - but i hope someone can help verify if my approach getting energy information to show up on the new energy tab - is correct. :upside_down_face:

I have bought a smart-me han module. my Electrical Meter is From Kamstrup, and they provice a HAN port - that smart-me created an device for.
This module has the possibility to transfer my electrical meter readings to their cloud service.
They have a free REST based API - that i currently use - but you can actually also connect to the device via MODBUS over TCP - which i have not yet looked into.

I have integrated my device - with sensors - based on this rest call:
https://smart-me.com:443/api/Devices/<<device_uid>>

which gives me this in return:

{
    "Id": "DeviceID",
    "Name": "ElektravejHAN",
    "Serial": mySerial,
    "DeviceEnergyType": 1,
    "FamilyType": 6,
    "ActivePower": 0.425,
    "ActivePowerUnit": "kW",
    "CounterReading": 22684.57,
    "CounterReadingUnit": "kWh",
    "CounterReadingT1": 22684.57,
    "CounterReadingT2": 0.0,
    "CounterReadingT3": 0.0,
    "CounterReadingT4": 0.0,
    "CounterReadingImport": 22684.57,
    "CounterReadingExport": 0.0,
    "Voltage": 233.0,
    "VoltageL1": 233.0,
    "VoltageL2": 234.0,
    "VoltageL3": 233.0,
    "CurrentL1": 1.41,
    "CurrentL2": 1.16,
    "CurrentL3": 0.98,
    "ActiveTariff": 1,
    "ValueDate": "2021-09-17T11:42:47.6264689Z"
}

I have then created the following sensors in my configuration.yaml file:

rest:
  - authentication: basic
    username: "[email protected]"
    password: "password"
    scan_interval: 30
    resource: https://smart-me.com:443/api/Devices/<<device_uid>>
    sensor:
      - name: "EL aktuelt forbrug" #this shows the current use i kw
        value_template: '{{ value_json.ActivePower }}'
        unit_of_measurement: "kW"
        device_class: "power"
        json_attributes:
          - "ActivePower"
          - "Name"
          - "Serial"
          - "ActivePower"
          
      - name: "EL MĂĽler" #this shows the meter reading - from when the meter was installed
        value_template: '{{ value_json.CounterReading}}'
        unit_of_measurement: "kWh"
        device_class: "energy"
        json_attributes:
          - "ActivePower"
          - "Name"
          - "Serial"
          - "ActivePower"

and then - to make it visible in the energy tab - i have created a template sensor - based on the meter

template: 
  - sensor: 
    - name: "El aktuelt forbrug stat"
      unit_of_measurement: kW
      state: "{{ states('sensor.el_aktuelt_forbrug') }}"
      attributes: 
        device_class: power
        state_class: measurement
        #last_reset: "{{ state_attr('sensor.eloverblik_energy_total', 'metering_date') }}"
  - sensor: 
    - name: "El MĂĽler stat" #the one that i use on the energy tab
      unit_of_measurement: kWh
      state: "{{ states('sensor.el_maler') }}"
      attributes: 
        device_class: energy
        state_class: total_increasing 

I have then added the “El måler stat” to th energy section - as well as my fixed price. pr. kwh
the values - are the current meter value - it’s an ever increasing value - that will never be reset - so it will keep increasing over time.

now - this is shown in the energy tab:

Now this seems “sane” - and as you can see data is flowing in.
But should i do more - to enable this to exist over time? right now i am not sure if i will loose my data when i restart my HA server?

I have also been looking into creating an utility meter - to show me the “price”, but i haven’t quite figured out how to do this yet.

Have anyone else used the smart-me han integration?

Best regards
Ronni

Hi Ronni!
This looks very cool. How has it been running, now you had it for some time?
Have you considered using Grafana to save the data over time?

// Mikkel

Hi Mikkel!
It’s been running flawless since my last post.
I have been gathering statistics and it’s actually pretty interesting to follow our consumtion habbits during the day.

The next project is to measure more specific areas - with some zigbee outlets that support power metering - they are however not fully supported in deconz yet - so it will have to wait until the next release.

1 Like

Looks amazing - I will definitely get this for myself. Thank you for sharing :slight_smile:

Hi really cool setup. i have tried to set up your solution and it will not receive data. i have had it retrieve data half an hour on a newly installed HA
and no contact again, what am I doing wrong, I can run modbus: no problems

Hi enggaard10
I have not tried with modbus - because i only have the free version, so i am only able to fetch data directly from their cloud service.

It’s been running for month for me - without any problems.

Have you tried connecting via postman or similier testing program - so verify that you can retrieve data?

Hello hostrup :slight_smile:

Hej.

nej jeg har ikke prøvet nogle test programmer, har du et link ?, med skal resource: https://smart-me.com:443/api/Devices/<<device_uid>> se südan eller skriver du Submeter nummeret ind i <<device_uid>> og hvordan skal det sü skrives ?

no I have not tried any test programs, do you have a link? with must resource: https://smart-me.com:443/api/Devices/ <<device_uid>> look like that or do you write the Submeter number into <<device_uid>> and how should it then is written ?

Hello again! / Hejsa!

https://www.postman.com/ -
Recomended for testing rest based services.

my call is exactly as you can see in my post https://smart-me.com:443/api/Devices/<<device_uid>>

but off course revice uid is my device uid eg.

https://smart-me.com:443/api/Devices/85595a3e-3b41-46e2-a736-063b5ccc72ff

Also - you can test directly using their own swagger site:
https://smart-me.com/swagger/ui/index

br Ronni

Hi Ronni :slight_smile:

it works now. I found found a way https://smart-me.com:443/api/DeviceBySerial?serial=92*****
it works for me and Modbus it needs to be set up in https://smart-me.com/swagger/ui

/Jan


Hi Ronni,

Thank you very much for your effort. This is really valuable, especially with the current energy prices.

I have followed your instructions with success, however, I do have one issue:

About once a day, It logs my full meter reading, as an hourly consumption, resulting in a huge spike.

Do you have any idea, where I messed up?

Thank you!!

Hi Peter!
No idea.
I havent done anything “more” than creating the sensors - and made sure that they were cumulative - meaning that they “count” up - have you create the same sensors as i have?
br Ronni

Hi Ronni,

I am prettey sure that they are the same:

template:

  • sensor:
    • name: “El aktuelt forbrug status”
      unit_of_measurement: kW
      state: “{{ states(‘sensor.el_aktuelt_forbrug’) }}”
      attributes:
      device_class: power
      state_class: measurement
      #last_reset: “{{ state_attr(‘sensor.eloverblik_energy_total’, ‘metering_date’) }}”
  • sensor:
    • name: “El MĂĽler status” #the one that i use on the energy tab
      unit_of_measurement: kWh
      state: “{{ states(‘sensor.el_maler’) }}”
      attributes:
      device_class: energy
      state_class: total_increasing

Br,
Peter

Hi Peter,

I’m having the same spikes.
It occurs about 2 - 3 times a week.
Have you found any solution to this?

Br,
Mikkel

Hi, this might be a bit off-topic, but I am also interested in this energy meter. The API polls the smart-me cloud. Is thery a way to use the device without internet (local API). Becaus if the internet would be offline, the cloud-calls and hence the whole energy management in the house would stop working…

Hi reinhard.
You should be able to use it locally via tcp/modbus
but i havent looked into it - as i think you need to pay for the local access via modbus to be opened.

Hi Mikkel,

Unfortunately no. I still get these peaks a few times a week, which makes the measurements more or less worthless. :frowning:

Hi

I have discovered that the Smart-Me meter returns quite a bit of data, that makes no sense, to me.
The attached images, shows a data export from the Smart-Me cloud.

Each and every time the value in column C (“Active Energy Import Total”) reads “0”, I get an energy-spike in Home Assistant.

All the other weird values, seem to be ignored, but I don’t really like the fact that the meter returns those kinds of data.


Hi Michael

Good observation. Maybe this could be raised to Smart Me?

Br
Mikkel

Hi Michael
Did you ever manage to find a solution to this?
I am frustrated still getting this invalid readings.

Hi Mikkel

Unfortunately no (but may be on to something).

I contacted Smart-Me regarding the situation.
They told me that the Kamstrup meter, is the source of the misread data.

They told me to read all the values from the Smart-Me module.
When a spike value occurs, I will get an often huge positive change in energy consumption.
The next value, should be normal, and will result in an opposite negative change in energy consumption, thus countering the spike value.

The thing is… utility_meter is designed to ignore negative changes in the energy consumption.

utility_meter/sensor.py (Lines 391 to 393):

        if (not self._sensor_net_consumption) and adjustment < 0:
            # Source sensor just rolled over for unknown reasons,
            return

Removing those lines kind of fixes the problem, except for the case when the spike happens at the beginning or end of the “cycle”. I have not been able to figure out how to fix a spike, across two different cycles.

1 Like