Rainmachine Irrigation Controller

Ah, that’s the issue: you’re copying from the dev branch, but this PR hasn’t been merged into dev yet. Try this: https://github.com/home-assistant/core/tree/fa414c6338e08a2910089da8e2cc5cb192cbcb91/homeassistant/components/rainmachine

Great, that worked. Thanks for pointing me to the right area. So if I’m reading the available options correctly, I can specify a program_id or an entiity_id. Out of curiosity, would it be possible to pause by device? To give you insight in what I am trying to accomplish… I have a well supporting my irrigation system and the well cannot keep up with the irrigation water demand. My hope is to create an automation which will pause the irrigation device(s) when the well pressure gets below a certain level and resume the device when it gets above a certain level (as measured by my well pressure transducer). This would be a pause/resume regardless of what schedule and/or entity might be running at the time. Secondly, my hope would be to pause one controller schedule while the other controller is running to ensure they two are never running at the same time (which would produce even more demand on my well). I’m of course open to any suggestions you may have regarding this. Thanks!

Not quite – in the case of program-based services, you will always provide both a program_id and an entity_id (or, if that feels strange, there’s another option1).

The idea is that:

  • The entity_id tells the service which RainMachine controller to target
  • The program_id tells the service which program on that controller to target

1It’s a little wonky to provide an entity_id to these service calls – you’re not really executing the service on that entity, but rather using that entity as a somewhat-unclear way to reference the controller. I recently learned about another method that may be clearer.

You’ll recall that HASS carries the idea of a “device” that can contain multiple “entities.” In our case, a RainMachine controller is a device and all of its switches/sensors/etc. are entities. It turns out that a recently merged (undocumented) PR allows you to specify the device_id in the service call instead. So, for instance, I can call the rainmachine.start_program service with this payload

device_id: <CONTROLLER_DEVICE_ID>
program_id: 1

The <CONTROLLER_DEVICE_ID> value isn’t represented in the UI, but you can find it by navigating to Configuration -> Devices, clicking on the RainMachine controller in question, and then looking at the URL (which will be of the form http://localhost:8123/config/devices/device/<CONTROLLER_DEVICE_ID>).

Again, this is totally optional and discretionary – you can stick with using entity_id if you like, but if this device_id route seems clearer (as it does to me), it’s available.

Yes: simply use the rainmachine.pause_watering service and, per the above, provide either a device_id for that controller or an entity_id belonging to the controller as the payload:

device_id: <CONTROLLER_DEVICE_ID>
seconds: 30

Note because the RainMachine API requires it, this service call requires you to input a number of seconds to pause before resuming; this ties into your next point:

I think we have all the pieces to accomplish what you want. You’ll have an automation (or multiple automation, if you prefer) that monitors the well pressure and calls rainmachine.pause_watering or rainmachine.unpause_twice appropriately.

The only “gotcha” here is that seconds argument that is part of the rainmachine.pause_watering service payload. Do you know how long it takes your well pressure to return? If so, you could give a seconds value that you know will always exceed that time.

Aaron,

Thank you so much for the detailed response. As I’m still new, this is going to take some time to digest, but I’ll certainly take the time for that. Really appreciate your feedback and detailed explanation.

Chandler

My pleasure! Let me know if you have questions. :+1:

ok, so I think I have come up with a solution for having only one controller running at a time, but would like your thoughts on it. The idea have an automation which pauses controller a when controller b is running. Below is a copy of the automation. Basically, I believe I am using the restart mode correctly where as after a 15 minute pause, the automation would re-run and pause again. This way controller B is basically being re-paused every 15 minutes when controller a is watering. If this looks good, I can go in and re-create this for controller b when controller a is watering. thoughts? As a note, I do have two schedules for controller a and am only referencing one of those schedules here (summer) as I believe I will not have an interference problem in the winter time (only using 4 of my 15 zones).

thanks!

Update:

This seems to work in all aspects except it only fires once. After the pause time is up, it resumes the controller B schedule whether the “winter” schedule is running or not… Any ideas or thoughts are appreciated and welcomed.

alias: Irrigation Controller Prioritization
description: Only one irrigation controller running at a time
trigger:
  - platform: device
    type: turned_on
    device_id: 9e579e51a208a708ba6a5a73cc0db59a
    entity_id: switch.pool_house_irrigation_controller_schedule
    domain: switch
condition:
  - condition: device
    type: is_on
    device_id: 884c6e915acbef7c10be5e515550d35c
    entity_id: switch.summer
    domain: switch
action:
  - service: rainmachine.pause_watering
    data:
      device_id: 9e579e51a208a708ba6a5a73cc0db59a
      seconds: 1800
mode: restart

I’m not totally clear, but this automation only has a trigger for one device and only has a condition for the other device – that may be intentional, but as I see it, this could cause issues (i.e., this automation only reacts when the pool house controller is turned on – not when it turns off, not when the other controller turns on/off, etc.).

ok, I did a really bad job of trying to explain what I am trying to accomplish, apologies for that. Let me try again…

I have two controllers which run independent schedules and to my knowledge there is no way via RainMachine to ensure they are not running at the same time. Hence I’m trying to create an automation in HA which will take care of this for me. Ultimately the goal would be to have each controller “poll” the other controller and see if it is running. If it is, it would pause itself until the running controller had completed its program. Once completed, they other controller would be able to run its program as normal.

My current setup:
Controller A, which has 15 zones, starts at 10PM every night and runs its schedule. Since I have a limited amount of well capacity, this schedule can take anywhere from 12 to 18 hours to complete. Controller B’s schedule (which has only 4 zones) is currently set to start at 1PM and run until completed. Again, depending on the time of year and my well capacity, this schedule can take anywhere from 6 to 8 hours. As one can see, these two schedules have the potential to overlap and I just want to ensure they don’t run simultaneously or they will probably never finish due to lack of well capacity. I’m sure that in the Texas summers in July and August, I could definitely be laying water down 24 hours a day potentially, but I believe this is the exception and not the rule for the entire year.

I hope this helps explain better… If I can be of further assistance, please let me know. As always, appreciate any and all insight you can give me into solving my conundrum.

Awesome, appreciate the detail! Let me think on this a bit and get back to you.

Alright, here’s what I have so far – may not be the full, final solution, but it’s a step further. Note that this assumes that my PR is merged (I think you already have it as a custom component).

Take a look at this bit of YAML:

---
automation:
  - alias: "Manage RainMachine Controllers"
    trigger:
      - platform: time
        at: "13:00:00"
      - platform: time
        at: "20:00:00"
    action:
      choose:
        - conditions:
            condition: template
            value_template: "{{ trigger.now.hour == 13 }}"
          sequence:
            - wait_template: >
              {{ is_state("binary_sensor.controller_a_running", "off") }}
            # ...
        - conditions:
            condition: template
            value_template: "{{ trigger.now.hour == 20 }}"
          sequence:
            - wait_template: >
              {{ is_state("binary_sensor.controller_b_running", "off") }}
            # ...

binary_sensor:
  - platform: template
    sensors:
      controller_a_running:
        value_template: >-
          {{
            is_state("switch.controller_a_program_1", "on") or
            is_state("switch.controller_a_program_2", "on") or
            is_state("switch.controller_a_zone_1", "on") or
            is_state("switch.controller_a_zone_2", "on")
          }}
      controller_b_running:
        value_template: >-
          {{
            is_state("switch.controller_b_program_1", "on") or
            is_state("switch.controller_b_program_2", "on") or
            is_state("switch.controller_b_zone_1", "on") or
            is_state("switch.controller_b_zone_2", "on")
          }}

This does two things:

  1. Defines two binary sensors that can tell you if a controller is running or not – note that you’ll probably want to adjust these with your own entities. (I really should add these entities in the integration itself…)
  2. At 10pm and 1pm, the automation runs, waiting for the other controller to be finished before starting (I left ... in place for whatever services you want to define).

Just some quick thoughts. Any initial questions/concerns?

Hey @bachya,

Can’t say thank you enough for this. Apologies for my delayed response due to the holidays. Same disclaimer as before being a noob, and it will take me a few days to digest and test, but am excited to do so. Will get back to ya, thanks again!

1 Like

ok, FINALLY had a break from holidays and family to give this a try. I believe I have defined entities correctly, but I’m getting an error "message malformed required key not provided @ data[‘action’]. I’m assuming I somehow mis-copied and pasted and have messed up my spacing, but can’t seem to find the error. thanks!


automation:
  - alias: "Manage RainMachine Controllers"
    trigger:
      - platform: time
        at: "13:00:00"
      - platform: time
        at: "20:00:00"
    action:
      choose:
        - conditions:
            condition: template
            value_template: "{{ trigger.now.hour == 13 }}"
          sequence:
            - wait_template: >
              {{ is_state("binary_sensor.controller_a_running", "off") }}
            # ...
        - conditions:
            condition: template
            value_template: "{{ trigger.now.hour == 20 }}"
          sequence:
            - wait_template: >
              {{ is_state("binary_sensor.controller_b_running", "off") }}
            # ...

binary_sensor:
  - platform: template
    sensors:
      controller_a_running:
        value_template: >-
          {{
            is_state("switch.summer", "on") or
            is_state("switch.winter", "on") or
           
          }}
      controller_b_running:
        value_template: >-
          {{
            is_state("switch.pool_house_irrigation_controller_schedule", "on") or
          }}

Also, I tried to re-create the animation using the UI, that seems to fix the formatting, but I don’t see how to define the binary sensor. When I take what I have created in the UI and edit as YAML and try to add the binary sensor info, I keep getting the error "extra keys not allowed @data [binary_sensor], trying to read up on this, should this info be placed in my main configration.yaml file instead of inside the animation? thanks again…

Hard to tell where that error is coming from without seeing your entire configuration.yaml. Does the log message give you a line number?

Hey Aaron,

To be clear, should I have this code in my configuration.yaml or my automation.yaml? Maybe I’m adding in the wrong place…

The automation can be added in either, or via the UI (which ends up adding it to automations.yaml). The binary sensor needs to be added to configuration.yaml.

ok, update. After teaching myself a little bit about visual studio and the home assistant helper, I’ve been able to debug all the errors (turned out I had a spacing issue). binary sensor is not in configuration.yaml and the automation piece has been created via the UI in HA, will start testing and report back.

thanks again for all your assistance!

1 Like

I am trying to get the Flow Sensor to report how much “leakage”. I only see that it report “off” on my system even though it is on. Any help would be appreciated. It looks like my entities are unavailable. How do I go about making them available?

Can anyone tell me If they have clicks and consumption working?

Do I need to add any specific yaml info to get that part of the integration to work?

I’m the integration author. Unfortunately, I don’t have a flow sensor, so I can’t test directly. That said, feel free to open an issue in the regenmaschine project (the underlying library that powers the integration), and I can help you debug.

Hey @bachya ,

Hope you are well sir. Need a little assistant whenever you have a free moment. I have my two binary sensors up and running for both my controllers, but I’ve been testing out a new animation and am not able to figure it out. I’m basically trying to pause one controllers program when it starts if it detects the other program is still running. See below

id: '1626385140990'
alias: Irrigation Sequencing Pause
description: Start Secondary Controller After Primary
trigger:
  - platform: state
    entity_id: binary_sensor.controller_b_running
    from: 'off'
    to: 'on'
condition:
  - condition: state
    entity_id: binary_sensor.controller_a_running
    state: 'on'
action:
  - service: rainmachine.pause_watering
    data:
      seconds: 86400
    target:
      entity_id:
        - switch.back_yard
mode: single

When this automation fires, I get the below message. Do I need to somehow update the long lived access token for this to work correctly? Let me know if I can provide any further information.

thanks again!