Glow / Hildebrand Display - Local MQTT Access - Template Help

My mqtt feed is UTC as well, so one hour behind the current summer time. It means you are experiencing the same issue as @glitter-ball . I suggest you try using the lifetime entity as he has sugested as see how that goes.

Unfortunately there is nothing i can do with code, apart from a specific hack for your use case.

I am trying to fix it using the below. It works fine in the delevoper tab but errors in yaml, any ideas?

  - name: "Smart Meter Gas: Cost (Today)1"
    unique_id: smart_meter_gas_cost_today1
    device_class: monetary
    unit_of_measurement: "GBP"
    state_class: "total_increasing"
    icon: mdi:cash
    {% if now() < now().replace(hour=0).replace(minute=45).replace(second=0).replace(microsecond=0) %}
       {{ states('sensor.smart_meter_gas_import_standing_charge') | float | round(2)}}
    {% else %}
        {{  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) }}
    {% endif %}

This basically says between 00:00 and 00:45 keep the daily total at the standing charge then after that do the normal calculations.

Developer tab

Thanks

You are missing the key for that value_template: > Add that in and indent everything based on that. You can see even in the preview in your developer tab that it does not have a key and is badly indented :slight_smile:

  - name: "Smart Meter Gas: Cost (Today)1"
    unique_id: smart_meter_gas_cost_today1
    device_class: monetary
    unit_of_measurement: "GBP"
    state_class: "total_increasing"
    icon: mdi:cash
    value_template: >
      {% if now() < now().replace(hour=0).replace(minute=45).replace(second=0).replace(microsecond=0) %}
         {{ states('sensor.smart_meter_gas_import_standing_charge') | float | round(2)}}
      {% else %}
          {{  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) }}
      {% endif %}

Now says:-

I am creating this as a template.

Apologies, havent paid attention to what you are doing. You dont need the value_template instead you need a state property as you are not creating a template sensor.

  - name: "Smart Meter Gas: Cost (Today)1"
    unique_id: smart_meter_gas_cost_today1
    device_class: monetary
    unit_of_measurement: "GBP"
    state_class: "total_increasing"
    icon: mdi:cash
	state: >-
      {% if now() < now().replace(hour=0).replace(minute=45).replace(second=0).replace(microsecond=0) %}
         {{ states('sensor.smart_meter_gas_import_standing_charge') | float | round(2)}}
      {% else %}
          {{  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) }}
      {% endif %}

Try this, also, have a look at the documentation on creating template sensors if needed.

I just came up with this monstrosity. This will certainly not work correctly :slight_smile:

- trigger:
    platform: state
    entity_id: sensor.smart_meter_electricity_import_today
  sensor:
    - name: "Smart Meter Electricity: Import Cost (Today)"
      device_class: monetary
      unit_of_measurement: GBP
      icon: mdi:currency-gbp
      state: >-
        {% set standing_charge = state_attr(this.entity_id, 'standing_charge') | float(default=0)%}
        {% set gross_cost = state_attr(this.entity_id, 'gross_cost') | float(default=0) %}
        {{ '{:.2f}'.format(standing_charge + gross_cost) }}
      attributes:
        gross_cost: >-
          {% set unit_rate = states('sensor.smart_meter_electricity_import_unit_rate') | float(default=0) %}
          {% set from = trigger.from_state.state | float(default=0) %}
          {% set to = trigger.to_state.state | float(default=0) %}
          {%- if from > to -%}
            {{ to * unit_rate }}
          {%- else -%}
            {% set consumed = trigger.to_state.state | float(default=0) - trigger.from_state.state | float(default=0) %}
            {% set previous_cost = state_attr(this.entity_id, 'gross_cost') | float(default=0) %}
            {{ previous_cost + consumed * unit_rate }}
          {%- endif -%}
        standing_charge: >-
          {{ states('sensor.smart_meter_electricity_import_standing_charge') | float(default=0) }}

Let me know how it goes. If it is reliable and it could help other people, I do not mind including it in the original post and giving you the credit.

To be honest I doubt it can be considered reliable as even restarting HA during the time when tariff changes will force that consumption chunk to be charged at incorrect unit price. It is a fun experiment though.

That did it. I dont expect it to be perfect but the cost is the main issue as that calculates and runs down which throws the cost out.

I will feedback tomorrow.

Thanks

1 Like

Could I ask what solar setup you have ?

Is it the older FIT scheme where you are not ‘paid’ for export ( You just get half the generation ).
Or the newer SEG scheme ?

From what I understand the problem is with the provider setting up the meter for the export data. If you are on the FIT ( as I am ). The provider has no interest in accessing this export data so does not turn it on. Only if you are on SEG do they want the data and therefore enable it in the meter.

Just one more thing (for now :)) the below is working, however it is not rounding it to 2 decimal places so I am currently getting: 1.47407624 instead of 1.47 though clicking the graph does show it correctly?

  - name: "Smart Meter Gas: Cost (Today)1"
    unique_id: smart_meter_gas_cost_today1
    device_class: monetary
    unit_of_measurement: "GBP"
    state_class: "total_increasing"
    icon: mdi:cash
    state: >
      {% if now() < now().replace(hour=0).replace(minute=45).replace(second=0).replace(microsecond=0) %}
        {{ states('sensor.smart_meter_gas_import_standing_charge') | float | round(2)}}
      {% else %}
        {{  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) }}
      {% endif %}

Screenshot 2022-10-19 at 17.52.39

What am I missing?

Thanks

Sorted, I missed some round brackets, the below now works

  - name: "Smart Meter Gas: Cost (Today)1"
    unique_id: smart_meter_gas_cost_today1
    device_class: monetary
    unit_of_measurement: "GBP"
    state_class: "total_increasing"
    icon: mdi:cash
    state: >
      {% if now() < now().replace(hour=0).replace(minute=45).replace(second=0).replace(microsecond=0) %}
        {{  states('sensor.smart_meter_gas_import_standing_charge') | float | round(2)}}
      {% else %}
        {{ ( 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) }}
      {% endif %}
2 Likes

So the first set of results look promising:-

Original sensor:-

Sensor using the code above:-

Energy dashboard for today:-

My meter reset at the same time again for me (00:38). So 45 minutes will be fine and will allow for some natural clock creep. Also it wouldn’t really matter if the sensor only started to calculate around midday as it would still update the energy dashboard correctly when it eventually started to use the calculations. So you could just have a sensor with a really big offset (if you get a random reset time) that was purely used for the energy dashboard cost.

To confirm the code I am using is: Glow / Hildebrand Display - Local MQTT Access - Template Help - #153 by hassio85

I will monitor over the next few days and report back.

Thanks

Hi, I"m having the same issue as @BertrumUK , but I didn’t seem to see a solution.

My Gas total doesn’t include the standing charge, however, the entity is reading as correct.

Screenshot 2022-10-22 234413

Excuse the triple post… only one media for new users per post.

Sorry, could you clarify what the issue is? I don’t remember what issue Bertrum had

Wow, thanks for the quick reply!

Basically, on the energy dashboard my Gas Total doesn’t include the standing charge.

However when I look at the entity [Smart Meter Gas: Cost (Today)] it is showing the correct amount, including the standing charge.

Could you please provide me the current value for:

Gas Import Standing Charge
Gas Import Unit Rate
Gas Cost Today
Gas Import Today (i know this is not the same entity used for the energy dashboard).
The gas import as shown on the energy dashboard
The gas price as shown on the energy dashboard

It should be whatever units used today as per energy dashboar * unit rate + standing charge = energy gas total which should be very similar to gas cost today. This is all correct at my end. If any of these entities are wrong, then the calculation will be wrong

Screenshot 2022-10-23 000759