Well I have now tried multiple variations and so far what seems to make a difference is to set up the Utility Meter to measure the daily energy import or export (kWh) under YAML, not via the Helper menu (sub-menu of Settings). The only difference is in the YAML version I set the Tariffs option.
If I compare the two, I get the same kWh readings, but it appears the way the UI version is handled in the maths equation of the Template Sensor is different.
I will let it run for 24 hours and then I will add a Tariff to the UI version and see what happens. Maybe I am dreaming and need to triple check my settings, but I now have three variations running and only one is giving me history - the YAML Utility Meter!
EDIT:
Well I feel like a goose. After much trial and error, I found I had two problems:
1. Extraneous characters in my maths/state code; and
2. I hadn’t twigged to the obvious, that when I set up a new sensor, it will return an error in a formula until it has some data. So setting up a new solar generation sensor after sunset will most likely return “unknown” results on an equation until tomorrow. If only I had just waited 12 hours.
I did spend a bit of time working out how I want naming conventions, because quite a few of my sensors across HA don’t conform to any pattern. So as I was re-doing my energy set-up based on @del13r advice, I started re-naming or creating them like this:
sensor.
grid
_power ##(instant import W)
_energy ## kWh importing Currently all-time: sensor.grid_import_energy
_daily # Utility Meter single kWh EXISTS in config already
_tou ### Utility Meter parent of below
_peak ### use "peak" for single tariff instead of daily?
_shoulder
_offpeak
_supply_charge # $
_tariff # single $/kWh eg $0.3142
_tou ## used in automation if TOU
_peak ## if TOU - use "peak" for single tariff?
_shoulder
_off-peak
_cost # single tariff calculated by above (kWh * tariff)
_daily
_peak ## if TOU - use "peak" for single tariff instead of "daily"?
_shoulder
_off-peak
consumption
_power ##(instant W)
_net ##(instant production minus import W)
I thought this would be a simple & quick process, but so far I am up to 35 sensors (including allowing for future ToU and capped exports) I’m sure there are a couple I have missed- but there might be some I can collapse. I haven’t started on planning naming conventions for battery sensors yet!
I did start with explanatory names like “sensor.grid_energy_import_daily” but the names started getting too long and related-sensors weren’t grouped. I identified tier-1 names like “grid”, “solar” & “consumption” to allow a quick search of all “children” sensors.