I have this
The first one is input helper with manualle entered data
The second one is generated by HA, i.e. in my energy dashboard settings for gas_usage I use a fixed price so the one you see shows ‘today’ costs which are 0 as I did not enter anything today
From what i can see you seem to use a separate entity for the price not? Maybe that could be an issue??? But on the other hand it worked in SQLite
haha true, this is so annoying, getting crazy of it.
But i found out something else.
I did create another entity that collecs the data of my gas-usage.
So when i selected that entity, and selected the my entity with colletcing the total cost it works.
There is a stupid thing happening, check this out.
Story continues, my zigbee device transmitting from the elec meter had a connection issue for more than 1 day. Repaired yesterday…history of costs (!) all gone, I did not change the device and my consumption is still OK…yippie
So here is what I did …awaiting the next issue
0. made sure elect costs are no longer calculated (setting in Energy dashboard)
I removed all 5 cost sensors from /config/.storage/core_entity_registry
I removed all cost-sensor stuff from statistics and statistics_meta and statistics_short_term
I removed all states for these (was not too easy)
I reinstalled the cost sensor via energy dashboard, sensor.linky_base_cost now showing as only active one
I recreated the costs using the consumption sensor stats, inserting in statistics using sum = sum * 0.175, 0.175 my cost per kWh
The dashboard now shows fine again, I need to wait for the next 2 hrs if this stays fine
EDIT: why I needed to do this was because data from the original sensor.linky_base_cost ended up in sensor.linky_base_cost_2 and bits and pieces in _3 … _5…a total mess
Thanks for your info.
I think i got it working, i will also wait again from now on 30 minutes, as my new device what i created had + instead of * so if that works, i need to try how i can import the old data into this new device. but lets wait.
I also will report at 12:00 and see if it did calculate, but i think its correct.
I’m using a total cost device, using this template
So this (device) entity is called sensor.calculategaspricetest, this calculated the value i use in my helper
this is the template from the helper.
- sensor:
- name: Today GAS Total Cost
device_class: monetary
state_class: measurement
unit_of_measurement: EUR/m³
state: >
{{ (states('input_number.gasprice')|float(0))}}
Yes it works, calculation is correct now, using a TOTAL entity with the cost.
Thanks for the code, but i want to import all old costs, what where recorded in my database into this new one because my old costs are changed daily, but i want to import till yesterday and not today.
How can i do that ?
My new device ID is 135
my old device ID is 29
insert into statistics (created,start,state,sum,metadata_id) select created, start, 0, sum, [NEWcostsensor] from statistics where metadata_id = [OLDcostsensor] and start < '2022-12-01'
Note that if the newcostsensor already has values before today then it will throw an error as duplicates are not allowed
Mine works too but I have just screwed up too much with removing data. I mended the last short_term record to show the correct ‘total’ and now it shows fine again…not 100% confident after last nights reset of course … in other words, I know how to construct the right values now but I am totally in the dark as to when a reset takes place and why for pete’s sake it created 4 cost sensors since yesterday wihtout taking the correct values.
Well lets try it, i will do the migration again, it takes arround 40 minutes and
i will try to correct the short_term and see if it get fixed.
If not, then ill do start with adding the new cost TOTAL entity what i created yesterday, and see if it calculates right.
If that does, i will use your code to import the old data into the today created one.
Because a total entity should behave like a total, and no calculation is done in the EnergyDB… so it should work normal, but what i dont know is if i can import the data from the (entity containing a fixed price) to a total entity… thats the question.
I opened a case with HA now but it is too hard for me to create a replication of it, asking for insight in how this works which may then explain the mismatches…still, this seems very much a bug but we need to know the cause to tackle it
Well, with my issue i can replicate the issue, by just using the migration script.
This only causes that the cost sensor getting messed up, while the rest works perfect with no issue…