What is the mode of âscript.script_office_work_lightsâ? If itâs default (mode: single), you canât call it again until it is completed. All future attempts will be ignored (and logged). If you expect 3 instances to happen, make it mode: parallel
Also, what does that script do? Does it take a long time for it to run?
There is a subtle difference between the 2 (other than script.turn_on not allowing you to pass data). The 2nd one runs the script and returns immediately. The 1st one will wait for the entire script to complete before continuing.
If you have some rogue light or something that wont reply, this poor script is just going to wait forever to finish. It might even halt on errors for all I know. Either way, the 2nd one doesnât care. It just says âgood luckâ and goes to the next step.
Your numeric_state trigger will only happen once. After that, it will never not be 2. Thus, will never cross the bounds.
numeric_state triggers will only fire if the previous state was outside of the bounds. Thus, the first double click it probably goes from 0 to 2. Now itâs stuck at 2 forever and will never fire again.
One thing I noticed, the click count never resets when I look at the entity switch details⌠the click type varies, depending if it is a single, double or triple click.
Shelly type Shelly Button 1
Shelly ID 483FDA6FE510
Ip address 192.168.3.17
Protocols CoAP-discovery, poll, CoAP-msg
Uptime 47 h
Cloud status connected
Click type double
Click count 93
Either that or the shelly integration counts the total clicks.
In any case itâd be best to set a simple action, i.e. toggling a light and check if the trigger or the action is causing trouble.
Looking at the latest reply it seems like the integration is counting the total amount of clicks
Well in that caseâŚ
Letâs hope the click type changes state whenever clicked
trigger:
- platform: state
entity_id: binary_sensor.shelly_for_ha_shbtn_1_483fda6fe510_switch
attribute: click_type
to: double
That makes sense in a way since it will wait for you to finish clicking before updating.
Maybe thereâs an easier way, which integration are you using for your binary sensor?
Shelly, Tasmota, MQTT?
In any case, there might be an event fired on a double-click, you could listen to * events in the developer tools while double-clickingâŚ
If thereâs nothing, the next step would be to check if the click count updates before youâve finished clicking:
(before) 93 --> (double-click) --> (now) 95
We could catch that
(before) 93 --> (first click of double click) --> 94 --> (second click of double click) --> (now) 95
while this behavior would be bad
Well, at least it increments. For now, you can use this:
alias: AUTOMATION_SCRIPT_OFFICE_WORK_LIGHTS_TOGGLE
description: Run Script to toggle office lights on button 2x press
trigger:
- platform: state
entity_id: binary_sensor.shelly_for_ha_shbtn_1_483fda6fe510_switch
to: on
condition: []
action:
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.shelly_for_ha_shbtn_1_483fda6fe510_switch
to: on
timeout: '00:00:03' # wait this long until the 2nd button press
continue_on_timeout: false
- service: script.script_office_work_lights
mode: queued
max: 3