Triggering an automation early then the specified time

I noticed the lag when the automation triggers. So e.g. if the text file is at 18:00 and when the time sensor hits 18:00 the automation does not trigger by the second rather it triggers after 5-8 seconds.

I noticed this lag with the time sensor itself i.e. when the minute changes it does not change and has a lag of 5-8seconds. So it could be the reason why the automation has a lag.

Do you know how I could reduce the time in seconds ?

Ok, but what do you trigger/execute that shows the lag?

Well I monitor how long it takes for the notification to arrive on my phone after the automation is triggered. Does that make sense?

Just to jump in, I think the 5 second lag you are talking about is unavoidable, since there is some time involved in sending the message to the cloud and it arriving at your phone (I am assuming iOS notifications and these are not processed locally, the cloud is involved).

I, for example, am not using a time-comparison trigger as you are; I send a notification when my garage door opens. Sure enough, the door opens, and several seconds later I get the notification.

1 Like

Exactly. Whatever notification service you are using, it always will have some sort of delay, shorter or longer. So, using HA as a tea timer might not be the best idea. But that is not HAs fault but rather cause by the accumulation of latencies of different systems being used.

1 Like

I am certain it’s nothing to do with the notification instead it’s the time component which is the issue as I have monitored it and when the minutes changel the time on HA frontend lags for about 5 seconds.

What’s exactly the problem? What are your trying to do that 5 seconds delay/lag is such a big issue for getting notified? Which notification component are you using?

1 Like

Thanks for your concern but I have explained myself previously. As I said it’s nothing to do with the notification component.

Template sensors like that have a major performance impact. Instead you should create a binary template sensor that is on when the condition is met.

That may reduce your lag a bit.

1 Like

I have tried to implement it and this is what I have come up with but gives me error in this line {{ is_state('sensor.manutd', is_state('sensor.time')) }}

binary_sensor:
  - platform: template
    sensors:
      test_up:
        friendly_name: "Test"
        value_template: >-
          {{ is_state('sensor.manutd', is_state('sensor.time')) }}

That won’t work, because is_state requires 2 arguments, and you’ve only given it sensor.time.

binary_sensor:
  - platform: template
    sensors:
      test_up:
        friendly_name: "Test"
        value_template: >-
          {{ states.sensor.manutd.state == states.sensor.time.state }}

This assumes that sensor.time isn’t a timestamp with second (or sub-second) accuracy.

so I used this {{ states.sensor.manutd.state == states.sensor.time.state }} but I get the following error :

2017-10-20 15:24:20 ERROR (Thread-2) [homeassistant.util.yaml] while scanning for the next token
found character '\t' that cannot start any token
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 68, column 1
2017-10-20 15:24:20 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: while scanning for the next token
found character '\t' that cannot start any token
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 68, column 1

Line 68 is {{ states.sensor.manutd.state == states.sensor.time.state }}

Don’t use tabs, you have to use spaces

2 Likes

I know some of us sound like a broken record, but why is the timing so critical that 8 seconds is a problem? What specifically are you trying to do?

This is an important question, because some user might have a good way to accomplish what you want, but without the struggles and complications you’re having now. :slight_smile:

It might be easier to modify the python script to output the correct format like json or use mqtt. He is using this script.

Right that sorts that out.

Sorry for my novelty but do I expect to see the binary sensor on the front end? I have tried looking for it as a senor in the states page but cannot see it. I have done a test run when the sensor.manutd is equal to sensor.time.

You should see it in the dev-states view (<>), whether you see it elsewhere depends on your configuration.

If you don’t see binary_sensor.test_up it suggests that it hasn’t loaded. Use hassctl to test your configuration.

1 Like

Hey @Dolores, @RobDYI has just explained what I am trying to achieve.

If anyone of you could please try to use the time component the way I have used it, you might actually see what I am trying to explain all this time (and the lag).

The lag is important because the time component is not in sync in general with HA and it defeats the purpose really of having a “time” component.

The trouble is, Home Assistant isn’t a real time platform and doesn’t pretend to be one. There’s always going to be delays, even when everything is purely internal to the system you’re running it on. Using a template like that slows things down again, and may well be the primary source of the delay.

The best you’re likely to achieve is to identify the typical range, and instead set it to trigger one minute earlier, then have a delay of (say) 52 seconds. That’s horribly, horribly, inefficient, but it may achieve what you’re after.

My purely time based automations generally fire within 2 minutes of the designated time (so, if due to trigger at 06:00 they’ll trigger between 06:00 and 06:01 inclusive).

2 Likes

Binary sensor sorts it out thanks ever so much @Tinkerer. Must admit your automation knowledge is pretty damn good mate. Cheers!!