I'm trying to trigger on SoC level, help needed

Post Reply
marcus
Posts: 11
Joined: Thu Aug 10, 2023 8:19 am

I'm hoping someone can help, I thought this would work after testing in the templates page but hasn't triggered.

Background for goal:
I've had automations setting the work mode based on the tariffs, so at the start of the peak rate I switch to Feed-In Priority, at the end of peak I switch back to Self use. Now with the ability to Force Discharge I edited this to get even more at the peak export rate starting at 4pm. I only wanted to discharge to a set SoC though, so I set the number.min_soc and number.min_soc_on_grid to something that would see us to the next day.

Of course you reach the Min SoC, you are in Force Discharge mode, the system starts consuming from the grid (at the peak rate).

So I thought of this, if the SoC gets to that level in Force Discharge mode, I trigger this changing the mode to something else (Self Use or Feed In) and set the Min SoC to a lower level to use battery and prevent any grid consumption.

didn't trigger though, Any ideas?

Code: Select all

trigger:
  - platform: template
    value_template: >-
      "{{  states('sensor.battery_soc') | int(0) <=
      states('input_number.min_soc_peak') | int(0) }}"
here's the full automation

Code: Select all

alias: "Energy: Battery target Force Discharge SoC level achieved "
description: >-
  Sets the Min SoC to lower 'day time' level and work mode back to Feed-In
  Priority
trigger:
  - platform: template
    value_template: >-
      "{{  states('sensor.workshop_battery_soc') | int(0) <=
      states('input_number.min_soc_peak') | int(0) }}"
    variables:
      minSoC: "{{ float(states('input_number.min_soc_day')) }}"
      workmode: Feed-In Priority
condition:
  - condition: template
    value_template: "{{ states('select.workshop_work_mode') == 'Force Discharge' }}"
action:
  - service: number.set_value
    target:
      entity_id: number.workshop_min_soc
    data:
      value: "{{ minSoC }}"
  - service: number.set_value
    target:
      entity_id: number.workshop_min_soc_on_grid
    data:
      value: "{{ minSoC }}"
  - service: select.select_option
    target:
      entity_id: select.workshop_work_mode
    data:
      option: "{{ workmode }}"
mode: single
thanks!
Marcus

House
H1 Series H1-3.7-E Inverter | RS485 Modbus->HA
8x Jinko 300W Mono (3x East facing; 5x South facing - 2400W)
Workshop
H1 Series H1-5.0-E Inverter | RS485 Modbus->HA
7x HV2600 2.6 kWh (5x V2; 2x V1 (Version C)) BMS V2 using this fix
12x Canadian 430W (2 strings South facing - 5160W)
Dave Foster
Posts: 1295
Joined: Thu Oct 13, 2022 7:21 pm

I can’t test it but the logic looks ok, but as a trigger I think that template test will only ‘trigger’ when the test changes i.e. your battery soc would have to drop below or go above you input number - but it won’t trigger if it is already above or below it.

The best way to handle it is to change it from the trigger, instead trigger on time pattern every 5 minutes ‘/5’ and move the template down to conditions - that way it will trigger every 5 minutes, test the conditions and if they are true it will continue to the actions.

I’d suggest adding a logbook entry to the actions, that way it will be much easier to see when it fires.

Code: Select all


service: logbook.log
data:
  message: MinSoC at or below 
  name: Force Discharge Battery Check
marcus
Posts: 11
Joined: Thu Aug 10, 2023 8:19 am

thanks Dave,

The polling every 5 minutes against a condition works a treat, great idea! :idea: I don't think the trigger was firing at all on the state...

If it helps anyone else trying to achieve similar this is what I've gone with
Note: tweak vars with entity "workshop" and introduce input_number.min_soc_peak and input_number.min_soc_day similar to max SoC automation

Code: Select all

alias: "Energy: Battery target Force Discharge SoC level achieved"
description: >-
  Sets the Min SoC to lower 'day time' level and work mode back to Feed-In First
  - it 'polls' every 5 minutes during the 16th, 17th & 18th hours to check
  condition
trigger:
  - platform: time_pattern
    hours: 16
    minutes: /5
  - platform: time_pattern
    hours: 17
    minutes: /5
  - platform: time_pattern
    hours: 18
    minutes: /5
condition:
  - and:
      - condition: template
        value_template: "{{ states('select.workshop_work_mode') == 'Force Discharge' }}"
      - condition: template
        value_template: >-
          {{ states('sensor.workshop_battery_soc')|float(0) <=
          states('input_number.min_soc_peak')|float(0) }}
action:
  - variables:
      minSoC: "{{ float(states('input_number.min_soc_day')) }}"
      workmode: Feed-in First
  - service: number.set_value
    target:
      entity_id: number.workshop_min_soc
    data:
      value: "{{ minSoC }}"
  - service: number.set_value
    target:
      entity_id: number.workshop_min_soc_on_grid
    data:
      value: "{{ minSoC }}"
  - service: select.select_option
    target:
      entity_id: select.workshop_work_mode
    data:
      option: "{{ workmode }}"
mode: single

trace.png
cheers
Marcus

House
H1 Series H1-3.7-E Inverter | RS485 Modbus->HA
8x Jinko 300W Mono (3x East facing; 5x South facing - 2400W)
Workshop
H1 Series H1-5.0-E Inverter | RS485 Modbus->HA
7x HV2600 2.6 kWh (5x V2; 2x V1 (Version C)) BMS V2 using this fix
12x Canadian 430W (2 strings South facing - 5160W)
Post Reply