Script / Automation help - trigger upon 4 successive state changes

I have a Z-wave switch that’s far away and we get lazy having to walk all the way over to it (I know, sad right?), so I’d like to give a second, closer Z-wave switch the ability to turn on those lights as well.

I’d like to physically flip switch.near 4 times (on, off, on, off) and then IF that sequence happens within 2 seconds, HA will activate switch.farfaraway.

I’m able to make it mirror the state switch.near, but I’m not sure how might I require it to be switched 4 times within 2 seconds as a trigger? Am I looking at an automation or a script? python?

Thanks so much! Love this community. :slight_smile:

This would be pretty easy to do using AppDaemon.

technically possible to do with an automation, but I wouldn’t recommend it.

You would have an input_boolean, and an input_slider.
Then an automation that runs with switch_near that turns input_boolean on, and increments the slider value, and kicks of a script.
The script would delay 2 seconds then turn input_boolean off.

It would be pretty complex, and better implemented wit appdaemon.

As the other said, it can be done with HA, but it’s not that intuitive and likely requires more than one automation.

If you want to go the HA route I would do it like this:

  1. make an input_boolean, let’s call it ‘shortmemory’
  2. make an automation that deactivates shortmemory when it’s been ‘on’ for 2 seconds
  3. make an automation that reacts on the switch going from ‘off’ to ‘on’ and if ‘shortmemory’ is ‘off’ turns it ‘on’
  4. make an automation that reacts on the switch going from ‘off’ to ‘on’ and if ‘shortmemory’ is ‘on’ activates switch.farfaraway

As for step 2, I use something similar for my coffe maker, for the bool I guess its something like this:

- alias: forget it
  trigger:
    - platform: state
      entity_id: input_boolean.shortmemory
      to: 'on'
      for:
        seconds: 2
  action:
    - service: homeassistant.turn_off
      entity_id: input_boolean.shortmemory

Thanks for the ideas! It wasn’t crazy hard… I was having more problems with the ####ing indentions and -'s than anything else… sigh.

automation 5:
  - alias: Switch on, bool on
    trigger:
      platform: state
      entity_id: switch.island_23
      to: 'on'
    condition:
      condition: state
      entity_id: input_boolean.shortmemory
      state: 'off'
    action:
      service: homeassistant.turn_on
      entity_id: input_boolean.shortmemory

  - alias: turn on cabinet light if conditions are true
    trigger:
      platform: state
      entity_id: switch.island_23
      to: 'on'
    condition:
      condition: state
      entity_id: 'input_boolean.shortmemory'
      state: 'on'
    action:
      service: switch.turn_on
      entity_id: switch.cabinet_6

  - alias: forget it
    trigger:
      - platform: state
        entity_id: 'input_boolean.shortmemory'
        to: 'on'
        for:
          seconds: 2
    action:
      - service: homeassistant.turn_off
        entity_id: 'input_boolean.shortmemory'

It works but the timing has to be pretty exact for some reason. If I flip too fast it doesn’t seem to register. I’ll update this post if I do something different. The results are different if I’m flipping the physical switch on the wall vs. on the HASS frontend/webpage.