Turn on Switch for a Period of Time, Every 30 Minutes, Based on Outdoor Temperature

When the outside air temperature drops to a certain value or below, I would like to turn on a switch every 30 minutes, but only leave it on for x number of seconds. Then repeat at every 30 minute interval thereafter until the temperature rises above my threshold.

My use case is that I have an Insteon relay on a water valve that I use to fill my pool. When the outside temperature dips into the teens, the buried water line has a tendency to freeze. I solved this in the ISY application by turning the valve on every 30 minutes or so, and letting it run just for a couple of seconds. This water movement seemed to be enough to prevent freezing.

Currently, the relay is controllable from within HA, and the temp sensor info from a hyper-local weather service API has been pretty accurate, so I think I have what I need to do this.

Everything except the programming know-how, that is. I’ve been looking at triggers and timers, but have only determined that I am going to need some help.

You can use 2 time pattern triggers 30 minutes apart as the triggers and the temperature below whatever value you want as the condition.
Then it’s just a matter of turning the relay on, waiting for a few seconds to pass and then turning it off.

Thanks, Adam,

I’m confused as to why it would take “two time pattern triggers 30 minutes apart,” and then how to add the delay.

I created an automation based on what I think you suggested, which built the following in my automations.yaml file:

- id: '1703912394597'
  alias: Pool Fill Freeze Protect
  description: ''
  trigger:
  - platform: time_pattern
    minutes: /30
  condition:
  - condition: numeric_state
    entity_id: sensor.my-weather-service_temperature
    below: 20
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.i_o_linc_21_f3_8b_relay
    data: {}
  mode: single

This obviously doesnt work. Could you maybe give me another nudge?

I was just thinking about setting it to run at the same time every hour (e.g. 15 and 45 minutes past the hour) so you know when it runs but what you have does the same thing. I just like knowing when things should run.

What you have should turn it on. What does the automation trace show?

You can add this between your switch.turn_on and your mode: single. Change the 05 to however many seconds you want to wait.

    - delay: '00:00:05'

    - service: switch.turn_off
      target:
        entity_id: switch.i_o_linc_21_f3_8b_relay

Oh, I see. Yeah, this was more for triggering on a weather event. If the temperature were to drop into the range where I tend to experience issues, I wouldn’t want to wait until the next scheduled time.

I didn’t realize there was an automation trace, but I see it now, so thank you! I haven’t done too much in HA, but need to start using the tools available to help troubleshoot my efforts.

Thanks to the both of you. I tested this out using current temperatures, and it triggered and for the run time desired. Here’s my final code:

alias: Pool Fill Freeze Protect
description: ""
trigger:
  - platform: time_pattern
    minutes: /30
condition:
  - condition: numeric_state
    entity_id: sensor.pirateweather_temperature
    below: 25
action:
  - service: switch.turn_on
    target:
      entity_id: switch.i_o_linc_21_f3_8b_relay
    data: {}
  - delay: "00:00:05"
  - service: switch.turn_off
    target:
      entity_id: switch.i_o_linc_21_f3_8b_relay
    data: {}
mode: single

Adam, thanks for getting me off to a good start, and Mike, you provided the last bit that got this working. In hindsight, I feel sort of silly now, seeing how simple it was - I think half the battle is knowing which tools to use.

Thanks, again!

You can add another trigger for temperature < 25 and it will run the first time the temperature drops so you don’t have to wait for the next scheduled time for it to run.

Good idea- thanks!