Glow / Hildebrand Display - Local MQTT Access - Template Help

@glitter-ball Read the instructions again, you have set the wrong option for the costs in the Energy dashboard.

Smart Meter Gas: Import
Use an entity tracking the total costs: Smart Meter Gas: Cost (Today)

1 Like

Thanks - just spotted that myself! Fixed and all good. Great work producing all this.

1 Like

The only other niggle at the moment is that the cumulative gas kWh reading didn’t reset at midnight last night, but this morning when the first gas was used. I’ll see if it does it again tonight. If so, I’m guessing it’s something to take up with Glowmarkt…

Cumulative is not meant to reset. Cumulative is current meter reading and it will only go up. It will have the same value as if you were to read the meter physically.

Hope this helps.

Later edit: the energy dashboard figures it out how much you consumed by checking the value diffrence between times

Without knowing the exact behaviour of most sensors, but it seems unlikely that you would have energy sensors measuring kWh that would be state_class: measurement Are those not sensors that increase and reset per day/week etc?

The alternative would have been total, but it doesn’t quite feel appropriate as per the documentation. In reality it does not really matter that much. The cumulative sensors are using total_increasing as expected.

PS: the DCC integration uses the same state classes for similar entities.

Yeah I was thinking that total would be more appropriate for energy stuff. But fair

Yeah, I can see the reasoning, but in equal measure I can see why measurement is also appropriate. Particularly “current measurement” and “absolute value is interesting”.

I think it is ok anyway, the entity itself will have a history, and people can choose to keep that data into long term if they need to. Probably the most important is the cumulative being correct, as that is actively used in the Energy calculation whereas the rest are kinda irrelevant as you can have the same info by looking at the Energy per particular period of time.

1 Like

@drthanwho Saying that, I went back to the docs, and I think you are right, total might be the correct thing to do.

I should have been clearer. I’m looking at values in a graph card…

The electricity reset at midnight. The gas didn’t. I’ll see what happens tonight. Not sure, yet, why one resets and not the other.

@glitter-ball Can you please set up a new entity just for debugging purposes. Make sure to change REDACTED. And you will need to delete this entity in your config and HA when we are done to keep things clean. This new entity will not manipulate the value from mqtt, instead it will let it be as is. This way we can see exactly what info you are receiving.

- name: "Debug Gas: Import (Today)"
  unique_id: "debug_gas_import_today"
  state_topic: "glow/REDACTED/SENSOR/gasmeter"
  device_class: "energy"
  unit_of_measurement: "kWh"
  state_class: "measurement"
  value_template: "{{ value_json['gasmeter']['energy']['import']['day'] }}"
  icon: "mdi:fire"

I do not think this is code related to be honest, but rather what data the IHD sends or even what data the gas meter makes available. I suspect the gas meter will have reporting that is less often than electricity, because it is not connected to mains and needs to conserve energy. Or it could even be possible that the gas meter disconnects from the network because of range, or just instability.

Bear in mind these are just my thoughts and nothing certain, but let’s see what your data has to say. When you report back, can you please send screenshot from the History page, in 24 hours interval, so we can see the data nicely with every time slot.

For comparison, here are my sensors


Also, you can use the Energy dashboard to see your import by date, which is based on the Import entity (cumulative). On paper, these 2 figures should end up being identical, or very closed to each other. But i guess sometimes if something mis-reports, you will see differences?

My suggestion for total was because I’ve only ever seen energy being represented with total or total_increasing. As long as there are other sensors that can be used for the Energy Dashboard it shouldn’t matter as much. But for a lot of people configuraing sensors manyally they don’t have additionally the lifetime sensor and I see those coming in with daily sensors in Discord complaining they can’t add them because they have used measurement (or even worse power). I do see you have the total_increasing sensor for lifetime so it’s not as bad.

That said, and as it happened yesterday, someone was trying to add the daily sensor in Energy Dashboard and saying it’s broken when they should be using the lifetime one with total_increasing. So one positive thing would be that any of those sensor would be able to be used in the dashboard if they all had total / total_increasing

I’ll try and set up today. There are at least 2 things going on…

  • Electricity resets at 0100 BST, rather than midnight. That’s a time zone thing.

  • The gas fleetingly drops to zero at midnight BST and then jumps back to the previous day’s cumulative total until the first half-hour slot of consumption in the new day, whereupon it resets. This is screwing up the gas cost calcs too.

The gas meter only reports every 30 mins because it’s battery powered. But AFAIK it still reports if consumption is zero? If not, then we’re probably stuffed. That said, the total could be reset at midnight regardless.

1 Like

I’ve set the debug gas entity up and a matching electricity one, for interest. Then this happened…

image

I think the hiccup at about 18:11 is me switching the Glow IHD from displaying in kWh to displaying in £. No idea why it’s done that to the MQTT data. I switched back and saw nothing.

@robertalexa - OK. The results are in after one midnight transition. The gas debug version worked. The original didnt.


The electricity ones look identical - both reset at 01:00 BST instead of midnight…


Edit : Thought the debug gas one looked suspicious - there’s a thick line at midnight. Zooming in…

So it’s reset to zero at 00:00:39 then jumped back to previous day’s total at 00:03:09 and returned to zero permanently at 00:03:34! Oh dear. Not helpful. I’d better see what it does tonight…

1 Like

@glitter-ball Heya, thanks for posting those screenshots. Something is very suspicious though.

Can you please double triple check that the entities in your config are definitely using the code in my post? There have been numerous updates since my initial post and I am not sure if you are running the latest.

One other thing, can you please go to Developer Tools → Template and paste this in {{ now() }} . Compare the datetime output to the current time. Are they matching or is there a difference?

In case they do not, double check your settings in Settings → General

I am going away for a month as of later on this evening, so please do not think I am ignoring you if you don’t hear anything from me. Hopefully the above gets you sorted, if not, I will do my best to help you when i return.

PS: I have a feeling that your timezone is not correct in HA, the template checking the current time vs 00:01 will give the wrong result at the wrong time and thus you get stuck with the previous value.

I will be around for a few more hours so I can help in the meantime

The ‘now’ template reports 13:46 BST and my timezone is set as per your example. My electricity meter clock is showing BST, albeit a couple of minutes slow. I’m not sure the gas meter has a clock - if it does, it’s not visible or gas readings are stamped by the comms hub in the electricity meter. Both meters are reporting in GMT in the raw MQTT from the Glow IHD (1 hour behind with a ‘Z’ suffix)

Was hoping to attach my YAML to save screens of text here. Not sure I can do that, so apologies…

    sensor:  
    - name: "Smart Meter Electricity: Export"
      unique_id: "smart_meter_electricity_export"
      state_topic: "glow/REDACTED/SENSOR/electricitymeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "total_increasing"
      value_template: "{{ value_json['electricitymeter']['energy']['export']['cumulative'] }}"
      icon: "mdi:flash"
    - name: "Smart Meter Electricity: Import"
      unique_id: "smart_meter_electricity_import"
      state_topic: "glow/REDACTED/SENSOR/electricitymeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "total_increasing"
      value_template: >
        {% if value_json['electricitymeter']['energy']['import']['cumulative'] == 0 %}
          {{ states('sensor.smart_meter_electricity_import') }}
        {% else %}
          {{ value_json['electricitymeter']['energy']['import']['cumulative'] }}
        {% endif %}
      icon: "mdi:flash"
    - name: "Smart Meter Electricity: Import (Today)"
      unique_id: "smart_meter_electricity_import_today"
      state_topic: "glow/REDACTED/SENSOR/electricitymeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "measurement"
      value_template: >
        {% if value_json['electricitymeter']['energy']['import']['day'] == 0 
          and now() > now().replace(hour=0).replace(minute=1).replace(second=0).replace(microsecond=0) %}
          {{ states('sensor.smart_meter_electricity_import_today') }}
        {% else %}
          {{ value_json['electricitymeter']['energy']['import']['day'] }}
        {% endif %}
      icon: "mdi:flash"
    - name: "Smart Meter Electricity: Import (This week)"
      unique_id: "smart_meter_electricity_import_week"
      state_topic: "glow/REDACTED/SENSOR/electricitymeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "measurement"
      value_template: "{{ value_json['electricitymeter']['energy']['import']['week'] }}"
      icon: "mdi:flash"
    - name: "Smart Meter Electricity: Import (This month)"
      unique_id: "smart_meter_electricity_import_month"
      state_topic: "glow/REDACTED/SENSOR/electricitymeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "measurement"
      value_template: "{{ value_json['electricitymeter']['energy']['import']['month'] }}"
      icon: "mdi:flash"
    - name: "Smart Meter Electricity: Import Unit Rate"
      unique_id: "smart_meter_electricity_import_unit_rate"
      state_topic: "glow/REDACTED/SENSOR/electricitymeter"
      device_class: "monetary"
      unit_of_measurement: "GBP/kWh"
      state_class: "measurement"
      value_template: "{{ value_json['electricitymeter']['energy']['import']['price']['unitrate'] }}"
      icon: "mdi:cash"
    - name: "Smart Meter Electricity: Import Standing Charge"
      unique_id: "smart_meter_electricity_import_standing_charge"
      state_topic: "glow/REDACTED/SENSOR/electricitymeter"
      device_class: "monetary"
      unit_of_measurement: "GBP"
      state_class: "measurement"
      value_template: "{{ value_json['electricitymeter']['energy']['import']['price']['standingcharge'] }}"
      icon: "mdi:cash"
    - name: "Smart Meter Electricity: Power"
      unique_id: "smart_meter_electricity_power"
      state_topic: "glow/REDACTED/SENSOR/electricitymeter"
      device_class: "power"
      unit_of_measurement: "kW"
      state_class: "measurement"
      value_template: "{{ value_json['electricitymeter']['power']['value'] }}"
      icon: "mdi:flash"
    - name: "Smart Meter Gas: Import"
      unique_id: "smart_meter_gas_import"
      state_topic: "glow/REDACTED/SENSOR/gasmeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "total_increasing"
      value_template: >
        {% if value_json['gasmeter']['energy']['import']['cumulative'] == 0 %}
          {{ states('sensor.smart_meter_gas_import') }}
        {% else %}
          {{ value_json['gasmeter']['energy']['import']['cumulative'] }}
        {% endif %}
      icon: "mdi:fire"
    - name: "Smart Meter Gas: Import (Today)"
      unique_id: "smart_meter_gas_import_today"
      state_topic: "glow/REDACTED/SENSOR/gasmeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "measurement"
      value_template: >
        {% if value_json['gasmeter']['energy']['import']['day'] == 0 
          and now() > now().replace(hour=0).replace(minute=1).replace(second=0).replace(microsecond=0) %}
          {{ states('sensor.smart_meter_gas_import_today') }}
        {% else %}
          {{ value_json['gasmeter']['energy']['import']['day'] }}
        {% endif %}
      icon: "mdi:fire"
    - name: "Smart Meter Gas: Import (This week)"
      unique_id: "smart_meter_gas_import_week"
      state_topic: "glow/REDACTED/SENSOR/gasmeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "measurement"
      value_template: "{{ value_json['gasmeter']['energy']['import']['week'] }}"
      icon: "mdi:fire"
    - name: "Smart Meter Gas: Import (This month)"
      unique_id: "smart_meter_gas_import_month"
      state_topic: "glow/REDACTED/SENSOR/gasmeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "measurement"
      value_template: "{{ value_json['gasmeter']['energy']['import']['month'] }}"
      icon: "mdi:fire"
    - name: "Smart Meter Gas: Import Unit Rate"
      unique_id: "smart_meter_gas_import_unit_rate"
      state_topic: "glow/REDACTED/SENSOR/gasmeter"
      device_class: "monetary"
      unit_of_measurement: "GBP/kWh"
      state_class: "measurement"
      value_template: "{{ value_json['gasmeter']['energy']['import']['price']['unitrate'] }}"
      icon: "mdi:cash"
    - name: "Smart Meter Gas: Import Standing Charge"
      unique_id: "smart_meter_gas_import_standing_charge"
      state_topic: "glow/REDACTED/SENSOR/gasmeter"
      device_class: "monetary"
      unit_of_measurement: "GBP"
      state_class: "measurement"
      value_template: "{{ value_json['gasmeter']['energy']['import']['price']['standingcharge'] }}"
      icon: "mdi:cash"
    - name: "Smart Meter Gas: Power"
      unique_id: "smart_meter_gas_power"
      state_topic: "glow/REDACTED/SENSOR/gasmeter"
      device_class: "power"
      unit_of_measurement: "kW"
      state_class: "measurement"
      value_template: "{{ value_json['gasmeter']['power']['value'] }}"
      icon: "mdi:fire"
    - name: "Debug Gas: Import (Today)"
      unique_id: "debug_gas_import_today"
      state_topic: "glow/REDACTED/SENSOR/gasmeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "measurement"
      value_template: "{{ value_json['gasmeter']['energy']['import']['day'] }}"
      icon: "mdi:fire"
    - name: "Debug Electricity: Import (Today)"
      unique_id: "debug_electricity_import_today"
      state_topic: "glow/REDACTED/SENSOR/electricitymeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "measurement"
      value_template: "{{ value_json['electricitymeter']['energy']['import']['day'] }}"
      icon: "mdi:flash"`

and…

   - name: "Smart Meter Electricity: Cost (Today)"
     unique_id: smart_meter_electricity_cost_today
     device_class: monetary
     unit_of_measurement: "GBP"
     state_class: "total_increasing"
     icon: mdi:cash
     state: "{{ (
        states('sensor.smart_meter_electricity_import_today') | float 
        * states('sensor.smart_meter_electricity_import_unit_rate') | float 
        + states('sensor.smart_meter_electricity_import_standing_charge') | float
      ) | round(2) }}"
   - name: "Smart Meter Gas: Cost (Today)"
     unique_id: smart_meter_gas_cost_today
     device_class: monetary
     unit_of_measurement: "GBP"
     state_class: "total_increasing"
     icon: mdi:cash
     state: "{{ (
     states('sensor.smart_meter_gas_import_today') | float 
     * states('sensor.smart_meter_gas_import_unit_rate') | float 
     + states('sensor.smart_meter_gas_import_standing_charge') | float
   ) | round(2) }}"

Edit : Glow ID redacted…

Hi again. The above is exactly the problem. So the debug entity is just data exactly how it was received from the IHD, with no modifications at all. And this is exactly what is messing up your “normal” entity.

Because this is the template logic (of the “normal” entity):
If the value received is 0 and the time (now) is between 00:00 and 00:01 then accept the 0 value (daily reset). If the value is 0 AFTER 00:01, use the previously saved value - I have added this logic because in some instances the IHD reports a value of 0 randomly in the middle of the day, and then it goes back to what it was meant to be. That messes up the Cost entity and in turns messes up the cost on the Energy dashboard. Which is happening to you too. See how you don’t get negative values between 18:00 and 19:00, but you do in the Debug (raw) entity

So in your case, based on the information you have provided me:
00:00:39 - set to 0 (which is allowed by the template condition)
00:03:09 - the IHD erroneously sends old data
Any 0 value after that, will be dismissed and the previous value is used (from 00:03:09), which in your case is last night. No matter how many times you get a 0 value, it will always be recorded as the previous value (not 0)
Finally you get a new value that is NOT 0 and the sensor accepts the value.
image

That debug sensor proves that the problem is not with the code, but rather with the data sent by the IHD. Which might not even be the IHD that is wrong, it might be your smart meter making the mistake. But the best way to find this out is to get @JaneatGlow to assist. Maybe send Glow and email explaining what is happening, and provide them links to your post describing what happens with the Debug sensor (the post above).

I hope this helps you understand what is happening

The negative spikes in the debug entity is me putting the IHD in demo mode twice yesterday :flushed:.

Agree - it does look like the raw data is causing the issue. I’ll let it run for another day or two and then get a copy to @JaneatGlow to see what they make if it. I’ll also quiz them on why the electricity cumulative is resetting at 01:00.

Thanks for your patience and assistance. Have a good trip!

Yes but I have seen this behaviour where it randomly goes to 0 both at my end and other people above. So i think it is a possible case even with no manual “intervention”

Mine always resets at 00:00 so maybe the smart meters are misconfigured and the IHD is just a mere messenger. Also, when you talk to them, dont call it “cumulative” because in their terms, that refers to the total meter reading. Instead you could refer to it as Import Day (as per their MQTT standard). This way you avoid some confusion

You are very welcome and sorry I can’t help you too much.

The only thing that I can think of, which is a bit horrible, but might work is the following:

  • create an entity like “Yesterday Final Gas”
  • create an automation that runs every night at 23:59:59 that sets this new entity’s value to the current value of Import (Today). This way you now have a fixed reference of what was the last data.
  • change the template for Import (Today) and add another conditional to compare the current reading to the last known, and skip it if they are equal and the time is (for example) before 01:00.

I won’t be able to provide code for this as I am now running a bit short on time. I also don’t think this is the best approach, i would think the best method is to fix the problem rather than “hack it” so go with that approach first.

Hope this helps