Turn on RF outlet for one hour? Help please

Hi all,

Very new to HA but loving it. So far i have a few RF outlets, sonoffs and yeelights but looking to incorporate more devices soon.

Hopefully someone can help me with turning on an RF outlet(switch.switch_1) for one hour. I have these installed for electric heaters and lamps and would love this feature. I dont want specified time in the day but just on for 60 mins then off again.

I know im asking you guys to do all the hard work but i tried reading the supporting documentation for automation and cant really make sense of it.

Also, If i did get it to work would i be able to still turn on the heater with the toggle switch like norma or would it override this. Can i have both or is it an either or?

Thanks!

Hey,

This is what I’m using for my hall light when getting ready for work. It turns on at 6:15 am and the turns off after 10 mins. Only on work days.

## Turn on Hall Light when leaving for work
  - alias: Turn Hall Light On At 6:15
    trigger:
      platform: time
      at: '06:15:00'
    condition:
     - condition: time
       weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
    action:
      - service: homeassistant.turn_on
        entity_id: switch.front_hall_light_switch
      - delay: '00:10:00'
      - service: homeassistant.turn_off
        entity_id: switch.front_hall_light_switch
1 Like

I do this with a sports equipment dryer connected to a z wave switch. I can set the length of time I want the dryer running using an input_number. It is an automation that calls a script to handle the on/off and timer. This is probably overkill, but works for my needs.

here’s the input_number:

  equipment_dryer_hours:
    name: Hours
    icon: mdi:clock
    min: 0
    max: 12
    step: 1

and the automation:

  - id: equipment_dryer
    alias: 'Equipment Dryer'
    trigger:
    - platform: state
      entity_id: switch.appliance_switch_switch
      to: 'on'
    action:
    - service: script.turn_on
      entity_id: script.equipment_dryer_timer

and the script:

  equipment_dryer_timer:
    alias: Equipment Dryer Timer
    sequence:
      - delay: '{{ states.input_number.equipment_dryer_hours.state | int }}:00:00'
      - service: switch.turn_off
        entity_id:
        - switch.appliance_switch_switch
      - service: script.turn_off
        entity_id: script.equipment_dryer_timer

For a simple solution, it could probably be done all in an automation. Here’s the pseudo code for maybe a more simple solution:

  - id: heater
    alias: 'Heater'
    trigger:
    - platform: state
      entity_id: switch.heater
      to: 'on'
    action:
    - delay: '1:00:00'
    - service: switch.turn_off
      entity_id: switch.heater
2 Likes

Ok that worked great!

But…

as you can see from the image the automation is a toggle switch and it needs to be enabled and then i need to switch on the radiator for the one hour automation. I also need to disable the automation if i want the switch to be on longer.

Is there a way to have the automation disabled most of the time and then start it by clicking one button and the switch will turn on as well?

image

I can’t verify if this would work, but in theory it should:

  - id: heater
    alias: 'Heater'
    trigger:
    - platform: state
      entity_id: automation.heater
      to: 'on'
    action:
    - service: switch.turn_on
      entity_id: switch.radiator
    - delay: '1:00:00'
    - service: switch.turn_off
      entity_id: switch.radiator
    - service: automation.turn_off
      entity_id: automation.heater

now the automation can act as your heater 1 hour timer. when the automation is off you can manually toggle the heater on/off and it will not automatically turn off unless the automation gets turned on. also if you turn the heater on manually but then later on know you want it to auto shut off, you can then toggle the automation on and it will automatically shut off the heater after 1 hour. However, the reverse will not work. you cannot start an automation and then take manual control. once the automation is started, turning off the automation will only disable it from being activated by its triggers. to take manual control of the actions, I suggest putting them into a script like I did, that way you can manually turn off the script effectively stopping the timer without shutting off the heater.

EDIT: Someone please test this. my concern with the automation is if the timing is right. If the automation has to be on prior to seeing the trigger. if it’s not on/ready and it misses the state transition, does it execute? or if it doesn’t care about the state transition and only cares if the state is ever whatever it is looking for, then trigger.

Soooo… I think I just created a “useless box” or “useless machine” in code… the script shuts itself off if it gets turned on… Although the script has a usefulness to it, at its root, it is still “useless”

example: Useless machine definition

1 Like

I set up an automation that would switch off the bathroom fan after 1-hour and it works quite well - you could just change the entityID, initial state and final state to get it to work how you want:

#Automatically turn off the ensuite bathroom fan
- alias: Ensuite fan auto off
  trigger:
  - entity_id: light.bedroom_1_ensuite_fan
    from: 'off'
    platform: state
    to: 'on'
  action:
  - delay:
      minutes: 60
  - alias: Turn off fan
    data:
      entity_id: light.bedroom_1_ensuite_fan
    service: light.turn_off

yes, that works for turning something off after a period of time after it was turned on. very similar to what I posted as pseudo code above. however, their follow up question was being able to essentially override the shutoff timer and be able to have the device on for however long they want and not turn off. for that you have to get creative with automation, scripting, and triggers.

    alias: 'Man Cave Radiator (8 Hours)'
    trigger:
    - platform: state
      entity_id: switch.switch_4
      to: 'on'
    action:
    - delay: '8:00:00'
    - service: switch.turn_off
      entity_id: switch.switch_4

  - id: radiator2
    alias: 'Living Room Radiator (1 Hour)'
    trigger:
    - platform: state
      entity_id: switch.switch_3
      to: 'on'
    action:
    - delay: '1:00:00'
    - service: switch.turn_off
      entity_id: switch.switch_3

  - id: radiator3
    alias: 'radiator test 30 secs'
    trigger:
    - platform: state
      entity_id: automation.radiator3
      to: 'on'
    action:
    - service: switch.turn_on
      entity_id: switch.switch_4
    - delay: '0:00:30'
    - service: switch.turn_off
      entity_id: switch.switch_4
    - service: automation.turn_off
      entity_id: automation.radiator3

Essentially, I want 2 toggles.
Toggle 1: Turn radiator on/off (manual button / alexa)
Toggle 2: Turn radiator on for one hour only

EDIT:
Ok i tried it 5 times and it worked one. Very odd. I realised a mistake and changed the entity id to the correct name. Very strange that it only worked once

Hey!

I added in some delay and it seems to be a bit better! Think it might be because its RF and not ZWave or wifi. Anyway, Thank you very much!

    alias: 'radiator test 30 secs'
    trigger:
    - platform: state
      entity_id: automation.radiator_test_30_secs
      to: 'on'
    action:
    - delay: '0:00:01'
    - service: switch.turn_on
      entity_id: switch.switch_4
    - delay: '0:00:10'
    - service: switch.turn_off
      entity_id: switch.switch_4
    - delay: '0:00:01'
    - service: automation.turn_off
      entity_id: automation.radiator_test_30_secs