home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.71k stars 30.83k forks source link

Energy Card not computing Gas Consumption Cost when Unit is in FT^3 #78675

Closed MisterTFM closed 2 years ago

MisterTFM commented 2 years ago

The problem

Upgraded HA to 2022.9.4, set an entity with current price (USD\ FT³), but Energy Card does not show calculated cost.

Accumulated Gas Use is correctly display in Energy Dashboard.

Gas Consumption Sensor has the following attributes: state_class: total_increasing unit_of_measurement: ft³ device_class: gas icon: mdi:fire friendly_name: Gas Energy from Utility Meter Cubic Feet

Entity with Current Price has the following attributes: unit_of_measurement: USD/ft³ device_class: monetary icon: mdi:fire friendly_name: Calculated Gas cu-ft Cost

ScreenHunter 376 ScreenHunter 377 ScreenHunter 378

What version of Home Assistant Core has the issue?

2022.9.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Energy Card

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

cbird527 commented 2 years ago

Hi, the gas cost has been working for me since 2022.9.1. One thing that I noticed was different between my cost entity and yours was that I have "unit_of_measurement: $/ft³" vs your "unit_of_measurement: USD/ft³". Not sure if it is the issue but might be worth trying if you haven't already.

image image

MisterTFM commented 2 years ago

I created an input_number with the same attributes as above, waiting a few hours to see if it works to compute gas cost.

Also noted when trying to use a static cost and entity cost, it still expects price per cubic meters:

ScreenHunter 382 ScreenHunter 384

MisterTFM commented 2 years ago

After several hours, still no Gas Consumption cost being displayed:

image

emontnemery commented 2 years ago

@MisterTFM Please share the state + attributes of the following entities from the states developer tool:

emontnemery commented 2 years ago

@MisterTFM please share a log with the settings below which shows what happens when there are at least 3 updates of the gas consumption sensor.

logger:                      
  default: warning           
  logs:                      
    homeassistant.core: debug
MisterTFM commented 2 years ago

@MisterTFM Please share the state + attributes of the following entities from the states developer tool:

  • The gas sensor
  • The price entity
  • The auto generated cost sensor

Gas Sensor: ScreenHunter 386

Price Entity: ScreenHunter 387

Not sure what you mean by "auto generated cost sensor" ??

emontnemery commented 2 years ago

Also noted when trying to use a static cost and entity cost, it still expects price per cubic meters

Thanks for bringing that up, it's fixed in https://github.com/home-assistant/frontend/pull/13824

Not sure what you mean by "auto generated cost sensor"

When you enable cost calculation for gas or electricity, that's managed by a sensor which is automatically created by Home Assistant. That sensor should get the entity_id of your gas consumption sensor, suffixed with _cost, so sensor.gas_energy_from_utility_meter_cu_feet_cost.

MisterTFM commented 2 years ago

sensor.gas_energy_from_utility_meter_cu_feet_cost

There is no entity with "_cost" when viewing in Developers Tools: ScreenHunter 388

I have the Energy card configured as:

ScreenHunter 389

Gas Cost entity:

ScreenHunter 390

MisterTFM commented 2 years ago

@MisterTFM please share a log with the settings below which shows what happens when there are at least 3 updates of the gas consumption sensor.


logger:                      

  default: warning           

  logs:                      

    homeassistant.core: debug

Haven't seen any references or Errors when viewing logs in regards to gas consumption.

emontnemery commented 2 years ago

Haven't seen any references or Errors when viewing logs

Right, so please enable debug log as requested and share a log which shows what happens when your gas sensor is updated

You can contact me on discord, emontnemery#6618, if you don't want to share the log here.

There is no entity with "_cost" when viewing in Developers Tools

Did you search only exactly for sensor.gas_energy_from_utility_meter_cu_feet_cost or did you try something more fuzzy; maybe just search for "energy" and for "cost".

Do you have any custom components installed? If you do, could you please disable them just to make sure they're not interfering?

Please also share the file .storage/energy

MisterTFM commented 2 years ago

Haven't seen any references or Errors when viewing logs

Right, so please enable debug log as requested and share a log which shows what happens when your gas sensor is updated

You can contact me on discord, emontnemery#6618, if you don't want to share the log here.

This log was cleared when I rebooted this morning around 9:00 am: Home Assistant Core - Log - 9-21-2022.txt

This graph from the energy card showing Gas Consumption and when it occurs: ScreenHunter 392

MisterTFM commented 2 years ago

There is no entity with "_cost" when viewing in Developers Tools

Did you search only exactly for sensor.gas_energy_from_utility_meter_cu_feet_cost or did you try something more fuzzy; maybe just search for "energy" and for "cost".

I searched on "energy", "cost" and "gas" and combinations, and see no auto generated entities in reference to "sensor.gas_energy_from_utility_meter_cu_feet_cost"

MisterTFM commented 2 years ago

Please also share the file .storage/energy energy-9-21-2022.txt

MisterTFM commented 2 years ago

Do you have any custom components installed? If you do, could you please disable them just to make sure they're not interfering?

How can I disable any "custom_components" ?

emontnemery commented 2 years ago

Thanks for sharing .storage/energy, I think the mystery is solved now and a workaround is to manually edit it.

In the file, there's this section:

      {
        "type": "gas",
        "stat_energy_from": "sensor.gas_energy_from_utility_meter_cu_feet",
        "stat_cost": null,
        "entity_energy_from": null,
        "entity_energy_price": "input_number.gas_cost",
        "number_energy_price": null
      }

Cost tracking should work if you change it like this:

      {
        "type": "gas",
        "stat_energy_from": "sensor.gas_energy_from_utility_meter_cu_feet",
        "stat_cost": null,
        "entity_energy_from": "sensor.gas_energy_from_utility_meter_cu_feet",
        "entity_energy_price": "input_number.gas_cost",
        "number_energy_price": null
      }

After the edit, restart Home Assistant.

Note: Please be careful when editing the file, make a backup copy of it before editing.

emontnemery commented 2 years ago

Instead of manually editing the file, try removing the gas consumption item: image

Then add it again, with the same settings. The .storage/energy should now be as expected and cost tracking should work.

MisterTFM commented 2 years ago

I first tried deleting the gas consumption entity, then added it again and entered a static price, then rebooted HA:

{ "type": "gas", "stat_energy_from": "sensor.gas_energy_from_utility_meter_cu_feet", "stat_cost": null, "entity_energy_from": "sensor.gas_energy_from_utility_meter_cu_feet", "entity_energy_price": null, "number_energy_price": 0.025 }

ScreenHunter 393

Gas Consumption Cost is now calculated correctly !!!!!!!!!!!!!!!!!!!

NEXT, I will try using an entity that contains the Gas Cost:

  {
    "type": "gas",
    "stat_energy_from": "sensor.gas_energy_from_utility_meter_cu_feet",
    "stat_cost": null,
    "entity_energy_from": "sensor.gas_energy_from_utility_meter_cu_feet",
    "entity_energy_price": "sensor.calculated_gas_cu_ft_cost",
    "number_energy_price": null
  }

Will have to wait an hour before gas consumption is registered again on graph, will report back findings. My goal is to use a entity that has a calculated cost from my paper gas bill.

###################################################

So, any explanation as to why the energy.txt file format was wrong, and how will 2022.9.X updates correct this in the future?

MisterTFM commented 2 years ago

Gas Consumption cost being calculated now using an "entity with current price". ScreenHunter 394

ScreenHunter 395

MisterTFM commented 2 years ago

@emontnemery Thanks for all your help !!!!!!!!!!!!