OK this finally works correctly.
It include, calibration, choice of calibration time, instructions by notification via HA app, notification if pump is outline
The code is :
###################################################################################
# Customize Gobal #
###################################################################################
homeassistant:
customize_glob:
"input_boolean.r2d*":
icon: mdi:calendar-clock
"input_boolean.r1d*":
icon: mdi:calendar-clock
"sensor.reefdoser*_pump*_daily_runtime":
icon: mdi:history
"sensor.reefdoser*_pump*_dosage_split":
icon: mdi:beaker
"sensor.reefdoser*_pump*_time_split":
icon: mdi:update
"input_number.reefdoser*_pump*_daily_mins":
icon: mdi:clock
"input_select.reefdoser1_pump*_daily_freq":
icon: mdi:progress-clock
#switch:
# - platform: mqtt
# name: "Reefdoser1 Pump1"
# state_topic: "homeassistant/stat/Reefdoser1/POWER1"
# command_topic: "homeassistant/cmnd/Reefdoser1/POWER1"
# qos: 1
# payload_on: "ON"
# payload_off: "OFF"
# retain: True
###################################################################################
# input_boolean #
###################################################################################
input_boolean:
r1p1:
name: "Kh (R1P1) : Mode auto"
icon: mdi:arrow-decision-auto-outline
# Pump calibration
calibr1p1on:
name: "Mode calibration"
icon: mdi:tape-measure
calibr1p1start:
name: "Lancer la calibration"
icon: mdi:clock-start
###################################################################################
# sensor #
###################################################################################
sensor:
- platform: template
sensors:
# Reefdosers ONLINE status sensors
reefdoser1:
value_template: '{% if is_state("device_tracker.reefdoser1", "home") %}Online{% else %}offline{% endif %}'
friendly_name: 'État Reefdoser1'
icon_template: >-
{% if is_state('device_tracker.reefdoser1', 'home') %}
mdi:power-plug
{% else %}
mdi:power-plug-off
{% endif %}
# Reefdoser1 Runtime sensors
reefdoser1_pump1_daily_runtime:
value_template: "{{ (float(states('input_number.reefdoser1_pump1_daily_dosage')) / ((float(states('input_number.reefdoser1_pump1_calibration_dosage')))/(float(states('input_number.reefdoser1_pump1_calibration_time'))))) | round(2) }}"
friendly_name: 'R1P1 Durée ajout quotidien'
unit_of_measurement: 'sec'
reefdoser1_pump1_dosage_split:
value_template: "{{ (float( states('input_number.reefdoser1_pump1_daily_dosage')) / float(states('input_select.reefdoser1_pump1_daily_freq'))) | round(2) }} "
friendly_name: 'R1P1 Qté ajout fractioné'
unit_of_measurement: 'ml'
reefdoser1_pump1_time_split:
value_template: "{{ (float(states('sensor.reefdoser1_pump1_daily_runtime')) / float(states('input_select.reefdoser1_pump1_daily_freq'))) | round(2) }}"
friendly_name: 'R1P1 Durée ajout fractioné'
unit_of_measurement: 'sec'
###################################################################################
# device_tracker: #
###################################################################################
device_tracker:
- platform: ping
hosts:
reefdoser1: 192.168.1.49
###################################################################################
# input_numbers #
###################################################################################
input_number:
reefdoser1_pump1_daily_dosage:
name: Ajouts quotidiens
min: 1
max: 500
step: 1
unit_of_measurement: ml
icon: mdi:beaker
# initial: 30
reefdoser1_pump1_daily_mins:
name: Décal. min. /H. réf.
min: 00
max: 59
step: 1
mode: box
# initial: 00
unit_of_measurement: mins
reefdoser1_pump1_calibration_dosage:
name: Résultat calibration en ml
min: 1
max: 100
step: 0.5
unit_of_measurement: ml
mode: box
icon: mdi:flask-outline
# initial: 30
unit_of_measurement: mins
reefdoser1_pump1_calibration_time:
name: Durée calibration en sec
min: 1
max: 60
step: 1
unit_of_measurement: sec
icon: mdi:timer-sand
# initial: 30
# initial: 30
###################################################################################
# input_select #
###################################################################################
input_select:
reefdoser1_pump1_daily_freq:
name: Nbr d'ajouts quotidiens
options:
- "1"
- "2"
- "3"
- "4"
- "6"
- "8"
- "12"
- "24"
icon: mdi:target
###################################################################################
# automations #
###################################################################################
automation:
# Reefdoser1 Section
# R1P1 Subsection Automations
- alias: Reefdoser1 Pump1 at the specified frequency
trigger:
- platform: time_pattern
hours: "/1"
seconds: "00"
condition:
condition: and
conditions:
- condition: template
value_template: "{{ now().hour % ( 24 / float(states('input_select.reefdoser1_pump1_daily_freq')))|int == 0 }}"
- condition: template
value_template: "{% if now().minute | int == states.input_number.reefdoser1_pump1_daily_mins.state | int %}true{% endif %}"
- condition: state
entity_id: sensor.reefdoser1
state: 'Online'
- condition: state
entity_id: input_boolean.r1p1
state: 'on'
action:
- service: switch.turn_on
entity_id: switch.pompe_doseuse_kh
- delay: '00:00:{{ states.sensor.reefdoser1_pump1_time_split.state | int }}'
- service: switch.turn_off
entity_id: switch.pompe_doseuse_kh
# Notify offline
- alias: Notify reefdoser1 offline
trigger:
platform: state
entity_id: device_tracker.reefdoser1
to: 'not_home'
action:
service: notify.mobile_app_iphone_x_raphael
data:
title: "Reefdoser1 offline"
message: "les pompes reefdoser1 sont hors ligne et non fonctinelles "
data:
push:
thread-id: "activité_reef-group"
# Calibration start
- alias: Notify ready calibration R1P1
trigger:
platform: state
entity_id: input_boolean.Calibr1p1on
to: 'on'
action:
service: notify.mobile_app_iphone_x_raphael
data:
title: "Calibration R1P1 - Kh"
message: "Vérifiez le tuyau ; plein et sans bulles d'air. Choisisez la durée calibration. Placez le recipient doseur en sortie. Enclanchez calibration start"
data:
push:
thread-id: "activité_reef-group"
# Calibration view reset with auto statut
# Allow to mask calibration card in lovelace if off
- alias: Reset calibration view
trigger:
platform: state
entity_id: input_boolean.r1p1
to: 'off'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.calibr1p1on
# Calibration view reset with auto statut
# Allow to mask calibration card in lovelace if off
- alias: Calibration pump
trigger:
platform: state
entity_id: input_boolean.calibr1p1start
to: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: sensor.reefdoser1
state: 'Online'
- condition: state
entity_id: input_boolean.calibr1p1on
state: 'on'
action:
- service: switch.turn_on
entity_id: switch.pompe_doseuse_kh
- delay: '00:00:{{ states.input_number.reefdoser1_pump1_calibration_time.state | int }}'
- service: switch.turn_off
entity_id: switch.pompe_doseuse_kh
- service: input_boolean.turn_off
entity_id: input_boolean.calibr1p1start
- service: notify.mobile_app_iphone_x_raphael
data:
title: "Fin calibration"
message: "Reporter la qté delivrée par la pompe"
data:
push:
thread-id: "activité_reef-group"
###################################################################################
# group #
###################################################################################
group:
aqua_view:
view: yes
name: Pompes Doseuses
entities:
- group.r1p1
r1p1:
name: R1P1 - Kh
control: hidden
entities:
- switch.pompe_doseuse_kh
- input_boolean.r1p1
- input_number.reefdoser1_pump1_daily_mins
- input_select.reefdoser1_pump1_daily_freq
- input_number.reefdoser1_pump1_daily_dosage
- sensor.reefdoser1_pump1_dosage_split
- sensor.reefdoser1_pump1_daily_runtime
- sensor.reefdoser1_pump1_time_split
###################################################################################
# Dynamic Card in lovelace #
###################################################################################
#cards:
# - card:
# entities:
# - entity: switch.pompe_doseuse_kh
# - entity: input_boolean.r1p1
# - entity: input_boolean.calibr1p1on
# show_header_toggle: false
# title: Kh - R1P1
# type: entities
# conditions:
# - entity: input_boolean.r1p1
# state: 'off'
# title: Réveil - Aube
# type: conditional
# - card:
# entities:
# - entity: switch.pompe_doseuse_kh
# - entity: input_boolean.r1p1
# - entity: input_number.reefdoser1_pump1_daily_mins
# - entity: input_select.reefdoser1_pump1_daily_freq
# - entity: input_number.reefdoser1_pump1_daily_dosage
# - entity: sensor.reefdoser1_pump1_dosage_split
# - entity: sensor.reefdoser1_pump1_daily_runtime
# - entity: sensor.reefdoser1_pump1_time_split
# - entity: sensor.reefdoser1
# - entity: input_boolean.calibr1p1on
# show_header_toggle: false
# title: Kh - R1P1
# type: entities
# conditions:
# - entity: input_boolean.r1p1
# state: 'on'
# type: conditional
# - card:
# entities:
# - entity: input_number.reefdoser1_pump1_calibration_time
# - entity: input_boolean.calibr1p1start
# - entity: input_number.reefdoser1_pump1_calibration_dosage
# show_header_toggle: false
# title: Calibration Kh - R1P1
# type: entities
# conditions:
# - entity: input_boolean.calibr1p1on
# state: 'on'
# type: conditional
#type: vertical-stack
Final look when all is developed :