what’s in the state topic? There’s nothing that explains to HA how to take the value from that topic and use it. I.e. i’ts missing a value_template
I’m interested in the state changes that home assistant sees. This is the information that’s a result of the home assistant state changes, so it’s the wrong table.
I can’t immediately tell where to get that mqtt history information, I can look into adding some kind of firehose on that topic so that I can read through the data and verify if there’s anything incorrect. Or is there a way to retrieve historical information through another way, is home assistant storing this somewhere?
In terms of configuration, I believe I followed the setup information when this feature was launched, if there’s anything missing from that, do you have any pointers where to look for an up to date config? The configuration itself to tell home assistant how to read these values is to my knowledge done by specifying the device_class, the unit_of_measurement and assigning it to the respective property of the energy feature? Let me know if I did miss something!
You should just be able to look at your history graph. That’s made from the non-long-term tables inside your database.
As for your configuration, that will depend on the topic. How is the device posting to your topic? Your current configuration has no safeguards against non numeric data.
Looking at the history graph there’s indeed a 400kWh drop (2688 → 2288), I’m curious now to find that information in the database but I can’t at least pin point it in the stastics_short_term.
Either way, that does indeed point to invalid data being pushed through, I’ll make sure to check the script that does the pushing and see if I can add some safety measures.
Is there anything possible on the receiving end btw? You mentioned value_template and safeguards, I’m assuming these will need to be set through a template sensor which takes the value from the mqtt and applies such guards? Can those evaluate that the state never can be below the state it had received before? (which in this case seemed to have happened)
you can add an availability to your mqtt configuration to look for numbers
availability:
- topic: your_state_topic
value_template: "{{ value | is_number }}"
This will make your sensor go unavailable when it’s not a number. When it returns, it won’t produce a spike.
This is assuming that the bad number is not coming from your custom script. You should look at the script and ensure 0 is not sent as a response to an error.
Thanks @petro for looking at this - I too am having issues, although I have tried to fix this with the availability code below to no avail. I am using ModbusTCP2MQTT to ingest my inverter data.
Your value_template, which produces your state is {{ value_json.daily_purchased_energy }}, that’s what’s making your number. | is number checks to see if a variable/equation is a number. So what do you think your value_template should be for availability?
I don’t think you understood my response. Your value_template for availability is not correct. My response was to help you correct your value template by leading you down the correct path.
Very much appreciate the help but I’m an absolute amateur when it comes to any sort of language other than english… but that said, and this is a guess based on my logic only, should it be “> 1” ?
had the same issue, have a sensor integrated via ESPHome.
Had the spikes too. Was a problem at the sending device.
Found a workaround using a median.
See the last four entries.
Let me try to make it clear (without giving you the answer, so that you can learn):
This is where your data is coming from:
This is your availability template:
So, your data is coming from value_json.daily_purchased_energy. You want to change {{ value | is_number }} so that it’s looking at value_json.daily_purchased_energy instead of value. So how would you change the template?
I to am having similar issues with both gas and electric sensors. I am using Hildebrand Glow CAD, with MQTT bridged to pull data from Hildebrand.
An example is from today for gas (electric also had spike at the same time however gas should only get updates every half hour from Hildebrand):
it is that simple. As for your edit, post your current configuration because what you have written prior to your edit should work. Your post edit template is jibberish.
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