Include (history) statistics in notify message

Dear Home Assistant community, I have a use case I did not find a solution myself crawling through the archives of the internet.

I am collecting power consumption from a Shelly socket which provides the overall consumption as a summary. The example use case is a dishwasher.

Based on the changes in the overall consumption, the history statistics plugin is able to display the daily consumption in a nice way, see attached snapshot.

My question is now, is it possible to get a calculated summary for each iteration of the device.

a) I haven’t found a way to access the values used to present the history statistics - based on the datetime of the iteration it would be possible to calculate the difference which is the actual consumption.

b) Another way would be to copy the current overall consumption to a dummy (helper) entity, when the device iteration is started. The the iteration is finished, this overall consumption at that time could be subtracted from the initial value so we have the difference which is the actual consumption.

Happy to get some feedback on this use case and maybe some possible solution ideas.

1 Like

Hi,

I have also seeked a lot to get the data of the power consumption of one device to use it in a push message. I think I have now found a good solution which collects the running time, the power consumption of one iteration and notifies when one procedure is done.

I used two automations (begin and end) and a helper to store the initial value.

Start:

alias: Waschmaschine aktiviert
description: ""
trigger:
  - type: power
    platform: device
    device_id: 7a493b1a4de15d250203ba0f9a60c429
    entity_id: sensor.shellyplug_s_f17c9c_power
    domain: sensor
    above: 20
    below: 2200
    for:
      hours: 0
      minutes: 0
      seconds: 10
condition:
  - condition: state
    entity_id: input_boolean.waschmaschine
    state: "off"
action:
  - service: input_boolean.turn_on
    target:
      entity_id:
        - input_boolean.waschmaschine
    data: {}
  - service: input_number.set_value
    data_template:
      entity_id: input_number.start_energy
      value: "{{ states('sensor.shellyplug_s_f17c9c_energy') }}"
    enabled: false
  - service: input_number.set_value
    data:
      value: "{{ states('sensor.shellyplug_s_f17c9c_energy') }}"
    target:
      entity_id: input_number.start_energy
  - service: notify.pushover
    data:
      message: Waschmaschine wurde gestartet 🧦 πŸ‘•
      title: Home Assistant
mode: single

End:

alias: Waschmaschine fertig
description: ""
trigger:
  - type: power
    platform: device
    device_id: 7a493b1a4de15d250203ba0f9a60c429
    entity_id: sensor.shellyplug_s_f17c9c_power
    domain: sensor
    above: 1.5
    below: 9
    for:
      hours: 0
      minutes: 0
      seconds: 30
condition:
  - condition: state
    entity_id: input_boolean.waschmaschine
    state: "on"
action:
  - service: notify.pushover
    data:
      message: >-
        Waschmaschine ist fertig πŸ‘•πŸ‘–{{"\n"}}Verbrauch: {{
        (states('sensor.shellyplug_s_f17c9c_energy')|float -
        states('input_number.start_energy')|float)|round(4)}} kWh
        ⚑{{"\n"}}Laufzeit: {{ (as_timestamp(now()) -
        as_timestamp(states.input_boolean.waschmaschine.last_changed |
        default(0)) | int ) | timestamp_custom("%H:%M", false)}} ⏳
      title: Home Assistant
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.waschmaschine
    data: {}
mode: single

Helper:

Helper to store the beginning value:

I hope I did not got you wrong and this can help you solve the issue :slight_smile: