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?