(newby question) Trigger switch on above soc and above is_power

Hello HA forum,

this is my very first post here and I hope you excuse maybe stupid newby failures. And please excuse that I might ask questions that have been answered many times before. Will try to stop doing so once I dived deeper into this.

Basic information about my system:
In the course of renovating my old house I try to add a few smart features.

HA on Pi 4b
Growatt (20KWp/30KWh battery)
Anker (Solix E1600Pro, 1 extra battery).
Fritz!Dect components
Moboix cams
Music Players (HifiBerry/Volumio multiroom, Denon HEOS, Linn)
coming soon:
thermostat for electrical floor heating.
Zigbee things.
RS485/ModBUS RTU Gateway (Moxa nPort) to replace Growatt cloud and access the SmartMeter.

Today I set up HA. Was impressively easy!
I started with GUI only, integrated the above mentioned components, created a dashboard and tried automations., added SSH access and well have no clue about the big picture of where to find which configuration files etc.

My first idea is to switch on a pump when the SOC of the Growatt battery is above a value (e.g. 20%) and the output of the generators (panels) ist above a value (e.g. 1500 Watts).

Didn’t work out using GUI assumingly because the SOC can be above the trigger value and the “preset” gave me this “yaml” code:

type: battery_level
device_id: 1cc9617b89dbfe6c4078185134a46042
entity_id: 9ce89635e286728db77c177e01313992
domain: sensor
trigger: device
above: 20
for:
  hours: 0
  minutes: 5
  seconds: 0

AGAIN I found this part of code in the GUI but don’t know if I am in the right place!

I understand the problem but didn’t find the way to go… I need a trigger that does:

  1. check SOC
  2. if SOC is above value and
  3. if power is above value do
  4. switch device on

I think that this will need a different trigger type, probably a numeric state trigger. I checked the documentation (/automation/triggers) and got lost when it came to the value_templates.

Maybe someone would be so kind to give my the little code I need to replace mine?

domain…
triggers:
- trigger: numeric_state
entity_id:…

Very best regards and many thanks in advance!
German

First off if posting code please format it correctly as per this post

Secondly use state as the trigger rather than device, it will provide better results.

And most of all you have described what you want well and if we look at that.

You use the state of SOC as the trigger, no need for values above or below just when it changes.

Next the “if” part you will use a condition for (the and if section) and use numeric state for the that, and pick you SOC.

Then in the “then do” section use switch and pick your switch.

Hope this helps, but please ask for more info if you need it.

You had the right ideas, you just need to get an idea of the terms HA uses.

This page and the pages that follow may also help.

Dear Arh, first of all thank you very much for your friendly and fast reply!

I struggle getting the very first part of the logic done.

The doc says " the state trigger fires when the state of any of given entities changes" but in my case that value (SOC) does not change. The result of the GUI generated code is to read the current state and proceed with the next step (condition) only if the current value (SOC) is above something.

Since my SOC does not change but has a certain value I got confused.

May I have to revert the logical order like this?

The trigger is not SOC (battery_level) but the generator output (is_power) that changes above a given value whilst SOC is the condition.

Something like this:

listen to a change of “is_power”
if value changes “above x”
and if SOC is “above z”
than switch on

If that is correct could I just scramble the codes order and do this?

alias: HWW on
description: ""
triggers:
  - type: is_power
    condition: device
    device_id: 1cc9617b89dbfe6c4078185134a46042
    entity_id: cf513bb4a603808f2ee943d1505a3c28
    domain: sensor
    above: 1250  
conditions:
- type: battery_level
    device_id: 1cc9617b89dbfe6c4078185134a46042
    entity_id: 9ce89635e286728db77c177e01313992
    domain: sensor
    trigger: state
    above: 20
actions:
  - type: turn_on
    device_id: f2a7994746d6191a39520e71aa155d89
    entity_id: ba7d37e2a42b38716f6bb0dcabca2a8c
    domain: switch
mode: single

→ causes indentation error in line 12 row 14… I will try this one next

alias: HWW on
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.xyz_interne_leistung
    above: 1250
conditions:
  - condition: numeric_state
    entity_id: sensor.xyz_ladezustand_soc
    above: 25
actions:
  - type: turn_on
    device_id: f2a7994746d6191a39520e71aa155d89
    entity_id: ba7d37e2a42b38716f6bb0dcabca2a8c
    domain: switch
mode: single

Have to see what happens tomorrow when there is some light I guess. Haven’t found a test procedure in HA yet :slight_smile:

vbr
German

Heading the right direction I think.
More to think about. Why and how to avoid device_ids in automations and scripts

The second option is going in the right direction but as pointed out above, try to use entities instead of devices,

try this sort of thing as the action.

action: switch.turn_off
metadata: {}
data: {}
target:
  entity_id: your switch

Unfortunately the automation did not work at first.
After restarting HA i did…

After reading your remarks on device ids I did this:

alias: HWW on
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.fsp4f1c0ee_interne_leistung
    above: 1250
conditions:
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_ladezustand_soc
    above: 20
actions:
  - action: homeassistant.turn_on
    target:
      entity_id: switch.hww
    data: {}
mode: single

I can manually fire the trigger (switch HWW on) so the action (generic switch) seems to be ok…

SOC was down BELOW treshhold (20%) in the morning and than changes/loads.
At the same time power was ABOVE trigger value PRIOR to condition (SOC) reaching required minimum.

Q: will this kind of automation permanently listen/read the values of both SOC and power output?

You are still in that trap with the trigger. If you trigger above a value like you have, it will only trigger if the value goes from below to above the value you set. So if it is already above that value it will not trigger. This is why you remove that value and add it as a condition.

Something like this maybe, I have just written this with cut and paste here so not tested and some bits may be wrong but you will get the idea i’m sure.

alias: HWW on
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.fsp4f1c0ee_interne_leistung
conditions:
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_ladezustand_soc
    above: 20
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_interne_leistung
    above: 1250
actions:
  - action: homeassistant.turn_on
    target:
      entity_id: switch.hww
    data: {}

copy. I added a second condition (the entity_id first used as trigger).
Will see tomorrow and let you know if it works.

→ Many thanks for your help!!!

NEXT will be to schedule and prioritize loads (automations). E.g. electrical_floor_heating bathroom on from 6 to 8 (and 18:00 to 21:00) if SOC is above x else set water_heating_thermostat to desired temp,

I guess I also have to find out how to prioritize a set of (at certain times) concurrent automations like P1 floor heating bathroom, P2 floor heating kitchen, P3 charging the car, P4 filling the pond etc.

To proceed to phase 2 I ordered hardware to “smarten” my electrical floor heatings (DEVI.reg touch).
Looks like I will have to use a WLAN thermostat (€35 @JeffsOnlineShop). Can’t find a Zigbee one…

To add devices (sensors and actors) I prefer Zigbee. SONOFF Dongle, plug and temp/hum sensor are on the way.

To do multiple options as actions you can use the choose option, this will allow you to set a condition for each action which can be a time or temperature or anything really.

As fro the thermostat stuff, you can use the generic thermostat with any temperature sensor and switch.

:+1: more work to do and more money to spend due to your great input :slight_smile: will use that thermostat for starting an airpump in the pond to open a fish breathing hole in the winter or to add oxygen when water is very warm. Which forces me to invest in a DP2000 weather station and sensors.

Oh dear… Really nice what HA can do.

Hello Arh,

the suggested automation does not work either.

alias: HWW on
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.fsp4f1c0ee_interne_leistung
    above: 1250
conditions:
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_ladezustand_soc
    above: 20
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_interne_leistung
    above: 1250
actions:
  - action: homeassistant.turn_on
    target:
      entity_id: switch.hww
    data: {}
mode: single

Failing with such a simple task currently reduces my enthusiasm somewhat…
Well looks like I have to dive deeper and find another solution

Best regards
Holger

Like this, with the above 1250 removed. Its not needed.

As I described earlier with your yaml it will only trigger when the sensor goes from below 1250 to above.1250 if the soc is below 20 when it triggers it will never run.

alias: HWW on
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.fsp4f1c0ee_interne_leistung
conditions:
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_ladezustand_soc
    above: 20
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_interne_leistung
    above: 1250
actions:
  - action: homeassistant.turn_on
    target:
      entity_id: switch.hww
    data: {}
mode: single

I think you describe what I want but I don’'t really understand what you say :wink:

I tried to do this:

Trigger HWW on
IF output is above 1250W
AND (at the same time) SOC is above 20%

Basically I want the battery charged first and afterwards, if there is enough solar power for my “daily” workload, switch certain “less important” loads in a certain order on.

One reason for this is that I have an automatic 3-phase backup of the whole environment and want to assure a certain SOC is available in case of an outage and until a gen can jump in.
I know that I could set the minimum SOC level of the battery to 20% but that seems to be way less flexible.

So it is correct that the trigger will never fire when the SOC is below 20%.

If you use the yaml I provided above, it will trigger every time the output changes. It will then check if the output is above 1250, and the soc is above 20, if both conditions are met it will run.

Forget trying to trigger above 1250, as i keep saying its not needed.

Check your automation traces to see how it works.

I can’t save the YAML if I remove the “above” line (or replace the whole code with yours).
→ Message malformed, must contain at least one of above. below

Solution: check if STATE of PV output changes, than check conditions and trigger if ok:

alias: HWW on
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.fsp4f1c0ee_interne_leistung
conditions:
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_ladezustand_soc
    above: 20
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_interne_leistung
    above: 1250
actions:
  - action: homeassistant.turn_on
    data: {}
    target:
      entity_id: switch.HWW
mode: single
`´`

Its the 3 dots at the end, not sure how they git there :slight_smile: try this

alias: HWW on
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.fsp4f1c0ee_interne_leistung
conditions:
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_ladezustand_soc
    above: 20
  - condition: numeric_state
    entity_id: sensor.fsp4f1c0ee_interne_leistung
    above: 1250
actions:
  - action: homeassistant.turn_on
    data: {}
    target:
      entity_id: switch.HWW
mode: single

Don’t know about these dots either. Probably the cat walked over the keyboard :slight_smile: but as said my code worked today. Let’s see how it does for some days. Due to the April kind of weather we are going to see most all possibel combinations of SOC and output. Thank you for your assistance and be sure that you will hear from me again :slight_smile: VBR Holger