From 0274ddc7d393074e2f74a245c30f172378f5fc26 Mon Sep 17 00:00:00 2001 From: ttrabatt Date: Sat, 22 Feb 2025 21:40:12 +0100 Subject: [PATCH] EVcharge-process-NG under test --- automations.yaml | 31 ++- .../homeassistant/evcharge-process.yaml | 105 ++++---- examples/evcharge-process-OLD.yaml | 250 ++++++++++++++++++ 3 files changed, 313 insertions(+), 73 deletions(-) create mode 100644 examples/evcharge-process-OLD.yaml diff --git a/automations.yaml b/automations.yaml index ce7080f..557ae7e 100644 --- a/automations.yaml +++ b/automations.yaml @@ -88,22 +88,25 @@ input: light_target: entity_id: light.test_lamp1 -- id: '1739185900251' - alias: EVcharge-process - description: 'Charge sequentially via both front and back plugs depending on EVcharge - request flags ' - use_blueprint: - path: homeassistant/evcharge-process.yaml - input: - evcharge_entity1: switch.evcharge_front - evcharge_entity1_power: sensor.evcharge_front_power - evcharge_entity2: switch.evcharge_back - evcharge_entity2_power: sensor.evcharge_back_power - use_entity1: input_boolean.evcharge_front_request - use_entity2: input_boolean.evcharge_back_request - start_button: input_button.evcharge_start - id: '1739393696392' alias: Power-load-high 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 + power and energy entities) + use_blueprint: + path: homeassistant/evcharge-process.yaml + input: + evcharge_entity1: switch.evcharge_front + evcharge_entity2: switch.evcharge_back + use_entity1: input_boolean.evcharge_front_request + use_entity2: input_boolean.evcharge_back_request + start_button: input_button.evcharge_start diff --git a/blueprints/automation/homeassistant/evcharge-process.yaml b/blueprints/automation/homeassistant/evcharge-process.yaml index 70378c7..ccfbdc1 100644 --- a/blueprints/automation/homeassistant/evcharge-process.yaml +++ b/blueprints/automation/homeassistant/evcharge-process.yaml @@ -1,6 +1,6 @@ blueprint: name: evcharge_process - description: Mange charging process between two charging points + description: Manage charging process between two charging points with Charged Energy calculation domain: automation author: Tiziano Trabattoni input: @@ -11,13 +11,6 @@ blueprint: entity: filter: - domain: switch - evcharge_entity1_power: - name: Charge via 'Controlled Plug1' - description: Identifies the Switch1 power entity (eg EVcharge-front-power) - selector: - entity: - filter: - - device_class: power evcharge_entity2: name: Charge via 'Controlled Plug2' @@ -26,13 +19,6 @@ blueprint: entity: filter: - domain: switch - evcharge_entity2_power: - name: Charge via 'Controlled Plug2' - description: Identifies the Switch1 power entity (eg EVcharge-back-power) - selector: - entity: - filter: - - device_class: power use_entity1: name: Enable charge via 'Controlled Plug1' @@ -74,34 +60,23 @@ conditions: [] variables: evcharge_entity1_var: !input evcharge_entity1 evcharge_entity2_var: !input evcharge_entity2 - evcharge_entity1_power_var: !input evcharge_entity1_power - evcharge_entity2_power_var: !input evcharge_entity2_power + + evcharge_entity1_power_var: >- + {% from 'template_library.jinja' import getpower_id %} + {{ getpower_id(evcharge_entity1_var) }} + evcharge_entity2_power_var: >- + {% from 'template_library.jinja' import getpower_id %} + {{ getpower_id(evcharge_entity2_var) }} + evcharge_entity1_energy_var: >- + {% from 'template_library.jinja' import getenergy_id %} + {{ getenergy_id(evcharge_entity1_var) }} + evcharge_entity2_energy_var: >- + {% from 'template_library.jinja' import getenergy_id %} + {{ getenergy_id(evcharge_entity2_var) }} + use_entity1_var: !input use_entity1 use_entity2_var: !input use_entity2 - # tried to get entity for sensot.evcharge_front_power with jinja macro, macro working but using in automation is not - # terefore added more inputs and entity and entity powe must be assigned correctly otherwise the automation won't work - # jinja macro in config/custo_template/template_library.jinja - # - # Hereafter the macro for reference only: - # - # {% macro getpower_id(evcharge_id) %} - # {% set attrib_list = device_entities( device_id (evcharge_id ) ) %} - # {% for attrib in attrib_list %} - # {% if ( attrib | regex_search('power$')) %} - # {{ attrib }} - # {% endif %} - # {% endfor %} - # {% endmacro %} - - # Hereafter the attemped usage as variable initialization - # evcharge_entity1_power_var: >- - # {% from 'template_library.jinja' import getpower_id %} - # {% getpower_id(evcharge_entity1_var) %} - # evcharge_entity2_power_var: >- - # {% from 'template_library.jinja' import getpower_id %} - # {% getpower_id(evcharge_entity2_var) %} - # here list of mobile APP to be notified recipient_list: - notify.mobile_app_tiziano_iphone15pro @@ -112,10 +87,10 @@ actions: - or: - condition: template value_template: "{{ is_state(evcharge_entity1_var, 'on') }}" - # TEST ONLY: value_template: "{{ false }}" + # value_template: "{{ false }}" # TEST ONLY - condition: template value_template: "{{ is_state(evcharge_entity2_var, 'on') }}" - # TEST ONLY: value_template: "{{ false }}" + # value_template: "{{ false }}" # TEST ONLY then: # charge already active, send message and terminate @@ -146,29 +121,34 @@ actions: message: >- "EVcharge process on {{ evcharge_entity1_var }} has started" title: EV Charge process - - # Wait before starting charge - - delay: 10 + # take energy counter before charging + - variables: + energy1_before: "{{ states(evcharge_entity1_energy_var) | float }}" # Start plug1 and wait until power measured is below input_number.evcharge_no_charge_threshold for 10 minutes = 600 seconds - action: switch.turn_on entity_id: !input evcharge_entity1 - # TEST ONLY: entity_id: switch.presa_smart_1 + # entity_id: switch.presa_smart_1 # TEST ONLY # need to wait car to start charging - delay: 120 - # TEST ONLY: - delay: 10 + # - delay: 10 # TEST ONLY - repeat: until: "{{ ( states(evcharge_entity1_power_var) | int ) < ( states('input_number.evcharge_no_charge_threshold') | int ) }}" - # TEST ONLY: until: "{{ ( states('input_number.test_evcharge_front') | 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 sequence: - delay: 120 + # - delay: 10 # TEST ONLY + + # take energy counter after charging + - variables: + energy1_after: "{{ states(evcharge_entity1_energy_var) | float }}" # turn off evcharge_entity1 - action: switch.turn_off entity_id: !input evcharge_entity1 - # TEST ONLY: entity_id: switch.presa_smart_1 + # entity_id: switch.presa_smart_1 # TEST ONLY - repeat: # send message to all recipient-list members for_each: "{{ recipient_list }}" @@ -178,13 +158,12 @@ actions: metadata: {} data: message: >- - "EVcharge process on {{ evcharge_entity1_var }} has ended" + "EVcharge process on {{ evcharge_entity1_var }} has ended: {{ energy1_after - energy1_before }} kW/h charged" title: EV Charge process # wait couple of minutes before starting charge on plug2 - delay: 120 - # TEST ONLY: - delay: 10 - + # - delay: 10 # TEST ONLY - if: - condition: template value_template: "{{ is_state(use_entity2_var, 'on') }}" @@ -202,25 +181,33 @@ actions: "EVcharge process on {{ evcharge_entity2_var }} has started" title: EV Charge process + # take energy counter before charging + - variables: + energy2_before: "{{ states(evcharge_entity2_energy_var) | float }}" + # turn_on evcharge_entity2 - action: switch.turn_on - entity_id: !input evcharge_entity2 - # TEST ONLY: entity_id: switch.presa_smart_2 + entity_id: switch.presa_smart_2 # TEST ONLY # need to wait car to start charging - delay: 120 - # TEST ONLY: - delay: 10 + # - delay: 10 # TEST ONLY - 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) }}" + # until: "{{ ( states('input_number.test_evcharge_back') | int) < ( states('input_number.evcharge_no_charge_threshold') | int) }}" # TEST ONLY sequence: - delay: 120 + # - delay: 10 # TEST ONLY + + # take energy counter after charging + - variables: + energy2_after: "{{ states(evcharge_entity2_energy_var) | float }}" # turn off evcharge_entity2 - action: switch.turn_off - entity_id: !input evcharge_entity2 - # TEST ONLY: entity_id: switch.presa_smart_2 + # 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 }}" @@ -230,7 +217,7 @@ actions: metadata: {} data: message: >- - "EVcharge process on {{ evcharge_entity2_var }} has ended" + "EVcharge process on {{ evcharge_entity2_var }} has ended: {{ energy2_after - energy2_before }} kW/h charged" title: EV Charge process - if: diff --git a/examples/evcharge-process-OLD.yaml b/examples/evcharge-process-OLD.yaml new file mode 100644 index 0000000..457a21c --- /dev/null +++ b/examples/evcharge-process-OLD.yaml @@ -0,0 +1,250 @@ +blueprint: + name: evcharge_process + description: Mange charging process between two charging points + domain: automation + author: Tiziano Trabattoni + input: + evcharge_entity1: + name: Charge via 'Controlled Plug1' + description: Identifies the Switch1 (eg EVcharge-front) + selector: + entity: + filter: + - domain: switch + evcharge_entity1_power: + name: Charge via 'Controlled Plug1' + description: Identifies the Switch1 power entity (eg EVcharge-front-power) + selector: + entity: + filter: + - device_class: power + + evcharge_entity2: + name: Charge via 'Controlled Plug2' + description: Identifies the Switch2 (eg EVcharge-back) + selector: + entity: + filter: + - domain: switch + evcharge_entity2_power: + name: Charge via 'Controlled Plug2' + description: Identifies the Switch1 power entity (eg EVcharge-back-power) + selector: + entity: + filter: + - device_class: power + + use_entity1: + name: Enable charge via 'Controlled Plug1' + description: Identifies the input flag for charging on 'Controlled Plug1' (eg EVcharge_front_request) + selector: + entity: + filter: + - domain: input_boolean + use_entity2: + name: Enable charge via 'Controlled Plug2' + description: Identifies the input flag for charging on 'Controlled Plug2' (eg EVcharge_back_request) + selector: + entity: + filter: + - domain: input_boolean + + start_button: + name: start_button + description: Identifies the button to start EVcharge process + selector: + entity: + filter: + - domain: input_button + +triggers: + - trigger: state # Want to trigger start now + entity_id: !input start_button + id: start_now + - trigger: time # Start at F3 start tome + at: input_datetime.evcharge_good_time_start + id: start_at_good_time + +# for time being let's do sequential charge for Plug1 and then Plug2 +mode: single + +# here we could stop immediately if sensor.pw_load_power is above 5000W but lets decide after +conditions: [] + +variables: + evcharge_entity1_var: !input evcharge_entity1 + evcharge_entity2_var: !input evcharge_entity2 + evcharge_entity1_power_var: !input evcharge_entity1_power + evcharge_entity2_power_var: !input evcharge_entity2_power + use_entity1_var: !input use_entity1 + use_entity2_var: !input use_entity2 + + # tried to get entity for sensot.evcharge_front_power with jinja macro, macro working but using in automation is not + # terefore added more inputs and entity and entity powe must be assigned correctly otherwise the automation won't work + # jinja macro in config/custo_template/template_library.jinja + # + # Hereafter the macro for reference only: + # + # {% macro getpower_id(evcharge_id) %} + # {% set attrib_list = device_entities( device_id (evcharge_id ) ) %} + # + # {% for attrib in attrib_list -%} + # {% if ( attrib | regex_search('power$')) -%} + # {{ attrib }} + # {%- endif %} + # {%- endfor %} + # {% endmacro %} + + # Hereafter the attemped usage as variable initialization + # evcharge_entity1_power_var: >- + # {% from 'template_library.jinja' import getpower_id %} + # {% getpower_id(evcharge_entity1_var) %} + # evcharge_entity2_power_var: >- + # {% from 'template_library.jinja' import getpower_id %} + # {% getpower_id(evcharge_entity2_var) %} + + # here list of mobile APP to be notified + recipient_list: + - notify.mobile_app_tiziano_iphone15pro + - notify.mobile_app_emanuele_s24 + +actions: + - if: + - or: + - condition: template + value_template: "{{ is_state(evcharge_entity1_var, 'on') }}" + # TEST ONLY: value_template: "{{ false }}" + - condition: template + value_template: "{{ is_state(evcharge_entity2_var, 'on') }}" + # TEST ONLY: value_template: "{{ false }}" + + then: + # charge already active, send message and terminate + repeat: + for_each: "{{ recipient_list }}" + + sequence: + - action: "{{ repeat.item }}" + metadata: {} + data: + message: >- + "EVcharge process is ALREADY RUNNING" + title: EV Charge process ERROR + else: + sequence: + - if: + - condition: template + value_template: "{{ is_state(use_entity1_var, 'on') }}" + then: # EVcharge entity_1 (eg front) charge is requested + sequence: + - repeat: # send message to all recipient-list members + for_each: "{{ recipient_list }}" + + sequence: + - action: "{{ repeat.item }}" + metadata: {} + data: + message: >- + "EVcharge process on {{ evcharge_entity1_var }} has started" + title: EV Charge process + + # Start plug1 and wait until power measured is below input_number.evcharge_no_charge_threshold for 10 minutes = 600 seconds + - action: switch.turn_on + entity_id: !input evcharge_entity1 + # TEST ONLY: entity_id: switch.presa_smart_1 + + # need to wait car to start charging + - delay: 120 + # TEST ONLY: - delay: 10 + + - repeat: + until: "{{ ( states(evcharge_entity1_power_var) | int ) < ( states('input_number.evcharge_no_charge_threshold') | int ) }}" + # TEST ONLY: until: "{{ ( states('input_number.test_evcharge_front') | int) < (states('input_number.evcharge_no_charge_threshold') | int) }}" + sequence: + - delay: 120 + + # turn off evcharge_entity1 + - action: switch.turn_off + entity_id: !input evcharge_entity1 + # TEST ONLY: entity_id: switch.presa_smart_1 + + - repeat: # send message to all recipient-list members + for_each: "{{ recipient_list }}" + + sequence: + - action: "{{ repeat.item }}" + metadata: {} + data: + message: >- + "EVcharge process on {{ evcharge_entity1_var }} has ended" + title: EV Charge process + + # wait couple of minutes before starting charge on plug2 + - delay: 120 + # TEST ONLY: - delay: 10 + + - if: + - condition: template + value_template: "{{ is_state(use_entity2_var, 'on') }}" + then: + 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 }}" + + sequence: + - action: "{{ repeat.item }}" + metadata: {} + data: + message: >- + "EVcharge process on {{ evcharge_entity2_var }} has started" + title: EV Charge process + + # turn_on evcharge_entity2 + - action: switch.turn_on + entity_id: !input evcharge_entity2 + # TEST ONLY: entity_id: switch.presa_smart_2 + + # need to wait car to start charging + - delay: 120 + # TEST ONLY: - delay: 10 + + - 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) }}" + sequence: + - delay: 120 + + # turn off evcharge_entity2 + - action: switch.turn_off + entity_id: !input evcharge_entity2 + # TEST ONLY: entity_id: switch.presa_smart_2 + + - repeat: # send message to all recipient-list members + for_each: "{{ recipient_list }}" + + sequence: + - action: "{{ repeat.item }}" + metadata: {} + data: + message: >- + "EVcharge process on {{ evcharge_entity2_var }} has ended" + title: EV Charge process + + - if: + - and: + - condition: template + value_template: "{{ is_state(use_entity1_var, 'off') }}" + - condition: template + value_template: "{{ is_state(use_entity2_var, 'off') }}" + then: + - repeat: # send message to all recipient-list members + for_each: "{{ recipient_list }}" + + sequence: + - action: "{{ repeat.item }}" + metadata: {} + data: + message: >- + "EVcharge process activation ERROR, select what to charge" + title: EV Charge process ERROR