athom-tech / esp32-configs

ESP32 configuration for athom device
35 stars 17 forks source link

Energy Meter - No Button to Reset Energy Readings #21

Closed Roving-Ronin closed 2 months ago

Roving-Ronin commented 2 months ago

@tarontop @athom-tech

Could you PLEASE add in a button that allows resetting ALL the Energy sensors back to 0 ? All the usual methods I'm used to fail to work with the logs showing them reset, and then a second later the 'Energy_#_Internal' sensors then push their data back into the energy senors and restore the previous data that was wiped from them.

Try adding this and see for yourself.

api:
  # Define service that calls the 'button:' defined below to reset the Gas Meter - Current Reading'
  services:
    - service: reset_total_energy
      then:
        - button.press:
            id: button_reset_energy_reading

button:
  #  Reset the total energy entity (Gas - Current Reading)
  - platform: template
    name: 'Energy - Reset Readings'
    entity_category: config
    id: button_reset_energy_reading
    on_press:
      - lambda: |-
          id(Energy_1).publish_state(0.0);
          id(Energy_2).publish_state(0.0);
          id(Energy_3).publish_state(0.0);
          id(Energy_4).publish_state(0.0);
          id(Energy_5).publish_state(0.0);
          id(Energy_6).publish_state(0.0);
          id(Energy_sum).publish_state(0.0);

          id(id_Energy_1_persist) = 0.0;
          id(id_Energy_2_persist) = 0.0;
          id(id_Energy_3_persist) = 0.0;
          id(id_Energy_4_persist) = 0.0;
          id(id_Energy_5_persist) = 0.0;
          id(id_Energy_6_persist) = 0.0;

          id(id_Energy_1_lastvalue) = 0.0;
          id(id_Energy_2_lastvalue) = 0.0;
          id(id_Energy_3_lastvalue) = 0.0;
          id(id_Energy_4_lastvalue) = 0.0;
          id(id_Energy_5_lastvalue) = 0.0;
          id(id_Energy_6_lastvalue) = 0.0;

          id(id_Energy_sum_persist) = 0.0;
          id(id_Energy_sum_lastvalue) = 0.0;

LOGS:


READINGS AFTER BOOT / REFLASH:
================================
[22:25:42][D][sensor:094]: 'Temperature': Sending state 25.04237 °C with 0 decimals of accuracy
[22:25:42][D][sensor:094]: 'Current_1': Sending state 9.00675 A with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Power_1': Sending state 2003.90649 W with 0 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_1_Internal': Sending state 103.35679 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_1': Sending state 103.35679 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Current_2': Sending state 6.41211 A with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Power_2': Sending state 362.22397 W with 0 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_2_Internal': Sending state 14.21826 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_2': Sending state 14.21826 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Current_3': Sending state 2.07069 A with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Power_3': Sending state 451.14362 W with 0 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_3_Internal': Sending state 35.27080 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_3': Sending state 35.27080 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Current_4': Sending state 1.03488 A with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Power_4': Sending state 211.62866 W with 0 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_4_Internal': Sending state 17.24920 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_4': Sending state 17.24920 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Current_5': Sending state 0.86475 A with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Power_5': Sending state 181.75717 W with 0 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_5_Internal': Sending state 13.82370 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_5': Sending state 13.82370 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Current_6': Sending state 0.90368 A with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Power_6': Sending state 115.25282 W with 0 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_6_Internal': Sending state 8.87571 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Energy_6': Sending state 8.87571 kWh with 3 decimals of accuracy
[22:25:42][D][sensor:094]: 'Frequency': Sending state 49.94955 Hz with 0 decimals of accuracy
[22:25:42][D][sensor:094]: 'Voltage': Sending state 235.05020 V with 1 decimals of accuracy
[22:25:42][D][sensor:094]: 'Total_Energy': Sending state 192.79268 kWh with 3 decimals of accuracy

RESET PRESSED:
================================
[22:25:44][D][button:010]: 'Energy - Reset Readings' Pressed.

ENERGY SENSORS RESET TO ZERO:
================================
[22:25:44][D][sensor:094]: 'Energy_1_Internal': Sending state 0.00000 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_1': Sending state 0.01270 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_2_Internal': Sending state 0.00000 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_2': Sending state 0.00223 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_3_Internal': Sending state 0.00000 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_3': Sending state 0.00290 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_4_Internal': Sending state 0.00000 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_4': Sending state 0.00134 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_5_Internal': Sending state 0.00000 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_5': Sending state 0.00134 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_6_Internal': Sending state 0.00000 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Energy_6': Sending state 0.00067 kWh with 3 decimals of accuracy
[22:25:44][D][sensor:094]: 'Total_Energy': Sending state 0.00000 kWh with 3 decimals of accuracy

[22:25:47][D][sensor:094]: 'Grid Power': Sending state 2817.27393 W with 1 decimals of accuracy
[22:25:47][D][sensor:094]: 'Temperature': Sending state 24.83051 °C with 0 decimals of accuracy
[22:25:47][D][sensor:094]: 'Current_1': Sending state 9.00470 A with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Power_1': Sending state 2003.11829 W with 0 decimals of accuracy

ENERGY_#_INTERNAL / TOTAL_ENERGY - RESTORE OLD VALUES:
================================
[22:25:47][D][sensor:094]: 'Energy_1_Internal': Sending state 103.35969 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_1': Sending state 103.35969 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Current_2': Sending state 6.40553 A with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Power_2': Sending state 362.14221 W with 0 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_2_Internal': Sending state 14.21893 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_2': Sending state 14.21893 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Current_3': Sending state 2.12527 A with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Power_3': Sending state 459.00854 W with 0 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_3_Internal': Sending state 35.27147 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_3': Sending state 35.27147 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Current_4': Sending state 1.09878 A with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Power_4': Sending state 219.33592 W with 0 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_4_Internal': Sending state 17.24965 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_4': Sending state 17.24965 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Current_5': Sending state 0.86500 A with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Power_5': Sending state 180.47847 W with 0 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_5_Internal': Sending state 13.82393 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_5': Sending state 13.82393 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Current_6': Sending state 0.90236 A with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Power_6': Sending state 115.14188 W with 0 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_6_Internal': Sending state 8.87594 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Energy_6': Sending state 8.87594 kWh with 3 decimals of accuracy
[22:25:47][D][sensor:094]: 'Frequency': Sending state 49.93783 Hz with 0 decimals of accuracy
[22:25:47][D][sensor:094]: 'Voltage': Sending state 233.17500 V with 1 decimals of accuracy
[22:25:47][D][sensor:094]: 'Total_Energy': Sending state 192.79625 kWh with 3 decimals of accuracy

Edit: Just even tried chaing the 'persist' Globals to 'restore_value: no'. Flashed it, hit the reset and the value STILL get restored.

tarontop commented 2 months ago

You can try this first. I think it is not enough. You should also reset the energy on the metering chip register.

button:
  - platform: template
    name: Reset_Energy
    entity_category: config
    on_press:
      then:
        - globals.set:
            id: id_Energy_1_persist
            value: '0.0'
        - globals.set:
            id: id_Energy_2_persist
            value: '0.0'
        - globals.set:
            id: id_Energy_3_persist
            value: '0.0'
        - globals.set:
            id: id_Energy_4_persist
            value: '0.0'
        - globals.set:
            id: id_Energy_5_persist
            value: '0.0'
        - globals.set:
            id: id_Energy_6_persist
            value: '0.0'
        - globals.set:
            id: id_Energy_sum_persist
            value: '0.0'
Roving-Ronin commented 2 months ago

Where / how can one access those registers 'on the chip'?

Looking at your code, it appears to be the same operations as I've got (resetting the global), but just formatted a different way.

Roving-Ronin commented 2 months ago

Just got a moment to try the above code and whilst the log shows it triggered, it actually does nothing. Readings for Energy remain as they are (don't even momentarily change to zero and then back).

tarontop commented 2 months ago

https://github.com/athom-tech/esp32-configs/pull/22