Using Home Assistant to program/control a Victron system

Or alternatively, you could change from using an input_select to use and input_number.
Then, instead of a dropdown on the frontend, you’d have a slider, like this:
image

1 Like

Right, this is the latest one … still no luck.
When I tried something with unput_number as also suggested above, I got a Min SoC of 0%

- alias: Set Victron ESS Minimum SOC from input select
  trigger:
    platform: state
    entity_id: input_select.victron_ess_minimum_soc
  action:
    service: modbus.write_register
    data_template:
      unit: 100
      value: '{{ states(''input_select.victron_ess_minimum_soc'')|int * 10 }}'
      hub: victron
      address: 2901

- alias: Set input select from Victron ESS Minimum SOC
  trigger:
    platform: state
    entity_id: sensor.victron_ess_minimum_soc
  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.victron_ess_minimum_soc
      option: '{{ states(sensor.victron_ess_minimum_soc) }}'

- alias: Set ESS Min SoC Automatically
  trigger:
    platform: time_pattern
    minutes: /5
  condition:
    condition: and
    conditions:
    - condition: sun
      before: sunset
      before_offset: +04:00:00
    - condition: sun
      after: sunrise
      after_offset: -00:30:00
    - condition: template
      value_template: "{{ (states('sensor.bmv_soc')|int) < 800 }}"
  action:
    service: modbus.write_register
    data_template:
      unit: 100
      value: '{{ states(sensor.bmv_soc)|int - 1 - ((states(sensor.bmv_soc)|int -1 ) % 50 ) }}'
      hub: victron
      address: 2901

I think you need to divide by 10:

- alias: Set input select from Victron ESS Minimum SOC
  trigger:
    platform: state
    entity_id: sensor.victron_ess_minimum_soc
  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.victron_ess_minimum_soc
      option: '{{ states(sensor.victron_ess_minimum_soc)|int / 10 }}'
1 Like

No difference … auto upping the SoC does not work.
At least the 0% SoC is now gone.

In the Developer Tool page, go to Templates, then paste this:
{{ states(sensor.bmv_soc)|int - 1 - ((states(sensor.bmv_soc)|int -1 ) % 50 ) }}

See what it says

Damn, THAT is cool to know!

Found the problem!!!
Must be like this, ’ x 2 before and after sensors …

value: '{{ states(''sensor.bmv_soc'')|int - 1 - ((states(''sensor.bmv_soc'')|int -1 ) % 50 ) }}'
1 Like

Right, now it does work, but the maths are wrong.

I set ESS Min SoC to 45%. BMV SoC is 99%

Automation ran! YES!!!
But I got 5% Min ESS Soc, like so:
image

1 Like

Does your automation still have a condition that it only changes the Min SoC if BMV Soc < 80%?

Still the same:

- alias: Set ESS Min SoC Automatically
  trigger:
    platform: time_pattern
    minutes: /5
  condition:
    condition: and
    conditions:
    - condition: sun
      before: sunset
      before_offset: +04:00:00
    - condition: sun
      after: sunrise
      after_offset: -00:30:00
    - condition: template
      value_template: "{{ (states('sensor.bmv_soc')|int) < 800 }}"
  action:
    service: modbus.write_register
    data_template:
      unit: 100
      value: '{{ states(''sensor.bmv_soc'')|int -1 - ((states(''sensor.bmv_soc'')|int -1 ) % 50 ) }}'
      hub: victron
      address: 2901

Note: In the yaml file, one needs 2 x ’ but in the developer section, only 1 x ’ around sensor.

Mmm … https://www.youtube.com/watch?v=ozIKwGt38LQ&feature=youtu.be&ab_channel=SmarterEveryDay

Do you mind sharing how you did the above automation? I finally got time to play with HA again and learning slowly but surely… And example code helps a lot!

Sure, here you go. Actually rather simple now that I look at it again. Immediate thought was that it would cause a loop (Modbus sensor sets the input select, which sets the modbus sensor, which sets the input select, which sets the modbus sensor etc.) but I think since the value doesn’t “change” again it stops the loop.

This is all based on my setup from my previous post.

automation:
- alias: Set input select from Victron ESS Minimum SOC
  trigger:
    platform: state
    entity_id: sensor.victron_ess_minimum_soc
  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.victron_ess_minimum_soc
      option: '{{ states(sensor.victron_ess_minimum_soc) }}'
2 Likes

Hmmm this doesn’t seem to work for me. No idea why. The code compiles fine, just don’t see the option inside the “input select” being updated after I change the sensor’s value on the remote console…

Can you think of anything that I’m potentially doing wrong?

Does your Victron ESS Minimum SOC sensor update on the Home Assistant side?

(This one in my setup: sensor.victron_ess_minimum_soc)

Yes it does, obviously not in real time, but every time HA updates its sensors.

This is the code I am using:

Inside input_select.yaml:

victron_ess_minimum_soc:
name: Victron ESS Minimum SoC
options:
- 20
- 25
- 30
- 35
- 40
- 45
- 50
- 55
- 60
- 65
- 70
- 75
- 80
- 85
- 90
- 95
- 100

Inside Configuration.yaml

sensor:
- name: Victron ESS Minimum SOC
hub: victron
data_type: uint
slave: 100
register: 2901
scale: 0.1
unit_of_measurement: “%”

Inside automations.yaml

  • alias: Set Victron ESS Minimum SOC from input select
    trigger:
    platform: state
    entity_id: input_select.victron_ess_minimum_soc
    action:
    service: modbus.write_register
    data_template:
    unit: 100
    value: ‘{{ states(’‘input_select.victron_ess_minimum_soc’‘)|int * 10 }}’
    hub: victron
    address: 2901

  • alias: Set input select from Victron ESS Minimum SOC
    trigger:
    platform: state
    entity_id: sensor.victron_ess_minimum_soc
    action:
    service: input_select.select_option
    data_template:
    entity_id: input_select.victron_ess_minimum_soc
    option: ‘{{ states(sensor.victron_ess_minimum_soc) }}’

I am doing the same with the ESS Mode (Keep Batteries Charged etc.), that changes on selecting the the new input, but if I change it from remote console, the sensor updates in HA, but the input selector doesn’t…

It would pretty much do this:

I’ve specifically changed both the Mode and Min SoC on remote console, both changed their sensor values but the state change on the sensor doesn’t seem to trigger the automation?

Did you ever get this working?

I’m looking at doing something similar… why did you decide to stop at 80% minimum SOC? And does this strategy even work above 90% or 95%?

I tried playing with mine (manually) today set 95%, and I had cases where it was discharging the battery at 95%, but also charging the batteries (from the grid) while it was at 96%. I assume it might be the hysteresis at play.

Doing it manually.

I got it to this point, then stopped it:
image

… as it never actually did anything. So I “parked” it for it is like going from “Zero to Hero” learning to do higher-grade Doctorial stuff when HA is still mindboggling new to me. :smile:

The 80% there was just to get a working template … the logic is supposed to be:
Starting at Min SOC of 30% from previous night:
IF BMS SOC = 35.1 THEN set SOC = 35
IF BMS SOC = 40.1 THEN set SOC = 40
IF BMS SOC = 45.1 THEN set SOC = 45

Stopping at: IF BMS SOC = 95.1 THEN set SOC = 95

5% increments is fine, if one wants a bigger buffer, then do it in 10% jumps.

If anyone gets this working … and wants to share, I would seriously chaffed. :wink:

I found that Venus says i.e. 95%, but the actual number is like 94.9%
If one then sets it to 95%, Eskom will be called upon.
So that is why I, manually, wait for 0.1% above the SOC I want to set it at.

Yup, it is rounded to the nearest whole number for display purposes.

It would be safer to test if the SOC is between 35 and 40, because it is actually possible (if rare) for a battery to jump from 35.0 to 35.2, causing the soc to never be adjusted.

1 Like

And THE MAN, @ebendl has found a way to automate increasing the Min ESS SOC!!!
Give the man a Bells! :laughing:
1 - The automated increase of the SOC display … that one can manually intervene.
2 - The manual way of doing it

Logika is nou wraggies cool - copy/paste vir elke SOC setting …

2 Likes