Home Assistant Automation - Help :)

Hi all,
so I have Victron stats and some minor switches integrated into Home Assistant but I would now like to do my first automation.
I would like to Switch my pool pump on and off based on Victron SOC.

Pool Pump is controlled via Ewelink switch that is integrated into HA.

I have tried to go to Configuration/Automation and attempted to create what I want but have failed :frowning:


Slightly off topic; how are you finding the PoolSense? Thinking of getting one.

As for the automation; you can do that in the automations section of HA, and use the SOC as the trigger for the Pool pump. Do might want to use PV value as well. I have my pool come on when PV + SOC are above a certain level and then switches off when PV drops off.

I’m not at my PC so can’t type a lot, but maybe this code of mine help:

#Set maximum inverter power based on PV generation before sunset and battery full

 - alias: Set Maximum Inverter Power Based on PV Generation before SOC 100 and Sunset
    trigger:
        platform: state
        entity_id: sensor.DC_from_PV
    condition:
        condition: and
        conditions:
        - condition: sun
          before: sunset
        - condition: sun
          after: sunrise
        - condition: template
          value_template: "{{ (states('sensor.Battery_SOC')|int) < 100 }}"
    action:
        service: modbus.write_register
        data_template:
            unit: 100
            value: "{{ states('sensor.dc_from_PV')|int / 10 + states('input_number.input_maximum_battery_discharge_after_sunrise_before_battery_full')|int / 10 }}"
            hub: victron
            address: 2704

PoolSense is ok and assists with keeping the pool water healthy :slight_smile:
I would say it is useful as it was a chore to keep taking water samples to pool shops and those testing strips where a bit clunky for me. PoolSense tells you what you need to add to keep the levels right.
My pool water is clear so no complaints.
One of the downsides is that, as per their advice, the device battery last 2+ years and can’t be replaced so once done - you have to get a new one.

Hope this helps :slight_smile:

I am failing to enable this automation :frowning:

I added the “On” under state as there are no options there, and I also typed the number and added % sign…

Have you tried looking at my code? I do something similar, change the inverter’s max power based on the PV generated by the solar panels (before the SoC reaches 100).

It should help you with the syntax to get it going in your automations config file.

I’m not at all good at coding in HA, but it seems to get the job done.

This is my automations.yaml

  • id: ‘1626624185260’
    alias: Pool Pump ON by the Battery SOC
    description: ‘’
    trigger:
    • platform: numeric_state
      entity_id: sensor.battery_soc
      above: ‘70’
      condition: []
      action:
    • condition: state
      entity_id: device_tracker.switch_pool
      state: ‘On’
      mode: single

but its not working :frowning:

I’m not great with YAML, but what worked for me was to have trigger the sensor that should be monitored (or the like) and the condition the state that should exist for the action to be taken.

You don’t seem to have any condition specified? You can see in my code where I called the condition that my SoC should be < 100 (for this specific automation’s action to be executed).

Hi @Bobby

This yaml doesnt do anything, there is no “Action”
Have you designed this in the UI or purely from yaml?
My advice is to use the developer tools and confirm you are looking at the correct entities.
Reading the yaml you are looking for a condition where a device tracker has a state of “On”.
Is this correct?

I missed this post.

Your Action is wrong, you want to “call a service” or have a “device” selected to turn on.

Hi @C.Potgieter,
yes, this is created by Automations under Configuration. I don’t really know how to create this manually, I only search for things and then copy/paste

Ok, I will try to use “call a service” or “device” under Action
I noticed that as well that when created in Automation, there was no action next to the Trigger…

EDIT:
I just noticed that the when I select the device, there is no Actions defined (I am using the Sonoff LAN integration via HACS)…

I also tried at first to use the “wizard” to make automations. I found it so confusing that I rather just figured out how to do it manually.

Steps:

  1. Do you have all the sensors and switches loaded that you want to automate
  2. Can you observe their values, switch them on and off manually
  3. Understand really well what the conditions are you want for the automation - Really think about this, because many of these things are more complicated than you originally think. I find that I have this tendency to simplify something while thinking about it but when it comes to putting pen to paper, so to speak, I realise there is more nuance.
    You don’t want the pool pump to go on and off constantly, for example, and don’t want the pool pump to go off when you manually wanted it to be on, etc. etc. etc. So many things to keep in mind. Really try and distill it down to the bare basics of what you need. Code that. Then add refinements as shortcomings become apparent to you.
  4. Only now try and implement an automation yaml.

If you look at the code I wrote, you really want to do something very similar, perhaps:

 - alias: Trigger Pool Pump
    trigger:
        platform: state
        entity_id: sensor.Battery_SOC
    condition:
        condition: and
        conditions:
        - condition: sun
          before: sunset
        - condition: sun
          after: sunrise
        - condition: template
          value_template: "{{ (states('sensor.Battery_SOC')|int) > 90 }}"
    action:
        - data:
          entity_id: switch.pool_pump
          service: switch.turn_on

Something like that? I don’t know what your pool pump’s name is. Mine would be “switch.switch_pool_pump” but I don’t use it in an automation yet. There’s many HA wizzes (not me) on this forum and they have posted a lot of code already. That is where I learned everything I needed to know, just by reading their code and figuring out the syntax (partially - still a hit and a miss).

As an aside, all my SONOFF switches I flashed with Tasmota. Really easy, no soldering required. I find that it just works flawlessly on HA that way. Haven’t tried anything else though.

Yeah, you can just hold the pins inside the through-plated holes, and flash it quite easily. But I generally prefer to solder some pins into mine. The one exception was the RF bridge. There is no space to fit the pins under the big LED pad that sits on top of the board, and that is when I remembered that you flashed yours by just holding the pins to the holes :slight_smile:

It was actually based on Jaco’s suggestion! He helped me to get started with those Sonoffs. They’ve been running great now for months. The one switching my pool pump has saved me so much time and hassle…

@Bobby I just thought of another situation you probably want to avoid: If you set your ESS mode to keep batteries charged, you probably don’t also want to turn on your pool pump after a while…

I had to do some sniffing around, I flash my sonoffs, dont use them with sonoff lan.

My suggestion would be to use “call a service”
the service you are calling is “switch.turn_on” and you should be able to select the switch that youve added on your “management” page

Do you think that the code I gave above would work (at least to switch the pool pump, not necessarily having the conditions ironed out):

I think it should, obviously depending on the names he gave to his SoC sensor and pump’s switch.

As a basic automation yes, this will work just fine, presuming you would have an automation to turn it off too based on soc or sunset. Ive seen some “smarter” options, where the automation turns the pump on for 15mins and then turns it off again. Catering for a drop in SOC with a single automation. This way the pump only runs for 15mins and if SOC drops below 90 it wont switch on again until it reaches 90, as you trigger on ever state change for SOC.

One of the biggest learning curves for HA automations is trigger vs condition and when to use them, and knowing that sometimes you need to check your values in both.

For complex scenarios like a pool, nodered works great for automation too.

I cycle my batteries…got lithiums so set down to 30% but they reach 55-60% over night

I put in the code but it is giving me an error :frowning:


bad indentation of a mapping entry at line 2, column 12:
trigger:

I tried changing the indentation of the “trigger:” but that didn’t resolve it :frowning:

Alias, trigger, condition and action should all have the same spacing. At your alias, try adding two spaces in front of the “-”?

I’m still not really sure about HA and indentation. I find it frustrating to say the least… But how I explained it is how I have it on my side.

Everything from line 2 down needs to move 1 “tab space” backwards.

Have you changed the sensor and entity names to match your setup?