Using Home Assistant to program/control a Victron system

Right, I’ve got HA up and running thanks to @JacoDeJongh. It is running on a Hyper-V machine that is most of the time on seeing it is the entertainment PC, and the watts are like 35w.
I’m this far: (… check that max from 4.2kw array … )

Now I want to get this done: From sunup to sunset:
IF BMV_SOC = 36 THEN SET ESS_MIN_SOC = 35
IF BMV_SOC = 41 THEN SET ESS_MIN_SOC = 40
IF BMV_SOC = 46 THEN SET ESS_MIN_SOC = 45
IF BMV_SOC = 51 THEN SET ESS_MIN_SOC = 50
IF BMV_SOC = 56 THEN SET ESS_MIN_SOC = 55
… and so forth.

From no idea of HA even existed to this level, yeah, how else does one do it? :wink:
I have spent days now Googling how to do the above and are now more confused than even before I started. :laughing:

I have seen people suggest along these lines but I think there are a lot in-between I’m not “getting” my head around, like someone said, create an automations.yml:
action:

  • data_template:
    address: 2901
    hub: victron
    unit: 100
    value: ‘{{ CALC_HERE | int}}’
    service: modbus.write_register

Ok, now what?

Another one I saw:
sensors.yaml:

  • name: “ESS MIN SOC”
    hub: victron
    data_type: int
    unit_of_measurement: “%”
    slave: 100
    register: 2901
    scale: 0.1
    precision: 0

  • name: “BMV SOC”
    hub: victron
    data_type: uint
    unit_of_measurement: “%”
    slave: 245
    register: 266
    scale: 0.1

And create a switches.yaml
- platform: modbus
registers:
- name: Up SOC
hub: victron
slave: 100
register: 2901
command_on: 30 (something more is needed here … )
verify_state: false

Again, a lot missing in-between I think …

Anyone game to help me get the above in place, that it works?
See it as “Monkey see, Monkey do” … and on my way I am to craft more ideas.
Just need that template.

And once the above is working then I want to get this going, file for file, step by step inside HA:


Maybe @ebendl can add his files and steps inside HA, to copy/paste for the next person?

Want to use SolCast to determine what my ESS_MIN_SOC must be each night based on the anticipated production the next day.

After that I want a couple of them Sonof switches … switch stuff on and off from the HA dashboard … some stuff automatic. I’ll get there.

3 Likes

Nice…I went the node red route and keep my switches on node dashboard and the rest of the data exported to local emoncms to use as a visual dashboard and as my data server.

1 Like

Nice! Speaking of monkey see, monkey do. What theme are you running there? I’m loving the look with that colored background and rounder corners of the cards

I would take it one step at a time – especially if you’re new to Home Assistant!.

Quick Questions:

  • Do you already have a sensors.yaml, since you clearly have the Victron reporting values (I see SOC on your battery)
  • have you managed to set the minimum SOC from Home Assistant yet? Not automatically – just setting it via a dropdown value or so?

I can set my minimum SOC like this:

image

1 Like

First thing I did … Installed HACS and then IOS Theme Dark mode Light mode.

1 Like

Yes!!! Got sensors working, can pull any data from the system.

Tried to get it going that I could manually set the Min SOC on ESS as per your picture … no luck yet.

Would very much like to do what u did there first.

Thank you! Now my HA also looks spiffy!

1 Like

Sorry for the delay in replying!

The basic of switching the minimum SOC is a service called “modbus.write_register”. You specify the hub (called “Victron” in my case – this is the part that you set up with the VenusGX/ColorControl’s IP etc.), the address (2901 for the minimum SOC), and the value and unit.

In my case, I use a Home Assistant data template to use the templating language to send not a predefined, static value, but rather something based on another sensor or entity – in my case, the input_select called “input_select.victron_ess_minimum_soc”.

In automations:

automations:
    - 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

So the automation basically looks for a change in state (trigger: with the platform:state) of the input_select .victron_ess_minimum_soc. So if I select another value in the input select dropdown, this automation triggers.

The action that it takes is to take the value of the input_select, converts it from a text value to an integer (20 - 100), and then multiples it by 10. This is because the register expects values from 0 - 1000 according to the Victron spreadsheet – no idea why.

The input select is defined as follows:

input_select:
  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

I have another automation which reads the value from the register and then changes the input_select again – this is useful if I use the Remote console to set a value, then it automatically reflects in Home Assistant. But it isn’t as critical – rather get the above working!

1 Like

Thank you Eben … !

Yes, with Cronjobs I can set the min SOC with ease … but there is a trick to it if I never want to use Eskom.

Note: Errors that was here has been deleted to avert confusion …

Either in configuration.yaml, under the heading

input_select:
      - <config here>

Or you can create another YAML file (say called input_select.yaml) and then “include” it into your main config:

input_select: !include input_select.yaml

1 Like

Note: Errors that was here has been deleted to not confuse others …

Remove the top line from your input_select.yaml file.

Essentially, when HA sees input_select: !include input_select.yaml
it just takes the contents of the input_select.yaml file, and sticks them there, so as you have it, it would read:

input_select:
input_select:
victron_ess_minimum_soc:
name: ESS Minimum SoC
options:

* 20
… etc.

Note the doubling of the top line, that’s the issue

Note: Errors that was here has been deleted to not confuse others …

No, the issue is the content of the input_select.yaml / selected_input.yaml file (the name is somewhat irrelevant, as long as it’s referenced properly in your configuration.yaml).

The problem is that in the content of the file, the first line is input_select:
This line shouldn’t be there, because it’s causing a duplication of input_select: when the replacement of input_select: !include selected_input.yaml takes place.

Example:
If we’re looking for

cars:
- toyota
- ford
- bmw

we could just stick that in the configuration.yaml file, as is, but it’s nicer to split it up, by literally selecting everything after the : and putting it in a separate file.
Configuration.yaml:

cars: !include cars.yaml

cars.yaml:

- toyota
- ford
- bmw

cars.yaml should not contain cars:, since that already exists in the configuration.yaml file.

Hope I explained that clearly.

Do use the code formatting option on the forum - it preserves whitespace. Else it is impossible to see if indentation could be your problem (common issue in Yaml).

Sorted!!!
What one sees and assumes is not what was intended/said … monkies copy and paste … :laughing:

I was looking for that - which options should I use that the next person can copy/paste from here?

Here are the final files now, as I have no more errors:

In the automations.yaml file:

Create and edit selected_input.yaml file:
image

In the configuration.yaml file add this line:

Code formatting:

Paste your code, then surround it with ``` (3 backticks) (backticks must be on their own line, one set before the code, one set after it)

Turns this:
cars:

  • toyota
  • ford
  • bmw

into this:

cars:
- toyota
- ford
- bmw
1 Like

For copy and paste prosperity.

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

selected_unput.yaml:

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

Right, what step is next, to get that button on the screen to up the SOC manually?

On the page you want to add it, add a manual card, with this code:

type: entities
entities:
  - entity: input_select.victron_ess_minimum_soc
    name: Min Battery %
title: Min Battery SoC
2 Likes