Smart-Me energy montiroing template sensors

Hi Peter!
yes it would seem so.

they actually state that the internal address is -1
so i simply took the address eg. 2004 which is 8196 - and then i substracted 1
which is the one for total watt etc.

i dont have solarpanels - so cant verify the export part - but you can always compare with the app.
also -please remember the correct scale.

Hi Hostrup,
Thanks for the fast response.

Remember the correct scale - what do you mean when you mention scale?

You still dont experience these outliers in your reading?

I experienced it and are trying with a filter (outliers) to see if I can filter it away

Hi!
By scale i mean: scale: 0.001
so that you get the correct scale ( according to the value you read ).
With regards to the spikes - then no.
my data seems pretty consistant.
do you also get the spikes on the smart-me app / webinterface?
and as i wrote earlier - i have no solarpanels - so i dont export any power -
maybe it has something to do with that?

br Ronni

Hi all :slight_smile:

I have been away, from this community, for quite some time. But I have had some time to further investigate the issue with the “spikes”.

There are spikes on the smart-me web-interface.

I then changed the setup, so that it used the Modbus TCP protocol.
Using Wireshark, I could detect the same kind of spikes, in the network data.

It appears that the spikes originate either from the smart-me meter, or the Kamstrup meter.
I’m just not sure how to locate the actual source of the problem.
I’m not too keen on the idea of spending money on a new smart-me unit, if the issue is with the Kamstrup meter.

Hi Hostrup,
Thanks for your good input :slight_smile:

I am trying through the webinterface now and see if that improve the situation.

Hi Michael,

I had the spikes as well when I use the data directly from the Smart-Me/Kamstrup.
I am now trying through the webinterface instead and so far I have not seen the spikes.




Hi @hostrup
I got this peak today and I can see from the smart-me app that it have a even higher peak. Its very clear in the export section as I have not produced any power but exported 66.7kWh
The Import is properly correct (I did charge the car during the night)

So not completely solved, I hope its a one timer.

I have ordered a Saveeye and will test that one as well.

Hi Peter!
OK - it’s strange what happens - again - i have no “export” because i only consume power - as i dont have any solarpanels.

If you go to the smart-me homepage - and login there - you have the option to export your data - in both excel and csv format.

maybe you can try to export your data - and see how it looks there?
if there is an error on your Kamstrup meter - you should contact the utility company.
But - i guess your billing is ok - so my suspecion is that your smart-me meter might be defective.

have you tried to contact smart-me support? maybe they can add som value - as to why they think the spikes apear?

br Ronni

Hi Ronni,
It have actually not happened the last 3 weeks, I will cross my fingers and hope that everything is good. If I experience it again I will try to do as you say, look into the values I can export from Smart me and see there the problem is.
Br,
Peter

Hi Peter!
Great to hear.
I can tell that my integration also runs pretty smooth.
i use the modbus/tcp connection.
sometimes it “drops” the connection - and then i have to restart HA to make the connection available again. besides that - it works perfect.
i did play arround with the options for the modbus integration - but i haven’t found a 100% bulletproof connection type yet. :slight_smile:

@hostrup

thks for sharing this. Have installe smart-me based on your setup. All wroks fine except being able to add it into the energy tab:

I have used your setup in my templates.yaml file:

- sensor:
    - name: "El forbrug aktuelt stat"
      unit_of_measurement: kW
      state: "{{ states('sensor.el_forbrug_aktuel') }}"
      attributes: 
        device_class: power
        state_class: measurement        
    - name: "El Måler stat" #the one that i use on the energy tab
      unit_of_measurement: kW
      state: "{{ states('sensor.el_forbrug_total') }}"
      attributes:
        device_class: "energy"
        state_class: "total_increasing"

but get the following error:

Logger: homeassistant.components.sensor
Source: components/sensor/__init__.py:597
Integration: Sensor (documentation, issues)
First occurred: 2:35:59 PM (1 occurrences)
Last logged: 2:35:59 PM

Sensor sensor.el_forbrug_aktuelt_stat has device class None, state class None and unit kW thus indicating it has a numeric value; however, it has the non-numeric value: unknown (<class 'str'>); Please update your configuration if your entity is manually configured, 

Any idea what I am doing wrong

Marinus

@hostrup

Hi I’m new here and I’m expermenting a bit with your API integration to the Smart-Me for the Kamstrup meter.
I have solar panels so I also get exports values
Am I the only one who wonders over the the reading “CounterReading” the “CounterReading” is not the value shown on the front of the Kamstrup meter (not on my meter anyway) my meter show the value of “CounterReadingImport”.
The value of “CounterReading” is the “CounterReadingExport” subtracted from “CounterReadingImport”

“CounterReading”: 29747.519999999997,
“CounterReadingImport”: 33714.31,
“CounterReadingExport”: 3966.79,

Rgds Knud

Hi Knud!
I cant test that - as i only have import :slight_smile:

I might have found a workaround to the “spikes” issue… Well at least on my setup :upside_down_face:
Still in a test phase, but no spikes have occured since March 20th.

I noticed that the registers “Active Energy Import Total” and “Active Energy Import Tariff 1” are always identical. “Spikes” often appear in one or the other, but apparently never in both of them, at the same time.

Using a template sensor, and some scripting, I basically do the following:

  • Set a margin of how big a change in the value, is acceptable (In my case: 10kWh - Not even possible for me to use that much energy in 15 seconds, but spikes are always much bigger.)
  • Check the value of “Active Energy Import Total”. If the value is within acceptable limits, use that value.
  • Check the value of “Active Energy Import Tariff 1”. If the value is within acceptable limits, use that value.
  • If none of the registers return “valid” data, use the templates previous value.

This is my setup:

modbus:
  - name: "kamstrup"
    type: tcp
    close_comm_on_error: true
    host: HIDDEN
    port: HIDDEN
    delay: 2
    sensors:
      - name: "Kamstrup -  Active Energy Import Total - kWh"
        unique_id: "kamstrup_active_energy_import_total_kwh"
        device_class: energy
        state_class: total_increasing
        address:  8267
        count: 2
        unit_of_measurement: kWh
        scale: 0.001
        precision: 2
        data_type: int32
      - name: "Kamstrup -  Active Energy Import Tariff 1 - kWh"
        unique_id: "kamstrup_active_energy_import_tariff_1_kwh"
        device_class: energy
        state_class: total_increasing
        address:  8271
        count: 2
        unit_of_measurement: kWh
        scale: 0.001
        precision: 2
        data_type: int32

template:
  - sensor:
    - name: "Kamstrup - kWh"
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: kWh
      state: >
        {% set margin = 10 %}
        {% set new_kwh_value = none %}
        {% set total_kwh_state = states('sensor.kamstrup_active_energy_import_total_kwh') %}
        {% set tariff_1_kwh_state = states('sensor.kamstrup_active_energy_import_tariff_1_kwh') %}
        {% if total_kwh_state != 'unavailable' and tariff_1_kwh_state != 'unavailable' %}
          {% set previous_kwh_value = state_attr('this', 'previous_state')|float if state_attr('this', 'previous_state') is not none else none %}
          {% set new_kwh_value = previous_kwh_value %}
          {% set total_kwh = total_kwh_state|float %}
          {% if previous_kwh_value is not none %}
            {% if total_kwh is not none %}
              {% set delta_total_kwh = total_kwh - previous_kwh_value %}
              {% if (delta_total_kwh|float >= -(margin|float)) and (delta_total_kwh|float <= (margin|float)) %}
                {% set new_kwh_value = total_kwh %}
              {% endif %}
            {% else %}
              {% if tariff_1_kwh_state is not none %}
                {% set tariff_1_kwh = tariff_1_kwh_state|float %}
                {% set delta_tariff_1_kwh = tariff_1_kwh - previous_kwh_value %}
                {% if (delta_tariff_1_kwh|float >= -(margin|float)) and (delta_tariff_1_kwh|float <= (margin|float)) %}
                  {% set new_kwh_value = tariff_1_kwh %}
                {% endif %}
              {% endif %}
            {% endif %}
          {% else %}
            {% set tariff_1_kwh = tariff_1_kwh_state|float %}
            {% if total_kwh|float == tariff_1_kwh|float %}
              {% set new_kwh_value = total_kwh %}
            {% endif %}
          {% endif %}
        {% endif %}
        {{ new_kwh_value }}

Not the prettiest piece of code, but it’s a work in progress :see_no_evil:

Any ideas to improve it, are welcome.

1 Like

Hey guys

I’m in posession of a new power meter which is using smart-me as a gateway.
Besides the total energy consumption (which is working fine), I also have the total consumption splitted up by tariff (T1 and T2). I created the sensors but the energy dashboard somehow isn’t able to properly read it although the sensor seem to be properly configured.

For some reason the energy dashboard takes the total amount and adds it to the consumption resulting in let’s say 100kWh energy consumption for 1 hour.

Did anyone have a similar issue?
I’m currently not using modbus (since it’s behind a paywall), so only API.

Any advice would be welcome.

Please find my sensor configuration and the template below:

rest:
  - authentication: basic
    username: !secret smart-me_username
    password: !secret smart-me_password
    scan_interval: 30
    resource: https://smart-me.com:443/api/Devices/<ID>
    sensor:
      - name: "Stromverbrauch aktuell" #this shows the current use i kw
        value_template: '{{ value_json.ActivePower }}'
        unit_of_measurement: "kW"
        device_class: "power"
        json_attributes:
          - "ActivePower"
          - "Name"
          - "Serial"
          - "ActivePowerUnit"
      - name: "Stromzähler" #this shows the total meter reading - from when the meter was installed
        value_template: '{{ value_json.CounterReading}}'
        unit_of_measurement: "kWh"
        device_class: "energy"
        json_attributes:
          - "CounterReadingT1"
          - "Name"
          - "Serial"
          - "CounterReadingUnit"
      - name: "Stromzähler T1" #this shows the T1 meter reading - from when the meter was installed
        value_template: '{{ value_json.CounterReadingT1}}'
        unit_of_measurement: "kWh"
        device_class: "energy"
        json_attributes:
          - "CounterReadingT1"
          - "Name"
          - "Serial"
          - "CounterReadingUnit"
      - name: "Stromzähler T2" #this shows the T2 meter reading - from when the meter was installed
        value_template: '{{ value_json.CounterReadingT2}}'
        unit_of_measurement: "kWh"
        device_class: "energy"
        json_attributes:
          - "CounterReadingT2"
          - "Name"
          - "Serial"
          - "CounterReadingUnit"
template: 
  - sensor: 
    - name: "Aktueller Stromverbrauch"
      state: "{{ states('sensor.stromverbrauch_aktuell') }}"
      unit_of_measurement: kW
      attributes: 
        device_class: power
        state_class: measurement
  - sensor: 
    - name: "Stand Stromzähler Total"
      unit_of_measurement: kWh
      state: "{{ states('sensor.stromzahler') }}"
      attributes: 
        device_class: energy
        state_class: total_increasing 
  - sensor: 
    - name: "Stand Stromzähler T1"
      unit_of_measurement: kWh
      state: "{{ states('sensor.stromzahler_t1') }}"
      attributes: 
        device_class: energy
        state_class: total_increasing 
  - sensor: 
    - name: "Stand Stromzähler T2"
      unit_of_measurement: kWh
      state: "{{ states('sensor.stromzahler_t2') }}"
      attributes: 
        device_class: energy
        state_class: total_increasing 

And here a picture of the energy dashboard:

EDIT

NVM I realized when looking at the sensor those spikes are indeed returned by the API as already mentioned before my post.
However, it seems that this isn’t an issue when getting the values directly via modbus.

[quote=“Danne46, post:40, topic:339375, full:true”]
Thanks for sharing.Have done copy and past your integration, just filled in email and password and device id.But can’t get it working, problem with entity uid. Tried to fix that but think I am stupid or to new in this. Would be great to get a panel for energy.Using nabu casa green.

As mentioned before, if device ID does not work, try it with the serial:
resource: https://smart-me.com:443/api/DeviceBySerial?serial=yourserialhere
You’ll find your serial on https://webforms.smart-me.com

Hi everbody :slight_smile:

Got the smart-me module for kamstrup omnipower and have activated modbus.

Would one of you experts consider to make a real integration for HA on this Smart-Me/Kamstrup solution. Can’t get it up and running.

Would be greatly appreciated.

Thank you :slight_smile:

Hello !

Just found this post and i made a custom integration via custom repository on HACS to integrate Smart-Me counter based on hostrup post.

you can find it here : ahokami/ha-smartme: HA integration for smartme counter

This is the first time i make something like that so sorry if it’s not properly published

Hello, i just made one. you can try it and tell me if it works