Combine 2 python sensors to 1

Hi, i have 2 python command line sensors, but i somtimes have issues, that they cross each other, when pyhton is running, the other one cant runt, because it creates a TCP connection, only connection allowed
so basicly i only want python script, that receives it back in to 1 or 2 sensors

this is config now, you see i excecute 2 different pythons, the 2 pythons scrips are actual the same, its just the hex value thats different, so the result of the 2 “messages” i want to have it from 1 python script
doesnt mather if the end resuls is in 1 of 2 sensors, just want to fire only 1 python script

i also tried playing with the scan intervals, so that dont interfear with other, but doesnt help either :frowning:

sensor:
  - platform: command_line
    command: python3 /config/dobissreceive1.py
    name: prog1
    scan_interval: 10
    
  - platform: command_line
    command: python3 /config/dobissreceive2.py
    name: prog2
    scan_interval: 10

#python script
#!/usr/bin/python3
import socket
import codecs
import binascii
host = '192.168.0.10'
port = 1001
message = binascii.a2b_hex ("ED63300000000000000000000000AFAF4205420a410041014102410341044105410B42024304430A430B4408440943074306440A4500450145024503410A4106")
mySocket = socket.socket()
mySocket.connect((host,port))
mySocket.send(message)
data = mySocket.recv(1024)
data = binascii.hexlify(data).decode()
print (data)
mySocket.close()

i sometimes have those lines

2019-03-23 09:33:55 ERROR (SyncWorker_3) [homeassistant.components.sensor.command_line] Command failed: python3 /config/dobissreceive1.py

thats when the other script is firing already

Why not use 1 bash script to run both, and then use MQTT to feed the result in?

I don’t use mqtt now , don’t want to have more tools then needed :wink:
I think it’s possible verry easy, just don’t know the catch, I think I need to catch the message with arguments or something… But I am not a programmer, just a Googler :slight_smile:

You will have issues when polling a device which can only process one message, and a high sensor refresh rate. You need to do 2 sequentially.

You could bash script the two and store a file on the HDD, and then use a template sensor to read in the value from the file.

Well, I was thinking just to change my python script, I send 2 messages after each other…then I just export/ print the result in one sensor, so 2 messages in one long sensor field, afterwards in HA I can split them back