Trigger when counter is larger than n and hasn't changed for a second

I have a shelly 1 behind a wall switch, This switches the light behind it, but I have also managed to make automations to do stuff when the switch is changed 2 and 3 times in a row. But therefore I have to make 3 automations and one extra for every extra value (4, 5 etc).

I want to trigger the automation when the counter is on a value (larger than 1) for more than 1 second. Problem is the for statement needs the to statement and that is a string (as far as i can tell)

I would like something like this to work:

trigger: 
  platform: state
  entity_id: counter.counter_eetafel
  to: >2
  for: 00:00:01
   action: etc

How could I do this?

The complete code for up to 3 times state changing of the switch:

    - alias: Update Counter Eetafel
       hide_entity: true
       trigger:
         platform: state
         entity_id: sensor.lamp_schakelaar_eetafel
       action:
         service: counter.increment
         entity_id: counter.counter_eetafel
       id: update_counter_eetafel
     - alias: Reset Counter Eetafel
       hide_entity: true
       trigger:
         - platform: state
           entity_id: sensor.lamp_schakelaar_eetafel
           to: "1"
           for: 00:00:02
         - platform: state
           entity_id: sensor.lamp_schakelaar_eetafel
           to: "0"
           for: 00:00:02
       action:
         service: counter.reset
         entity_id: counter.counter_eetafel
       id: reset_counter_eetafel
     - alias: Turn of all lights when counter hits 2
       hide_entity: true
       trigger: 
         platform: state
         entity_id: counter.counter_eetafel
         to: "2"
         for: 00:00:01
       action:
         - service: scene.turn_on
           entity_id: scene.woonkamer_uit
         - service: counter.reset
           entity_id: counter.counter_eetafel
       id: turn_off_lights_when_counter_hits_2
     - alias: Turn on eetafel and woonkamer_lezen when counter hits 3
       hide_entity: true
       trigger: 
         platform: state
         entity_id: counter.counter_eetafel
         to: 3
         for: 00:00:01
       action:
         - service: scene.turn_on
           entity_id: scene.woonkamer_lezen
         - service: switch.turn_on
           entity_id: switch.lamp_eetafel
         - service: counter.reset
           entity_id: counter.counter_eetafel
       id: turn_on_eetafel_light_and_woonkamer_lezen_when_counter_hits_3

How about:

trigger: 
  platform: numeric_state
  entity_id: counter.counter_eetafel
  above: 2
  for: 00:00:01
   action: etc
2 Likes

Ah, didn’t know about above (and i assume below as well). Will try that :slight_smile:

Seems to work :slight_smile: I’ve condensed the thing somewhat to three automations tops. One for the counter, one for ‘normal’ wall switch action and one for more the double or more presses.

  - alias: Update Counter Eetafel
    hide_entity: true
    trigger:
      platform: state
      entity_id: sensor.lamp_schakelaar_eetafel
    action:
      service: counter.increment
      entity_id: counter.counter_eetafel
    id: update_counter_eetafel
  - alias: Turn on eetafel when counter is 1
    hide_entity: true
    trigger: 
      platform: state
      entity_id: counter.counter_eetafel
      to: "1"
      for:
        milliseconds: 250
    action:
      - service: switch.toggle
        entity_id: switch.lamp_eetafel
      - service: counter.reset
        entity_id: counter.counter_eetafel
    id: turn_on_eetafel_light_when_counter_is_1
  - alias: Control Lights With Switch Eetafel
    hide_entity: true
    trigger: 
      platform: numeric_state
      entity_id: counter.counter_eetafel
      above: 1
      for: 
        milliseconds: 250
    action:
      - service: scene.turn_on
        data_template:
         entity_id: >
          {% if states('counter.counter_eetafel') | int == 2 %} scene.woonkamer_uit
          {% elif states('counter.counter_eetafel') | int > 2 %} scene.woonkamer_lezen_eetafel
          {% endif %}
      - service: counter.reset
        entity_id: counter.counter_eetafel
    id: control_lights_with_switch_eetafel

This works.

Now for more time based actions.

1 Like