Rain Machine run times

I’m having the same issue as many others from what I’ve seen. When Rain Machine runs a program, all zones in the program are set to ON. I would like to know which zone is actively running only. In the integration, the Zone Completion Time is displayed as “In xx minutes” or “xx minutes ago” etc. I tried making sensors based on this, then realized there is already some math and conversion being done to display it that way in the integration since the actual sensors are timedate only. I have looked at these sensors while zones are running or not and cannot seem to make sense of the stamp. Has anyone been able to do anything like this or have any ideas?

Well, after two days of scouring this forum and testing, I finally found a solution. I hope this helps someone.

Basically, each zone (switch) in a watering program is turned on simultaneously when that program runs, but the run_completion_time sensor doesn’t show as future until the zone is actually running. So, you can compare each zone’s run_completion_time to the current time (both as unix timestamps) and if the current time is greater, the zone isn’t running yet, if it’s less, it is running. So you have to set up some sensors in config:

  - platform: template
    sensors:
      real_time:
        friendly_name: "Unix Timestamp"
        value_template: "{{ as_timestamp(now()) }}"

  - platform: template
    sensors:
      zone_x_unix:
        friendly_name: "Zone x Unix"
        value_template: "{{ as_timestamp(states('sensor.sprinklers_zone_x_run_completion_time')) }}"

  - platform: template
    sensors:
      zone_x_on:
        friendly_name: 'Zone x Sprinklers'
        value_template: >-
          {% if (states('sensor.real_time') < states('sensor.zone_x_unix')) %}
            on
          {% else %}
            off
          {% endif %}

Set a timestamp and comparison for each zone then, instead of displaying the status of the switch, you display the status of the sensor (you can use a call_service command to toggle the appropriate switch). It does take up to a minute for the completion_time to fall behind the current time, but now, if you have all your zones displayed, only the active one will show as on.

2 Likes

Thanks for sharing this. I was wondering where the timer was… So you had to create 3 templates for each zone?

Just two for each sprinkler. The first one in the above code is just a sensor to convert the current time to UNIX. It is used to compare each sprinkler’s end time.

Got it. I guess I misunderstood what this templating did exactly. I was thinking this was going to show the time remaining per zone, but it seems like it just shows if that particular zone is ON or OFF. I’ll have to see if I can figure out how to get this information surfaced in HA reliably.

Just curious, how are you using this in your dashboard? Could you share an image?

The run completion time (for each zone) is built into the integration. I am simply converting that to a UNIX timestamp format and comparing it to the current time (also in UNIX format). My purpose was to show only the running zone, not every zone in the program as running simultaneously.


Got it, thank you for sharing.

Was there an issue with the attribute of “status” under the integration switch to determine the state of the individual sprinkler (running, queued, not running, etc.)?

I found this thread because I was looking for a way to replace most reasons for opening the RainMachine app since the Completion Time Sensors don’t appear to provide information like time remaining per zone (unless I’ve missed it). In case this is helpful to anyone else, here’s what I’ve done in my setup. Let me know if anyone sees areas for improvement!

Goal - create countdown sensors for each Zone and a sensor that shows total remaining time for all zones when running a program. Effectively, remove the most common reasons I would open the RainMachine app instead of Home Assistant.

Requirements

  • Add RainMachine Integration via native connection → this one provides more detailed attribute detail about each zone.
  • Add RainMachine Integration via Homekit connection → this one provides an attribute for remaining_duration
  • Add multiple-entity-row via HACS → optional, but is what I used to organize my zones with key information in a single card in my dashboard.
  1. Create Template sensor to display time remaining for each zone. e.g. here’s an example of one of the sensors I added to my template.yaml file.
- sensor:
    - name: "<INSERT ZONE NAME> Time Remaining"
      unique_id: <INSERT_ZONE>_time_remaining
      state: >-
        {% set duration = state_attr('switch.<INSERT_HOMEKIT_RAINMACHINE_ZONE_SWITCH>', 'remaining_duration') %}
        {% set minutes = duration // 60 %}
        {% set seconds = duration % 60 %}
        {{ '{:02d}:{:02d}'.format(minutes, seconds) }}
  1. Create Template sensor to add up the zones to show Total Time Remaining. e.g. here’s my example:
- sensor:
    - name: "RainMachine Total Time Remaining"
      unique_id: rainmachine_total_time_remaining
#      unit_of_measurement: time
      state: >-
        {% set durations = [
          state_attr('switch.<INSERT_HOMEKIT_RAINMACHINE_ZONE_SWITCH_1>', 'remaining_duration') | default(0),
          state_attr('switch.<INSERT_HOMEKIT_RAINMACHINE_ZONE_SWITCH_2>', 'remaining_duration') | default(0),
          state_attr('switch.<INSERT_HOMEKIT_RAINMACHINE_ZONE_SWITCH_3>', 'remaining_duration') | default(0),
        ] %}
        {% set total_seconds = durations | select('number') | sum %}
        {% set minutes = total_seconds // 60 %}
        {% set seconds = total_seconds % 60 %}
        {{ '{:02d}:{:02d}'.format(minutes, seconds) }}
  1. Use multiple-entity-row to create a card that aggregates the zones and information into a consolidated view for the dashboard. e.g. here’s my example:
type: entities
entities:
  - entity: switch.<RAINMACHINE_PROGRAM_FROM_OFFICIAL_INTEGRATION>
    secondary_info: last-changed
  - entity: sensor.rainmachine_total_time_remaining
    type: custom:multiple-entity-row
    secondary_info: last-changed
  - entity: switch.<INSERT_RAINMACHINE_ZONE_1>
    type: custom:multiple-entity-row
    toggle: true
    secondary_info:
      attribute: status
    entities:
      - entity: sensor.<INSERT_ZONE_1_TIME_REMAINING>
        name: false
  - entity: switch.<INSERT_RAINMACHINE_ZONE_2>
    type: custom:multiple-entity-row
    toggle: true
    secondary_info:
      attribute: status
    entities:
      - entity: sensor.<INSERT_ZONE_2_TIME_REMAINING>
        name: false
  - entity: switch.<INSERT_RAINMACHINE_ZONE_3>
    type: custom:multiple-entity-row
    toggle: true
    secondary_info:
      attribute: status
    entities:
      - entity: sensor.<INSERT_ZONE_3_TIME_REMAINING>
        name: false

and here’s what this looks like in my dashboard:

The "00:00"s update with actual numbers when the zones are live, the total provides a total from all of the zones that are active, the “Not Running” shows which zone is running and which ones are queued, and the toggle turns the zone on/off. The toggle also will start the individual zone using the configuration settings on the RainMachine integration (Default 600 seconds).

Thanks for figuring this one out. Is this still the most current solution? Wanted to check there was no more elegant approach before I created dozens of new sensors, Cheers