Energy Integration Spike

Why does your entity_id not match the name of your sensor? It should be 1 to 1 unless you changed it manually. I’d verify you’re looking at the correct entity.

As for your template, when you convert the value to an int, you already have a number. So your availability template is doing nothing.

Supply the int with a default of none and check it against none. I.e. the end of your template should be int(default=none, base=16) is not none

Thanks @petro. entity_id doesn’t match being as I have manually added that name. Lol I have about 10 versions of the sensor going, all trying different things to resolve the problem. When I finally get there all the other sensor configs can be deleted and brought back inline with the names.
Sadly this hasn’t worked for me. The sensor now shows ‘Unavaible’ regardless of which of the following I try:

 - platform: mqtt
    name: "Home Gas M3 Raw 2"
    state_topic: !secret smart_hild_state_topic
    unit_of_measurement: m³
    value_template: "{{ (value_json['gasMtr']['0702']['00']['00']|int(default=none, base=16) is not none) * value_json['gasMtr']['0702']['03']['01']|int(base=16) / value_json['gasMtr']['0702']['03']['02']|int(base=16) }}"
    availability:
    - topic: !secret smart_hild_state_topic
      value_template: "{{ (value_json['gasMtr']['0702']['00']['00']|int(base=16)) | is_number }}"
    icon: 'mdi:flash'
    device_class: gas
    state_class: total_increasing
  - platform: mqtt
    name: "Home Gas M3 Raw 2"
    state_topic: !secret smart_hild_state_topic
    unit_of_measurement: m³
    value_template: "{{ (value_json['gasMtr']['0702']['00']['00']|int(base=16) * value_json['gasMtr']['0702']['03']['01']|int(base=16) / value_json['gasMtr']['0702']['03']['02']|int(base=16) }}"
    availability:
    - topic: !secret smart_hild_state_topic
      value_template: "{{ value_json['gasMtr']['0702']['00']['00']|int(default=none, base=16) is not none }}"
    icon: 'mdi:flash'
    device_class: gas
    state_class: total_increasing
  - platform: mqtt
    name: "Home Gas M3 Raw 2"
    state_topic: !secret smart_hild_state_topic
    unit_of_measurement: m³
    value_template: "{{ (value_json['gasMtr']['0702']['00']['00']|int(default=none, base=16) is not none) * value_json['gasMtr']['0702']['03']['01']|int(base=16) / value_json['gasMtr']['0702']['03']['02']|int(base=16) }}"
    availability:
    - topic: !secret smart_hild_state_topic
      value_template: "{{ value_json['gasMtr']['0702']['00']['00']|int(default=none, base=16) is not none }}"
    icon: 'mdi:flash'
    device_class: gas
    state_class: total_increasing
 - platform: mqtt
    name: "Home Gas M3 Raw 2"
    state_topic: !secret smart_hild_state_topic
    unit_of_measurement: m³
    value_template: "{{ (value_json['gasMtr']['0702']['00']['00'] * value_json['gasMtr']['0702']['03']['01'] / value_json['gasMtr']['0702']['03']['02'])|int(default=none, base=16) is not none}}"
    availability:
    - topic: !secret smart_hild_state_topic
      value_template: "{{ value_json['gasMtr']['0702']['00']['00']|int(default=none, base=16) }}"
    icon: 'mdi:flash'
    device_class: gas
    state_class: total_increasing
 - platform: mqtt
    name: "Home Gas M3 Raw 2"
    state_topic: !secret smart_hild_state_topic
    unit_of_measurement: m³
    value_template: "{{ (value_json['gasMtr']['0702']['00']['00'] * value_json['gasMtr']['0702']['03']['01'] / value_json['gasMtr']['0702']['03']['02'])|int(default=none, base=16) is not none}}"
    availability:
    - topic: !secret smart_hild_state_topic
      value_template: "{{ value_json['gasMtr']['0702']['00']['00']|is_number }}"
    icon: 'mdi:flash'
    device_class: gas
    state_class: total_increasing
 - platform: mqtt
    name: "Home Gas M3 Raw 2"
    state_topic: !secret smart_hild_state_topic
    unit_of_measurement: m³
    value_template: "{{ (value_json['gasMtr']['0702']['00']['00'] * value_json['gasMtr']['0702']['03']['01'] / value_json['gasMtr']['0702']['03']['02'])}}"
    availability:
    - topic: !secret smart_hild_state_topic
      value_template: "{{ value_json['gasMtr']['0702']['00']['00']|int(default=none, base=16) is not none }}"
    icon: 'mdi:flash'
    device_class: gas
    state_class: total_increasing

:cry:

The value template I provided should only have been in availabilities value template.

1 Like

@petro sorry to bother you again. I made the changes to the template and the sensor now looks like the following:

  - platform: mqtt
    name: "Home Gas M3 Raw 2"
    state_topic: !secret smart_hild_state_topic
    unit_of_measurement: m³
    value_template: "{{ value_json['gasMtr']['0702']['00']['00']|int(base=16) * value_json['gasMtr']['0702']['03']['01']|int(base=16) / value_json['gasMtr']['0702']['03']['02']|int(base=16) }}"
    availability:
    - topic: !secret smart_hild_state_topic
      value_template: "{{ value_json['gasMtr']['0702']['00']['00']|int(default=none, base=16) is not none }}"
    icon: 'mdi:flash'
    device_class: gas
    state_class: total_increasing

After restart and allowing MQTT to connect and pull data into HA, the sensor show as ‘Unavailable’. Sorry, but any other suggestions what im doing wrong in this config?

You changed the states value template. Are you sure that’s correct? Also consult your text logs for errors

Add me to the spike list… I use the following as an input for the energy dashboard and that works correctly (solar sensor):
image

And every day around 5 I have this spike:

Reply to self: anyone able to help a little?

Same here. As of yesterday, my Gas import has gone nuts too, all the values suddenly seem 100x what they should be. Normally I use 1.4m³ now its saying im using 128 m³

Additional info. After intensive troubleshooting…

When I reset the total day gen at 1:30:


Spikes gone, but still bad reading

When I use the total gen (not day gen):

I can’t get my readings right…

Same here, also regular energy spike in energy dashboard and sensors.
I am using grottserver (replaces growatt cloud) and have in in the engery output, battery charge and discharge parameters as well as in some other sensors, like grid frequency:

  - platform: mqtt
    state_topic: energy/growatt
    value_template: "{{ value_json['values']['pvfrequentie'] | int / 100 }}" 
    unique_id: growatt_grid_frequency
    unit_of_measurement: "Hz"
    name: Growatt - Grid frequency
    state_class: "measurement"      
    icon: mdi:waveform

I hope I solved the issue (at least no more spikes in a couple of days)

  1. I used the new format for mqtt sensor (instead of -plattform:mqtt)
mqtt:
  sensor:
  1. Then I used availability_template: direct after the value_template:
    New Code looks like this:
mqtt:
  sensor:
    - state_topic: energy/growatt
      value_template: "{{ value_json['values']['pvipmtemperature'] | int / 10 }}" 
      availability_template: "{{ value_json['values']['pvipmtemperature'] not in ['unavailable', 'unknown', 'Unknown', 'none']}}" 
      unique_id: growatt_ipm_temperature
      device_class: temperature
      unit_of_measurement: "°C"
      name: Growatt - IPM temperature
      state_class: "measurement"     

Best

*** Addition - didnt work. I had one energy spike again today. :frowning: ***

Very frustrating. Has no one an idea?

@tom_l closing my other topic isn’t of any help.

I opened a standalone topic in the hope I would get some help. Instead of being “part of another topic”.

I think most of the time you do a good job of moderation. But sometimes I think you’re not.

I honestly do not know why you are showing this kind of behavior. I am not aware that I am by any means polluting the forum.

How do I get rid of the negative spike? What do I need to change where?

For reference:

Neither is reposting duplicates.

You’ve been given advice in the other topic you should follow. Creating a new post is not going to change that.

Slap slap, seek help else where, not here?

He’s telling you to not post duplicate questions, which it is. Just bump your other post by replying in it. It’s the same as posting a new topic, but without the second topic. It moves your post to the top of the page and it actually gives it higher relevance when searched in the future.

This is more helpful