diff --git a/automations.yaml b/automations.yaml index 557ae7e..0f89537 100644 --- a/automations.yaml +++ b/automations.yaml @@ -93,11 +93,6 @@ description: '' use_blueprint: path: homeassistant/power-load-high.yaml -- id: '1740238584165' - alias: test1 - description: '' - use_blueprint: - path: homeassistant/test_macro.yaml - id: '1740247429602' alias: EVcharge-process description: Manage charge of 2 cars sequentially via 2 controlled plugs (requires @@ -110,3 +105,8 @@ use_entity1: input_boolean.evcharge_front_request use_entity2: input_boolean.evcharge_back_request start_button: input_button.evcharge_start +- id: '1740332596550' + alias: test-email + description: '' + use_blueprint: + path: homeassistant/test_macro.yaml diff --git a/blueprints/automation/homeassistant/evcharge-process.yaml b/blueprints/automation/homeassistant/evcharge-process.yaml index ccfbdc1..8513a21 100644 --- a/blueprints/automation/homeassistant/evcharge-process.yaml +++ b/blueprints/automation/homeassistant/evcharge-process.yaml @@ -78,10 +78,16 @@ variables: use_entity2_var: !input use_entity2 # here list of mobile APP to be notified - recipient_list: + recipient_list_notification: - notify.mobile_app_tiziano_iphone15pro - notify.mobile_app_emanuele_s24 + recipient_list_gmail: + title: "EVcharge Process" + target: + - "tiziano.trabattoni@outlook.com" + - "ema.trabattoni@gmail.com" + actions: - if: - or: @@ -93,17 +99,18 @@ actions: # value_template: "{{ false }}" # TEST ONLY then: - # charge already active, send message and terminate - repeat: - for_each: "{{ recipient_list }}" + # charge already active, send message email and terminate + sequence: + - repeat: + for_each: "{{ recipient_list_notification }}" + sequence: + - action: "{{ repeat.item }}" + metadata: {} + data: + message: >- + "EVcharge process is ALREADY RUNNING" + title: "EV Charge process ERROR" - sequence: - - action: "{{ repeat.item }}" - metadata: {} - data: - message: >- - "EVcharge process is ALREADY RUNNING" - title: EV Charge process ERROR else: sequence: - if: @@ -112,8 +119,7 @@ actions: then: # EVcharge entity_1 (eg front) charge is requested sequence: - repeat: # send message to all recipient-list members - for_each: "{{ recipient_list }}" - + for_each: "{{ recipient_list_notification }}" sequence: - action: "{{ repeat.item }}" metadata: {} @@ -121,9 +127,16 @@ actions: message: >- "EVcharge process on {{ evcharge_entity1_var }} has started" title: EV Charge process + - action: notify.tiziano_trabattoni_gmail_com + data: + title: "EVcharge process on {{ evcharge_entity1_var }} has started" + target: "{{ recipient_list_gmail['target'] }}" + message: >- + "EVcharge process on {{ evcharge_entity1_var }} has started" + # take energy counter before charging - variables: - energy1_before: "{{ states(evcharge_entity1_energy_var) | float }}" + energy1_before: "{{ states(evcharge_entity1_energy_var) | float | round(2) }}" # Start plug1 and wait until power measured is below input_number.evcharge_no_charge_threshold for 10 minutes = 600 seconds - action: switch.turn_on @@ -134,6 +147,7 @@ actions: - delay: 120 # - delay: 10 # TEST ONLY + # Wait for charging to complete - repeat: until: "{{ ( states(evcharge_entity1_power_var) | int ) < ( states('input_number.evcharge_no_charge_threshold') | int ) }}" # until: "{{ ( states('input_number.test_evcharge_front') | int) < (states('input_number.evcharge_no_charge_threshold') | int) }}" # TEST ONLY @@ -143,7 +157,7 @@ actions: # take energy counter after charging - variables: - energy1_after: "{{ states(evcharge_entity1_energy_var) | float }}" + energy1_after: "{{ states(evcharge_entity1_energy_var) | float | round(2) }}" # turn off evcharge_entity1 - action: switch.turn_off @@ -151,16 +165,22 @@ actions: # entity_id: switch.presa_smart_1 # TEST ONLY - repeat: # send message to all recipient-list members - for_each: "{{ recipient_list }}" - + for_each: "{{ recipient_list_notification }}" sequence: - action: "{{ repeat.item }}" metadata: {} data: message: >- - "EVcharge process on {{ evcharge_entity1_var }} has ended: {{ energy1_after - energy1_before }} kW/h charged" + "EVcharge process on {{ evcharge_entity1_var }} has ended: {{ ( energy1_after - energy1_before ) | round(2) }} kW/h charged" title: EV Charge process + - action: notify.tiziano_trabattoni_gmail_com + data: + title: "EVcharge process on {{ evcharge_entity1_var }} has ended: {{ ( energy1_after - energy1_before ) | round(2) }} kW/h charged" + target: "{{ recipient_list_gmail['target'] }}" + message: >- + "EVcharge process on {{ evcharge_entity1_var }} has ended: {{ ( energy1_after - energy1_before ) | round(2) }} kW/h charged" + # wait couple of minutes before starting charge on plug2 - delay: 120 # - delay: 10 # TEST ONLY @@ -171,8 +191,7 @@ actions: sequence: # then start plug2 and wait until power measured is below input_number.evcharge_no_charge_threshold for 10 minutes = 600 seconds - repeat: # send message to all recipient-list members - for_each: "{{ recipient_list }}" - + for_each: "{{ recipient_list_notification }}" sequence: - action: "{{ repeat.item }}" metadata: {} @@ -180,19 +199,27 @@ actions: message: >- "EVcharge process on {{ evcharge_entity2_var }} has started" title: EV Charge process + - action: notify.tiziano_trabattoni_gmail_com + data: + title: "EVcharge process on {{ evcharge_entity2_var }} has started" + target: "{{ recipient_list_gmail['target'] }}" + message: >- + "EVcharge process on {{ evcharge_entity2_var }} has started" # take energy counter before charging - variables: - energy2_before: "{{ states(evcharge_entity2_energy_var) | float }}" + energy2_before: "{{ states(evcharge_entity2_energy_var) | float | round(2) }}" # turn_on evcharge_entity2 - action: switch.turn_on - entity_id: switch.presa_smart_2 # TEST ONLY + entity_id: !input evcharge_entity2 + # entity_id: switch.presa_smart_2 # TEST ONLY # need to wait car to start charging - delay: 120 # - delay: 10 # TEST ONLY + # Wait for charging to complete - repeat: until: "{{ ( states(evcharge_entity2_power_var) | int ) < ( states('input_number.evcharge_no_charge_threshold') | int) }}" # until: "{{ ( states('input_number.test_evcharge_back') | int) < ( states('input_number.evcharge_no_charge_threshold') | int) }}" # TEST ONLY @@ -202,24 +229,28 @@ actions: # take energy counter after charging - variables: - energy2_after: "{{ states(evcharge_entity2_energy_var) | float }}" + energy2_after: "{{ states(evcharge_entity2_energy_var) | float | round(2) }}" # turn off evcharge_entity2 - action: switch.turn_off - # entity_id: !input evcharge_entity2 - entity_id: switch.presa_smart_2 # TEST ONLY + entity_id: !input evcharge_entity2 + # entity_id: switch.presa_smart_2 # TEST ONLY - repeat: # send message to all recipient-list members - for_each: "{{ recipient_list }}" - + for_each: "{{ recipient_list_notification }}" sequence: - action: "{{ repeat.item }}" metadata: {} data: message: >- - "EVcharge process on {{ evcharge_entity2_var }} has ended: {{ energy2_after - energy2_before }} kW/h charged" + "EVcharge process on {{ evcharge_entity2_var }} has ended: {{ ( energy2_after - energy2_before ) | round(2) }} kW/h charged" title: EV Charge process - + - action: notify.tiziano_trabattoni_gmail_com + data: + title: "EVcharge process on {{ evcharge_entity2_var }} has ended: {{ ( energy2_after - energy2_before ) | round(2) }} kW/h charged" + target: "{{ recipient_list_gmail['target'] }}" + message: >- + "EVcharge process on {{ evcharge_entity2_var }} has ended: {{ ( energy2_after - energy2_before ) | round(2) }} kW/h charged" - if: - and: - condition: template diff --git a/blueprints/automation/homeassistant/test_macro.yaml b/blueprints/automation/homeassistant/test_macro.yaml index c778a16..e0a1017 100644 --- a/blueprints/automation/homeassistant/test_macro.yaml +++ b/blueprints/automation/homeassistant/test_macro.yaml @@ -14,8 +14,14 @@ blueprint: # domain: binary_sensor variables: - recipient_list: + recipient_list_notification: - notify.mobile_app_tiziano_iphone15pro + recipient_list_gmail: + title: "Evcharge Process" + target: + - "tiziano.trabattoni@outlook.com" + - "ema.trabattoni@gmail.com" + # - notify.mobile_app_emanuele_s24 evcharge_entity1_power_var: >- {% from 'template_library.jinja' import getpower_id %} @@ -34,18 +40,42 @@ actions: - conditions: - condition: trigger id: - - p1-confort-light-on - - test_animation + - Pulsante1-single sequence: - # Hereafter the attemped usage as variable initialization - - repeat: # send message to all recipient-list members - for_each: "{{ recipient_list }}" + - alias: send notifications + repeat: # send message to all recipient-list members + for_each: "{{ recipient_list_notification }}" sequence: - action: "{{ repeat.item }}" metadata: {} data: message: >- "TEST -> >>{{ evcharge_entity1_power_var }}<<" - title: TEST TEST + title: "EVcharge process from HA" + - action: notify.tiziano_trabattoni_gmail_com + data: + title: "{{ recipient_list_gmail['title'] }}" + target: "{{ recipient_list_gmail['target'] }}" + message: >- + "TEST -> >>{{ evcharge_entity1_power_var }}<<" +# action: notify.example_gmail_com +# data: +# message: "test" +# title: "test email" +# target: +# - "example2@gmail.com" +# data: +# cc: +# - "example3@gmail.com" +# bcc: +# - "example4@gmail.com" +# from: "example@gmail.com" +# variables: +# cmd: >- +# "{% set ll = (repeat.item | list ) -%}{{ ll[0] }}" +# titolo: +# "{% set ll = (repeat.item | list ) -%}{{ repeat.item[ll[0]].title }}" +# to: +# "{% set ll = (repeat.item | list ) -%}{{ repeat.item[ll[0]].target }}" mode: single