Hey @robertalexa the setup has been working fine for months, then suddenly stopped in the early hours of the morning.
I’ve added your latest mqtt & template definitions, updated the REDACTED bits with those that match my system to see if some config had become corrupt.
I’ve done a config check in Dev tools and all passes, but on restart of HA I see a few errors in the logs relating to the template definition (see below) Any idea what’s causing this?
Source: helpers/template_entity.py:364
First occurred: 8:08:27 PM (2 occurrences)
Last logged: 8:08:27 PM
TemplateError('ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ ( 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) }}' but no default was specified') while processing template 'Template("{{ ( 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) }}")' for attribute '_attr_native_value' in entity 'sensor.smart_meter_electricity_cost_today'
TemplateError('ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ ( 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) }}' but no default was specified') while processing template 'Template("{{ ( 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) }}")' for attribute '_attr_native_value' in entity 'sensor.smart_meter_gas_cost_today'
@robertalexa just setup my new IHD with MQTT and followed your guide and everything worked first time! Thanks very much for creating such an easy way to set this up. Much appreciated.
I am also having a similar issue but I think the cause is different. My issue is that gas usage being recorded per day isnt being zero’d properly at the start of each day. I am unsure if this is an issue with MQTT data being sent from the CAD Display or with the template sensor.
Below is the entity graph for gas use over the last few days, as you can see the value drops but then immediately returns to yesterdays highest reading, this then sorts itself out by about 6-7am but by that point the usage is already skewed as it is taking wrong information to start the calculations off with.
Has anyone else encountered this? Electricity usage seems fine. Ultimately the usage data is right its just that the daily reset doesn’t happen properly.
I have just done a more thorough look of the posts in this thread (there are a lot) and noticed that this was discovered tail end of last year. I have now implemented this additional sensor to see how it works as listed in this post. I will report back if this resolves my issue. Great work everyone, loving all this local data!
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.