Time condition, less than one second possible?

So i have a time trigger for a binary sensor.
I want to do different things depending on how long it’s pushed for, but i want to start at less the 1 second trigger time.

So is it possible to use milliseconds in the trigger field, or even .5 of a second ?

- alias: 'Touch Pad trigger less than 1 second'
  trigger:
    platform: state
    entity_id: binary_sensor.esp2_touchpad
    from: 'off'
    to: 'on'
    for:
      seconds: <1
  action:
    - service: scene.turn_on
      entity_id: scene.bedroomdance

or

- alias: 'Touch Pad trigger before bedtime 2 seconds'
  trigger:
    platform: state
    entity_id: binary_sensor.esp2_touchpad
    from: 'off'
    to: 'on'
    for:
      seconds: 0.5
  action:
    - service: scene.turn_on
      entity_id: scene.bedroomdance

Don’t think you can do it this way.
what do you need to monitor and why is the time condition so important?
You could try and use a template condition and or a script to check how long the button was pressed for, something like:

    - condition: template
      value_template: '{{ (as_timestamp(now()) - as_timestamp(states.automation.touch_pad_trigger_less_than_1_second.attributes.last_triggered | default(0)) | int < 1)}}'

or maybe 2 automations, one that triggers on button pressed, one that triggers on button released, then get the time difference between the 2 automations being triggered, but seeing as we’re in the milliseconds world, I’m not sure how accurate this will be…

Its only cause i want to turn the lights on in normal mode if touched i.e. pressed for less than a second.
Turn on dance/disco mode if pressed for 1-5 seconds
do something else if pushed for longer the 5 seconds.

Agreed that ESP8266 over wifi wouldn’t be highly accurate in the milliseconds world, but prob enough to to tell between 0.5 and 1 seconds

I hadn’t thought of templates, i’ll have to dig into what u’ve posted (as they are above my knowledge at the mo)

So if you have an ESP8266 to run it, set your commands in there? How does the ESP talk to HA? Is it was MQTT? If so maybe change your code to have an effect set up when the button is pressed and help?

I did add a de-bounce on the https://esphomelib.com/ setup, so i’ll look at adding the timing that side.

It just posts ‘on’ and ‘off’ via MQTT as i’ve set it as a binary sensor.

Set it up as a MQTT JSON Light, it’ll give you the option for effects

sorry
i think you miss understood, the switch/button is setup as a binary sensor. The light is already a MQTT light.

I meant define your touchpad as an MQTT light instead of binary_sensor, then you can have more than on/off status (by using effects that you set up in the ESP when posting the message on the topic)

https://esphomelib.com/esphomeyaml/components/binary_sensor/index.html

Looks like i might be able to define in the sensor

Replyed at the same time.

God my list of things to do with HASS is growing bigger than what i have actioned :joy:

1 Like

That’s both the beauty and the pitfall of HA / home automation, it never ends.

I can see from another post that you are well versed in the template side of things.

Any pointers before i loose a day to my normal “hack at it, till you get it working approach”

Thanks for the praise :slight_smile:
I would think this is slightly different here and I would put part/most of the logic on the ESP code, and from the link you provided it appears you can set min and max times for presses, so see if you can add an if-then-else or a switch/case in there to define a status (on/off) and a substatus (mode, like “bedroomdance”) then post on MQTT the status and the effect. you’ll probably need to define an effect for “no effecT” as in simply On…
Hope that makes sense…

Kool, thanks for that, i’ll see what my day off brings, as i have list of things to do.

- delay:
   milliseconds: 200
3 Likes

I’m running Hassio 98.5 and I tried using 500 milliseconds to flash a light on and off.It worked but appeared more like 1 second. So I shortened it to 250 and nothing happened. I bumped it to 300 and it worked again. Not sure why 250 won’t work though but it could be the latency in the shelly switch I’m using.

delay: ‘00:00:0.3’

Or in the UI select Delay and in time 00:00:0.3 or half of a second 00:00:0.5

Tested and working.

4 Likes