So last post did not succeed too with solution tried…
This is the solution I used, after some days feedback
I use the “variable” integration, with this code in configuration.yaml :
variable:
water_history_ecs1:
value: 'none'
restore: true
Then, an automation fills the variable attributes every 5 seconds, shifting values from newer to older, thanks to an automation (automation.yaml) :
###################################################
- alias: update water temp history
initial_state: 'on'
trigger:
- platform: time_pattern
seconds: '/5'
action:
- service: variable.set_variable
data:
variable: water_history_ecs1
attributes:
history_24: "{{ state_attr('variable.water_history_ecs1', 'history_23') }}"
history_23: "{{ state_attr('variable.water_history_ecs1', 'history_22') }}"
history_22: "{{ state_attr('variable.water_history_ecs1', 'history_21') }}"
history_21: "{{ state_attr('variable.water_history_ecs1', 'history_20') }}"
history_20: "{{ state_attr('variable.water_history_ecs1', 'history_19') }}"
history_19: "{{ state_attr('variable.water_history_ecs1', 'history_18') }}"
history_18: "{{ state_attr('variable.water_history_ecs1', 'history_17') }}"
history_17: "{{ state_attr('variable.water_history_ecs1', 'history_16') }}"
history_16: "{{ state_attr('variable.water_history_ecs1', 'history_15') }}"
history_15: "{{ state_attr('variable.water_history_ecs1', 'history_14') }}"
history_14: "{{ state_attr('variable.water_history_ecs1', 'history_13') }}"
history_13: "{{ state_attr('variable.water_history_ecs1', 'history_12') }}"
history_12: "{{ state_attr('variable.water_history_ecs1', 'history_11') }}"
history_11: "{{ state_attr('variable.water_history_ecs1', 'history_10') }}"
history_10: "{{ state_attr('variable.water_history_ecs1', 'history_9') }}"
history_9: "{{ state_attr('variable.water_history_ecs1', 'history_8') }}"
history_8: "{{ state_attr('variable.water_history_ecs1', 'history_7') }}"
history_7: "{{ state_attr('variable.water_history_ecs1', 'history_6') }}"
history_6: "{{ state_attr('variable.water_history_ecs1', 'history_5') }}"
history_5: "{{ state_attr('variable.water_history_ecs1', 'history_4') }}"
history_4: "{{ state_attr('variable.water_history_ecs1', 'history_3') }}"
history_3: "{{ state_attr('variable.water_history_ecs1', 'history_2') }}"
history_2: "{{ state_attr('variable.water_history_ecs1', 'history_1') }}"
history_1: "{{ states('variable.water_history_ecs1') }}"
- service: variable.set_variable
data:
variable: water_history_ecs1
value: "{{ states('sensor.water_ecs1') }}"
The last part is the shower detection, based on more than 5liters hot water detection over the 2 min period (24*5sec). The initial shower index is backup at the beginning at the shower. When end of shower is detected, the ecs.efs variable attributes are updated to get the consumed water :
- alias: "update shower state 1 on"
initial_state: 'on'
trigger:
- platform: time_pattern
seconds: '/5'
condition:
condition: and
conditions:
- condition: state
entity_id: variable.water_shower1
state: "off"
- condition: template
value_template: "{{ (states('sensor.water_efs1')|int - state_attr('variable.water_history_efs1', 'history_24')|int) > 5 }}"
- condition: template
value_template: "{{ (states('sensor.water_ecs1')|int - state_attr('variable.water_history_ecs1', 'history_24')|int) > 5 }}"
action:
- service: variable.set_variable
data:
variable: water_shower1
attributes:
efs: "{{ state_attr('variable.water_history_efs1', 'history_24') }}"
ecs: "{{ state_attr('variable.water_history_ecs1', 'history_24') }}"
- service: variable.set_variable
data:
variable: water_shower1
value: "on"
###################################################""
- alias: "update shower state 1 off"
initial_state: 'on'
trigger:
- platform: time_pattern
seconds: '/5'
condition:
condition: and
conditions:
- condition: state
entity_id: variable.water_shower1
state: "on"
- condition: template
value_template: "{{ (states('sensor.water_efs1')|int - state_attr('variable.water_history_efs1', 'history_24')|int) <= 5 }}"
- condition: template
value_template: "{{ (states('sensor.water_ecs1')|int - state_attr('variable.water_history_ecs1', 'history_24')|int) <= 5 }}"
action:
- service: variable.set_variable
data:
variable: water_shower1
attributes:
efs: "{{ states('sensor.water_efs1')|int - state_attr('variable.water_shower1', 'efs')|int }}"
ecs: "{{ states('sensor.water_ecs1')|int - state_attr('variable.water_shower1', 'ecs')|int }}"
- service: variable.set_variable
data:
variable: water_shower1
value: "off"
Finally it is notified to the notification group, with 3 group of the following code to have a color notification change depending on the amount of water used during the shower:
- alias: "Notification fin douche maison"
trigger:
- platform: state
entity_id: variable.water_shower1
to: "off"
condition:
condition: and
conditions:
- condition: template
value_template: "{{ (state_attr('variable.water_shower1', 'ecs')|int) >= 12 }}"
- condition: template
value_template: "{{ (state_attr('variable.water_shower1', 'ecs')|int) < 24 }}"
action:
- service: notify.ALL_DEVICES
data:
title: "Bilan douche : moyen"
message: "Douche maison terminée. {{ state_attr('variable.water_shower1', 'ecs') }} L eau chaude et {{ state_attr('variable.water_shower1', 'efs') }} L eau froide"
data:
color: "#F56D2D"
My code is probably complicated, since I’m beginner.
All comments are welcomed to improve the way I did with home assistant.
Hope helping other