From 41c3a4fef113f2962b151b72b4e5a60bb11ea17e Mon Sep 17 00:00:00 2001 From: ttrabatt Date: Sat, 8 Feb 2025 00:45:32 +0100 Subject: [PATCH] EVcharge Process WIP testing --- automations.yaml | 4 +- .../homeassistant/evcharge-process.yaml | 46 ++++++++++++++++++- custom_templates/template_library.jinja | 9 ++++ 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 custom_templates/template_library.jinja diff --git a/automations.yaml b/automations.yaml index 15a37cd..55a63ad 100644 --- a/automations.yaml +++ b/automations.yaml @@ -116,14 +116,16 @@ input: light_target: entity_id: light.test_lamp1 -- id: '1738428672069' +- id: '1738952270274' alias: Test-EVcharge-process description: '' 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 diff --git a/blueprints/automation/homeassistant/evcharge-process.yaml b/blueprints/automation/homeassistant/evcharge-process.yaml index 31566bc..48a32f6 100644 --- a/blueprints/automation/homeassistant/evcharge-process.yaml +++ b/blueprints/automation/homeassistant/evcharge-process.yaml @@ -11,6 +11,13 @@ 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' @@ -19,6 +26,14 @@ 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' description: Identifies the input flag for charging on 'Controlled Plug1' (eg EVcharge_front_request) @@ -59,8 +74,35 @@ 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 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_ttrabatt_iphone15 #- notify.mobile_app_emanuele_s24 @@ -121,7 +163,7 @@ actions: - delay: 10 - repeat: - # until: "{{ ( states( evcharge_entity1_var, 'power') | int ) < ( states('input_number.evcharge_no_charge_threshold') | int ) }}" + # 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) }}" sequence: - delay: 60 @@ -175,7 +217,7 @@ actions: - delay: 10 - repeat: - # until: "{{ state_attr( evcharge_entity2_var, 'power') < states('input_number.evcharge_no_charge_threshold') }}" + # 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: 60 diff --git a/custom_templates/template_library.jinja b/custom_templates/template_library.jinja new file mode 100644 index 0000000..70e0999 --- /dev/null +++ b/custom_templates/template_library.jinja @@ -0,0 +1,9 @@ +{% 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 %} +