zeronounours / HA-custom-component-energy-meter

Provides extended features on top of utility-meter to track costs for each tariff as well as total costs
MIT License
19 stars 2 forks source link

Utility Meter: Reset - Doesn't work with Energy Meter #52

Closed Roving-Ronin closed 8 months ago

Roving-Ronin commented 1 year ago

Hi @zeronounours / Gauthier,

Could you please advise upon this issue. I've just reached by Gas 'end of quarter' meter reading date and usually when using the utility_meter option an automation would kick in and call the 'Utility Meter: Reset' service that would then target the sensor.gas_consumed_quarterly_mj entity to reset it back to 0 (mj) for the quarter.

Just checking now and found whilst the automation has triggered, the entity hasn't reset to zero. Editing the automation and checking the target, as it also needs the sensor.gas_consumed_quarterly_mj_cost entity added to the automation to reset the quarterly cost to zero and discovered that the 'Utility Meter: Reset' appears to ONLY allow selecting a 'utility meter' sensor, with the 'energy_meter' sensors not be an option to see and select.

I've also tried manually adding an automation, in case it was just the GUI editor not allowing us to see/select energy_meter sensors:

alias: Gas - Quarterly Meter Reset
description: Reset the gas readings totals when meter reading taken
trigger:
  - platform: calendar
    event: start
    offset: "8:0:0"
    entity_id: calendar.gas_meter_reset
condition: []
action:
  - service: utility_meter.reset
    data: {}
    target:
      entity_id:
        - sensor.gas_consumed_quarterly_mj
        - sensor.gas_consumed_quarterly_mj_cost
mode: single

and confirm even trying this manually is not working. Could you please advise if there is some work around or way you reset the energy_meter and associated cost sensors?

Out of interest, has there been any update on getting the functionality of the energy meter added into Home Assistant (i.e. adding to or replacing utility_meter), as I would think if this was done, then the 'Utility Meter: Reset' service (or a new 'Energy Meter: Reset' service) would be integral to HA.


UPDATE:

Still probably worth investigating getting the 'Utility Meter: Reset' updated to also work with Energy Meter (or a 'Energy Meter: Reset' added to HA), but to answer my own question re a temporary work around, I found that the utility_meter.calibrate service recognises the Energy Meter sensors and can be used to set them to zero.

Here is what I setup an an automation, that checks a calendar I've setup called 'Gas Meter Reset' and in which I define an entry on the approximate (buggers here can go anywhere from mid 80 to low 90 days in a quarter between readings) day and time when the meter reading guy checks the meter. Based upon that as the trigger, it then calls the utility_meter.calibrate service and sets it to zero (or the number defined in the automation).

Note: Users who have a monthly or quarterly meter reading that falls with 28 days of the start of the month or quarter (i.e. within 28 days of 1 Jan / 1 Apr / 1 July / 1 Oct) will not have this problem, as you can simply use the following, if you meter reading is half way through the quarter, then you'll have this issue also.

cycle: monthly
offset: 28

or

cycle: quarterly
offset: 28

The 'work around' automation:

alias: Gas - Energy Meter Reset
description: Use the utility_meter.calibrate service to set the gas MJ and Cost to ZERO.
trigger:
  - platform: calendar
    event: start
    offset: "8:0:0"
    entity_id: calendar.gas_meter_reset
condition: []
action:
  - service: utility_meter.calibrate
    data:
      value: "0"
    target:
      entity_id:
        - sensor.gas_consumed_quarterly_mj
        - sensor.gas_consumed_quarterly_mj_cost
mode: single

Thanks !

zeronounours commented 11 months ago

Are you sure the entity select.gas_consumed_quarterly_mj_cost exist? Only one select entity is created for an energy meter.

For instance:

energy_meter:
  daily_energy:
    source: sensor.energy
    name: Daily Energy
    cycle: daily
    price_entity: sensor.current_energy_price
    tariffs:
      - peak
      - offpeak

This configuration creates exactly 6 entities:

To reset all four utility meter sensors, the target entity_id of utility_meter.reset is only select.daily_energy. Both on my personal HA instance and on the test server, I can select with the GUI the select entity created by energy_meter

Roving-Ronin commented 11 months ago

@zeronounours I've been scratching my head on this one also, then worked out it was a typo on the OP's yaml code. The entity_id's called are 'sensor.gas_consumed_quarterly_mj' and 'sensor.gas_consumed_quarterly_mj_cost' , no SELECT.gas.xxx are involved.

OP has been revised to fix this. The OP still stands though that 'service: utility_meter.reset' doesn't work and you need to instead call 'service: utility_meter.calibrate' to reset sensors value to zero (as in the case of a quarterly meter here).

This is as per the 'UPDATE' section of the OP.

Gas FYI my gas.yaml I use is: https://github.com/Roving-Ronin/Home-Assistant/blob/main/packages/gas.yaml


If of interest, I'm also using Energy Meter for these two (I have 3 different feeds for power data, these and IoTaWatt):

Huawei Solar (using the WLCRS Huawei Integration - https://github.com/wlcrs/huawei_solar). Yaml: https://github.com/Roving-Ronin/Home-Assistant/blob/main/packages/huawei_solar_electricity_costs.yaml

Solar Analytics (using https://github.com/PeterH24x7/-Solar-Analytics-integration-for-Home-Assistant-Energy-monitoring to pull data from their cloud portal that records my Grid / Solar data). Yaml: https://github.com/Roving-Ronin/Home-Assistant/blob/main/packages/solar_analytics_electricity_costs_uses_prices_from_inputs.yaml

Water Pending using Energy Meter for the Water (both utility water and 10,000L rain water tank+pump), as waiting to get cabling to allow deployment of reed switch to utility meter and water pressure sensor into the rainwater tank. I still have to double check it all, but the yaml for that should be this: https://github.com/Roving-Ronin/Home-Assistant/blob/main/packages/water.yaml

zeronounours commented 8 months ago

For information, I've investigated, and its quite a normal behavior. Actually, the builtin utility_meter has this behavior : it only create select entity when using tariff (what you do not for your energy_meter) and the reset service can only be used through this select entity.

I'll update the behavior of the energy_meter to create a select entity whenever more than 1 sensor is to be created.

zeronounours commented 8 months ago

Actually, after trying to implement it, it completely breaks the utility_meter part. It's seems to be no way do to it properly.

The easiest work-around I've found is to create the energy_meter with a single tariff. This way, you'll get the select and will be able run the reset service.

As these are no solutions apart reimplementing utility_meter, I'm also closing this issue