Disable switch for 15 secs after toggle

Good evening everybody. My first post here :slight_smile:
I have a motorized water ball valve, that is controlled by a Sonoff mini. The thing is that it takes ~15 seconds to open/close. That’s why I need some kind of a solution to disable/deactivate/lock a lovelace switch for 15 seconds after toggling it. Just to give enough time for motor to close the valve. After that the switch should be back to normal and can be toggled again.
Haven’t found any ideas for that, so any suggestions are welcome. Thanks.

I wanted the same for my doorbell notification. See below what I put (using a timer with 10 seconds which is the duration during which I don’t want a new notification) that might help:

Timer definition in configuration:


timer:
  doorbell:
    name: doorbell timer
    duration: 10

Automation:


- id: doorbell_rings_notification
  alias: Doorbell rings notification
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.0x00158d0002ca0ef1_contact
    to: 'on'
  condition:
      condition: state
      entity_id: timer.doorbell
      state: 'idle'
  action:
  - service: timer.start
    data:
      entity_id: timer.doorbell
  - service: notify.mobile_app_rene_s_iphone_11
    data:
      message: 'someone at the door'

You could probably “wrap” a template switch around it that also uses a timer as @Piggyback suggested. Maybe something like this:

timer:
  valve:
    duration: 15
switch:
- platform: template
  switches:
    valve:
      value_template: "{{ is_state('switch.real_valve', 'on') }}"
    turn_on:
    - condition: state
      entity_id: timer.valve
      state: idle
    - service: timer.start
      entity_id: timer.valve
    - service: switch.turn_on
      entity_id: switch.real_valve
    turn_off:
    - condition: state
      entity_id: timer.valve
      state: idle
    - service: timer.start
      entity_id: timer.valve
    - service: switch.turn_off
      entity_id: switch.real_valve

Thanks. That looks pretty promising :slight_smile: But I got some error while checking Configuration:

Invalid config for [switch.template]: expected a dictionary for dictionary value @ data['switches']['turn_off']. Got [OrderedDict([('condition', 'state'), ('entity_id', 'timer.radiator_valve'), ('state', 'idle')]), OrderedDict([('service', 'timer.start'), ('entity_id', 'timer.radiator_valve')]), OrderedDict([('service', 'switch.turn_off'), ('entity_id', 'switch.sonoff_10008cf3d6')])]
expected a dictionary for dictionary value @ data['switches']['turn_on']. Got [OrderedDict([('condition', 'state'), ('entity_id', 'timer.radiator_valve'), ('state', 'idle')]), OrderedDict([('service', 'timer.start'), ('entity_id', 'timer.radiator_valve')]), OrderedDict([('service', 'switch.turn_on'), ('entity_id', 'switch.sonoff_10008cf3d6')])]
required key not provided @ data['switches']['radiator_valve']['turn_off']. Got None
required key not provided @ data['switches']['radiator_valve']['turn_on']. Got None. (See ?, line ?). 

Here’s what i got on my configuration.yaml:

#################################################################################
#  Home heating - Radiator valve timer                                          #
#################################################################################
timer:
  radiator_valve:
    duration: 15
switch:
  - platform: template
    switches:
      radiator_valve:
        value_template: "{{ is_state('switch.sonoff_10008cf3d6', 'on') }}"
      turn_on:
      - condition: state
        entity_id: timer.radiator_valve
        state: idle
      - service: timer.start
        entity_id: timer.radiator_valve
      - service: switch.turn_on
        entity_id: switch.sonoff_10008cf3d6
      turn_off:
      - condition: state
        entity_id: timer.radiator_valve
        state: idle
      - service: timer.start
        entity_id: timer.radiator_valve
      - service: switch.turn_off
        entity_id: switch.sonoff_10008cf3d6

I’m not a pro here. Can you help me with that?

The issue is because of incorrect indenting. Turn on and Turn off should be further indented. I tested the code on my instance and this will not give you errors:

timer:
  radiator_valve:
    duration: 15
switch:
  - platform: template
    switches:
      radiator_valve:
        value_template: "{{ is_state('switch.sonoff_10008cf3d6', 'on') }}"
        turn_on:
        - condition: state
          entity_id: timer.radiator_valve
          state: idle
        - service: timer.start
          entity_id: timer.radiator_valve
        - service: switch.turn_on
          entity_id: switch.sonoff_10008cf3d6
        turn_off:
        - condition: state
          entity_id: timer.radiator_valve
          state: idle
        - service: timer.start
          entity_id: timer.radiator_valve
        - service: switch.turn_off
          entity_id: switch.sonoff_10008cf3d6
1 Like

Just got a little deeper dive into this solution. René, you’re the man!! Worked like a charm! Exactly what I needed. Thank You.
ezgif-2-5602a7bdf0e9

1 Like