Glow / Hildebrand Display - Local MQTT Access - Template Help

I’ve managed to calculate costs for my peak/off-peak Intelligent Octopus electricity supply, with the help of this guide: https://community.home-assistant.io/t/simulating-different-tou-electricity-plans-with-utility-meter-automations-and-templates/494374.

First I created a daily utility meter with named “peak” and “off-peak” tariffs based on today’s import from MQTT, named “Electricity Used”.

Then, I created an automation to set the tariff to either “peak” or “off-peak”, using the binary sensor from the IO HACS integration (alternatively, I could have based it on the time):

alias: Update Octopus Tariffs
description: ""
trigger:
  - type: turned_on
    platform: device
    device_id: XXX
    entity_id: binary_sensor.octopus_intelligent_slot
    domain: binary_sensor
    variables:
      tariff: off-peak
  - type: turned_off
    platform: device
    device_id: XXX
    entity_id: binary_sensor.octopus_intelligent_slot
    domain: binary_sensor
    variables:
      tariff: peak
condition: []
action:
  - service: select.select_option
    data:
      option: "{{ tariff }}"
    target:
      entity_id: select.electricity_used
mode: single

This creates and fills two daily “buckets” for peak and off-peak energy used.

Finally, I used a template sensor to calculate the daily cost:

template:
  - sensor:
      - name: Daily Electricity cost
        state_class: total_increasing
        device_class: monetary
        unit_of_measurement: GBP
        icon: mdi:currency-gbp
        state: >
          {% set peak_cost = states('sensor.electricity_used_peak')|float * 0.429 %}
          {% set off_peak_cost = states('sensor.electricity_used_off_peak')|float * 0.10 %}
          {{ (peak_cost + off_peak_cost + 0.5109) | round(2) }}

I could have fetched the current rates and daily charge from the octo API, but they’re just hardcoded for the moment.

Hopefully this is useful to someone else.
Tim

1 Like

Hi, I know this is an ages old message, but I did the multiplication in the import today (same thing for month and week), not the cost, so that figure is also correct.

For example :-

  - name: "Smart Meter Electricity: Import (Today)"
    unique_id: "smart_meter_electricity_import_today"
    state_topic: "glow/441793525B28/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'] * 1000) }}
      {% endif %}
    icon: "mdi:flash"

Awesome work!

Tip: If you want all the MQTT data to show up under a single device (so all the entities are “related”), you can append the following to the MQTT configuration for each sensor:

      device:
        identifiers: REDACTED
        manufacturer: GLOW
        name: Glow IHD
        model: Display and CAD SMETS2

so, for the live consumption data:

- state_topic: "glow/REDACTED/SENSOR/electricitymeter"
      name: GLOW Electricity current consumption
      unique_id: glow_elec_current_consumption
      device_class: power
      state_class: measurement
      icon: mdi:meter-electric
      expire_after: 120
      value_template: "{{ value_json.electricitymeter.power.value }}"
      unit_of_measurement: kW
      availability:
       topic: "glow/REDACTED/STATE"
       value_template: "{{ value_json.han.status }}"
       payload_available: joined
      device:
        identifiers: REDACTED
        manufacturer: GLOW
        name: Glow IHD
        model: Display and CAD SMETS2

have also added availability checking and an expire after in case the device disconnects

4 Likes

Anyone else have issues creating the dashboard in Lovelace ? I get the error No card type found

amazing blueprint!
any chance you could edit it and create a device for the smart monitor itself to display the signal strength etc?

{
  "software": "v1.8.13",
  "timestamp": "2023-03-27T11:13:28Z",
  "hardware": "GLOW-IHD-01-1v4-SMETS2",
  "wifistamac": "4417935049C8",
  "ethmac": "4417935049CB",
  "smetsversion": "SMETS2",
  "eui": "70:B3:D5:21:E0:00:E4:73",
  "zigbee": "1.2.5",
  "han": {
    "rssi": -55,
    "status": "joined",
    "lqi": 180
  }
}

EDIT: managed to work it out myself!

I have edited it to include RSSI, LQI and Status. Actually turns out my IHD dropped offline a week or so ago and I never noticed so this is pretty useful as I can ping myself a message if that happens again. (Energy graph currently showing I have used 300 kWh today…)

I will refine it at some point as it has LQI as being measured in db and the RSSI and LQI values should probably both be in diagnostic section

cheers thank you! just one spelling mistake line 336 Staus should be Status hehe

1 Like

Thanks for the awesome work on this, I just deployed the blueprint to my instance last night. I have one slight issue, I only receive the “unavailable” state the the 2 cost sensors

> sensor.smart_meter_electricity_import_today_cost
> sensor.smart_meter_gas_import_today_cost

Are you able to provide any trouble shooting steps to get this working?

Hey - has anyone worked out how to create a sensor that can calculate the electric cost from the MQTT data when you have solar panels?

Have tried the below but because the solar panels also push power back to the grid, when the MQTT sensor has negative values (e.g. -400w) it subtracts from the sensor.

Need an ‘if negative value ignore’ logic in there but can’t work out how to add that?

  - sensor:
      - name: "Local Smart Meter Electricity: Current Cost"
        unique_id: smart_meter_electricity_current_cost
        device_class: monetary
        unit_of_measurement: "GBP"
        state_class: "total_increasing"
        icon: mdi:cash
        state: "{{ (
            states('sensor.smart_meter_electricity_power') | float 
            / 1000 
            * states('input_number.octopus_go') | float
          ) | round(2) }}"

maybe I should RTFM before posting :slight_smile:

To follow up on this, I managed to resolve the warnings in the log by changing the state class to total and explicitly setting the last_reset to fix the negative cost values:

template:
  sensor:
    - name: "Smart Meter Electricity: Cost (Today)"
      unique_id: smart_meter_electricity_cost_today
      device_class: "monetary"
      state_class: "total" # requires "last_reset" for use to track costs in energy dashboard
      unit_of_measurement: "GBP"
      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) }}"
      attributes:
        last_reset: "{{ today_at('00:00') }}" # required for use as "total" in energy dashboard

On why total is the right “state class” (rather than total_increasing), see the related discussion here:

5 Likes

Thanks for this, I was going to raise the same issue as I couldn’t understand why the Energy Dashboard stipulates one thing but HA warnings say not allowed. Seemed to me that the HA devs had created a bug without looking at their own documentation.

I read your github issue and the whole process was like “herding cats” or “pulling teeth” as we say in the UK.
Why wasn’t Frenck more supportive by providing examples which you guys asked for? Or was it that he just didn’t understand and just towed the party line until he had to listen?
I had a similar experience re Bluetooth Classic and it’s documentation - ran into Frenck - a brick wall.

Hi - just got this all working but my Import Unit Rate from Octopus is wrong on the device, showing 0.1575 - I wish (!) - more like 0.4… how can I fix this?

@monkeydust you cant. This is the value Octopus have set on your smart meter however they rarely update smart meter values. It is pretty much a waste of time importing this data into HA. Your best bet is to create your own entity and populate the value yourself if you are going to want to use the value for calculations

2 Likes

I spoke to someone at Hildebrand/Glow last week as mine were wrong and had only a fixed value, not changing as I’m on Octopus Flux. They are working on adding settings in the CAD/IHD so you can add them yourself.

1 Like

Yes, Jane said it is in the pipeline but that was a few months back

Just spotted this as i finally got around to working out why my Energy dashboard stats were a bit shot. The actual entities all seemed to be fine, but the stats being used my the dashboard were off (often by a £1.20 or so. I realised that the costs for the previous day was not being fully reset to 0. It would decrease and then about 5 mins past midnight report a value that was just a bit less than yesterdays maximum. So if i got a few days in a row where the number wouldn’t fully zero then the problem just gets progressively worse.

I have now changed the template sensor as above as i was getting the errors when changing the data fields about the last reset not being defined. The numbers seem ok (albeit an exact double of what has actually been used) so i am hopefully for tomorrow. I understand the stats etc have to work with a wide range of sensors bots custom and from devices but i wish it was slightly more user friendly to edit things when they go wrong.

My sensor appear to be working but I get the logs flooded with this:

    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 594, in state
    raise ValueError(
ValueError: Sensor sensor.v2smart_meter_electricity_energy_export has device class 'energy', state class 'total_increasing' unit 'kWh' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unknown' ()
2023-07-22 16:07:34.050 ERROR (MainThread) [homeassistant.components.mqtt.models] Exception raised when updating state of sensor.v2smart_meter_electricity_energy_export, topic: 'glow/78E36DD0A778/SENSOR/electricitymeter' with payload: b'{"electricitymeter":{"timestamp":"2023-07-22T15:07:25Z","energy":{"export":{"cumulative":0.000,"units":"kWh"},"import":{"cumulative":54647.570,"day":8.906,"week":106.220,"month":419.906,"units":"kWh","mpan":"not available","supplier":"---","price":{"unitrate":0.28080,"standingcharge":0.47910}}},"power":{"value":0.457,"units":"kW"}}}'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 590, in state
    numerical_value = int(value)
                      ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'unknown'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/mqtt/models.py", line 270, in process_write_state_requests
    entity.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 742, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 810, in _async_write_ha_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 748, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 594, in state
    raise ValueError(
ValueError: Sensor sensor.v2smart_meter_electricity_energy_export has device class 'energy', state class 'total_increasing' unit 'kWh' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unknown' ()

I suspect your “state class” is incorrect for the sensors.
‘total_increasing’ , will work but causes HA to throw these errors.
If this is the case then the solution is higher up the blog.

This does not appear to work for me:
The system cannot restart because the configuration is not valid: Invalid config for [mqtt]: [attributes] is an invalid option for [mqtt]. Check: mqtt->mqtt->sensor->13->attributes.

This is my config:

mqtt:
  sensor:
    - name: "Smart Meter Electricity: Energy Export"
      unique_id: "smart_meter_electricity_energy_export"
      state_topic: "glow/xxxxxxxx/SENSOR/electricitymeter"
      device_class: "energy"
      unit_of_measurement: "kWh"
      state_class: "total_increasing"
      value_template: "{{ value_json['electricitymeter']['energy']['export']['cumulative'] }}"
      icon: "mdi:flash"

changing the state_class to total and adding:

    attributes:
         last_reset: "{{ today_at('00:00') }}" # required for use as "total" in energy dashboard

generates an error