Hello @dikkertjedap! Thanks for responding.
I read your original thread and but was quite overwhelmed. I will read through it once more.
Your assumptions are correct! I have already setup sensors for PV production and Battery SOC (of the house), but unfortunately there doesn’t seem to be a way to get the cars SOC. Wallbox just lists this as unknown, but I couldn’t see this being a major problem? Where I get stuck is creating the input number in amps. I will show you what I’ve got so far and you can pick holes in it and provide further guidance if you are willing
- id: '###'
alias: test
description: ''
trigger:
- platform: time_pattern
minutes: /1
condition:
- condition: and
conditions:
- condition: sun
after: sunrise
after_offset: 02:00:00
- condition: sun
before: sunset
before_offset: -02:00:00
action:
- if:
- condition: numeric_state
entity_id: sensor.battery_soc
above: 90
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.battery_use
below: -1300
then:
- if:
- condition: device
type: is_off
device_id: dd9d56ea186f6428125c912832e9ad9c
entity_id: 047f7ff3b13da53c4f688733685ea22c
domain: switch
then:
- type: turn_on
device_id: dd9d56ea186f6428125c912832e9ad9c
entity_id: 047f7ff3b13da53c4f688733685ea22c
domain: switch
- service: number.set_value
data:
value: '{% set current_amps = states(''wallbox_portal_max_charging_current'')
| int %} {% set add_amps = (states(''battery_use'') | int / -240) | round(0,''floor'')
%} {{ current_amps + add_amps }}'
target:
entity_id: number.wallbox_portal_max_charging_current
else:
- if:
- condition: numeric_state
entity_id: sensor.battery_use
above: 0
then:
- type: turn_off
device_id: dd9d56ea186f6428125c912832e9ad9c
entity_id: 047f7ff3b13da53c4f688733685ea22c
domain: switch
mode: single
To explain some of this further, I have set battery_use
to below -1300
as I’m using this as my ‘surplus measurement’. IE when the battery is in negative use, it means it’s charging. And I have chosen -1300 because the minimum my wallbox can charge seems to be 6 amps (at 240V).
It’s the number.set_value
section it all falls apart. I have tried to pilfer this from the thread above and changed a few parameters, but I think I’m very much missing something. There was a user mentioning inputting an average surplus over 5 minutes and triggering as often, but I was unsure how to do this. I should also explain that this fails with value/template error because no default specified. I haven’t worried to fix this because I’m not sure if it’s worth fixing and I should be going another route entirely.
Thanks again for the response. I will peruse your original thread with hopefully some improved mental capacity and see if it starts to make sense.
Kindest regards.
EDIT: If starting from scratch, this is where I get to before I lose all sense of purpose and electrical brain power and start banging my head against the wall.
- id: '1696108815309'
alias: Test
description: ''
trigger:
- platform: time_pattern
minutes: /1
condition:
- condition: numeric_state
entity_id: sensor.battery_soc
above: 90
action:
- if:
- condition: numeric_state
entity_id: sensor.battery_use
below: -1400
then:
- type: turn_on
device_id: dd9d56ea186f6428125c912832e9ad9c
entity_id: 047f7ff3b13da53c4f688733685ea22c
domain: switch
- variables:
grid_usage: '{{ states(''sensor.battery_use'') | float }}'
max_charging_amps: 25
min_charging_amps: 6
grid_voltage: 240}
- condition: template
value_template: '"{{ grid_usage < 0 }}"'
- service: number.set_value
target:
entity_id: number.wallbox_portal_max_charging_current
data:
value: '{% set wallbox_portal_charging_power = (states(''number.wallbox_portal_max_charging_current'')
| int) * grid_voltage %} {% set wallbox_portal_max_charging_current = ((grid_usage
+ wallbox_portal_charging_power) / grid_voltage) | round(0, ''floor'') |
int %} {{ [max_charging_amps, charging_amps] | min }}'
I decided it would be potentially better to use your ‘Power Grid Usage’ sensor, so I tried adding it to my configuration.yaml
file like so
- name: "power consumption"
device_class: energy
state_class: total
state: "{{(state_attr('sensor.selectronic', 'load_w')|float) | round(3)}}"
unit_of_measurement: "W"
unique_id: sensor.selectronic.pwrcon
- name: "power production"
device_class: energy
state_class: total
state: "{{(state_attr('sensor.selectronic', 'solarinverter_w')|float) | round(3)}}"
unit_of_measurement: "W"
unique_id: sensor.selectronic.pwrpro
- name: "power grid usage"
unit_of_measurement: "W"
value_template: >
{% set power_production_w = states('sensor.power_production') | float * 1000 %}
{% set power_consumption_w = states('sensor.power_consumption') | float * 1000 %}
{% if power_production_w >= 0 and power_consumption_w >= 0 %}
{{ (power_production_w - power_consumption_w) }}
{% elif power_production_w >= 0 %}
{{ power_production_w }}
{% else %}
{{ -1 * power_consumption_w }}
{% endif %}
But it’s spewing errors, probably because I have no idea what I’m doing
EDIT II:
I just screwed around with the Template Developer Tools and came up with this, and it seems to give me the correct reading?
template:
- sensor:
- name: "Remaining power"
unit_of_measurement: "W"
state: >
{% set power_production_w = states('sensor.power_production') | float %}
{% set power_consumption_w = states('sensor.power_consumption') | float %}
{% if power_production_w >= 0 and power_consumption_w >= 0 %}
{{ (power_production_w - power_consumption_w) }}
{% elif power_production_w >= 0 %}
{{ power_production_w }}
{% else %}
{{ -1 * power_consumption_w }}
{% endif %}
If you don’t see anything too gnarly with this, let me know.
I think I’m finally beginning to get my head around this, but I won’t know until the sun is up tomorrow. This is what I’ve got!
- id: '1696138397325'
alias: IS THIS IT??
description: ''
trigger:
- platform: state
entity_id:
- sensor.power_surplus_for_car
condition:
- condition: numeric_state
entity_id: sensor.battery_soc
above: 90
action:
- variables:
grid_usage: '{{ states(''sensor.power_surplus_for_car'') | float }}'
max_charging_amps: 25
min_charging_amps: 6
grid_voltage: 240
- choose:
- conditions:
- condition: template
value_template: '{{ grid_usage > 0 }}'
sequence:
- type: turn_on
device_id: dd9d56ea186f6428125c912832e9ad9c
entity_id: 047f7ff3b13da53c4f688733685ea22c
domain: switch
- service: number.set_value
target:
entity_id: number.wallbox_portal_max_charging_current
data:
value: '{% set charger_power_draw = (states(''number.wallbox_portal_max_charging_current'')
| int) * grid_voltage %} {% set charging_amps = ((grid_usage + charger_power_draw)
/ grid_voltage) | round(0, ''floor'') | int %} {{ [max_charging_amps,
charging_amps] | min }}
'
- conditions:
- condition: template
value_template: '{{ grid_usage <= 0 }}'
sequence:
- service: number.set_value
target:
entity_id: number.wallbox_portal_max_charging_current
data:
value: '{% set deficit_watts = -1 * grid_usage %} {% set current_charging_amps
= states(''number.wallbox_portal_max_charging_current'') | int %} {% set
required_charging_amps = ((deficit_watts / grid_voltage) | round(0, ''ceil''))
| int %} {% set updated_charging_amps = current_charging_amps - required_charging_amps
%} {% if updated_charging_amps < min_charging_amps %} 1 {% else %} {{
[max_charging_amps, updated_charging_amps] | min }} {% endif %}
'
- choose:
- conditions:
- condition: template
value_template: '{{ states(''number.wallbox_portal_max_charging_current'')
| int <= 6 }}'
sequence:
- type: turn_off
device_id: dd9d56ea186f6428125c912832e9ad9c
entity_id: 047f7ff3b13da53c4f688733685ea22c
domain: switch
mode: single
Thanks so much