How to delay a "command line" sensor startup

Hi, i have an automation thats strats an python script at startup of HA , that scripts is somekind of socket server where i send messages too and receive messages from

so i also have an sensor configured, but at startup, the first time it failes and i get errors in my log file because of that

how can i delay that sensor with like 10 seconds or something?

here is automation + sensor yaml

#automation 
- alias: Socket Server
  initial_state: 'on'
  trigger:
    - platform: homeassistant
      event: start
  action:
    - service: shell_command.python_server #somekind of python file here

#sensor
  - platform: command_line
    command: !secret dobissreceive #somekind of python_script  file here
    name: prog
    scan_interval: 10

2020-06-25 15:54:02 ERROR (SyncWorker_1) [homeassistant.components.command_line.sensor] Command failed: xxxxx

See the delay example in the automation action docs.

That’s no good for delaying the sensor at start up though.

indeed, i dont want a delay automation, i need my sensor being delayed … :slight_smile:
my automation is started at HA startup, but probably the sensors is being fired first

I have the same problem with some sensors.

Oh, I see. If it’s a standalone Python script, just include:

import time
...
time.sleep(10)

That’s something I can do, I hope it doesn’t impact, because it will sleep every time scan_interval

Thnx for tip

Other suggestions are welcome also

hmm; that doesnt help, its all slow now :slight_smile:
2020-06-25 17:24:58 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform command_line is taking over 10 seconds.

Can you post the Python file? It might be easy to put the problem section in a try: / except: and fail silently when there’s a problem.

offcourse, i am just sending an “ok” command to a server … that server then gives me feedback about all my lights in my house … its to create value templates for all my lights/switches …

import socket
import sys
import time
import binascii

#time.sleep(20)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 10000)
sock.connect(server_address)
try:
    for x in range(0,1):
        message = "sensor"
        message = message.encode()
        sock.sendall(message)
        data = sock.recv(2048)
        print(data.decode())

finally:
    sock.close()

Maybe:

import socket
import sys
import time
import binascii

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 10000)
try:
    sock.connect(server_address)
    for x in range(0,1):
        message = "sensor"
        message = message.encode()
        sock.sendall(message)
        data = sock.recv(2048)
        print(data.decode())

except:
    pass

finally:
    if sock is not None:
        sock.close()

that did it, error gone from my log!

appreciate it :slight_smile: