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):
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.
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:
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
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
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?
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:
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
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.
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.