For this WebSocket integration, can this be used to add WebSocket devices from WebSocket scripts outside of HA (like Python) as HA entities?
Or to create WebSocket entities with WebSocket integration, it’s done entirely on configuration.yaml?
For this WebSocket integration, can this be used to add WebSocket devices from WebSocket scripts outside of HA (like Python) as HA entities?
Or to create WebSocket entities with WebSocket integration, it’s done entirely on configuration.yaml?
What do you mean by “websocket devices”?
The doc you point to is to interact with HA itself via websocket (vs. HTTP API)
I meant websocket devices as in, relays/sensor run by a Python websocket script. The websocket would of course would be accessed outside HA at this point.
But an example on how to use the websocket integration here to interact with HA via websocket? Sorry for bad english here.
Still not clear what you are trying to achieve.
See
for what can be done in HA through its websocket API.
To explain it clearer, I’ve used Python to build a program that turns on/off Raspberry Pi GPIO and/or receiving binary sensors (not including the html menu and javascript part here, only the Python).
from threading import Thread
from time import sleep
import socket
import RPi.GPIO as GPIO
UDP_TX_IP = "127.0.0.1"
UDP_TX_PORT = 3000
UDP_RX_IP = "127.0.0.1"
UDP_RX_PORT = 3001
print("UDP target IP: %s" % UDP_TX_IP)
print("UDP target port: %s" % UDP_TX_PORT)
sockTX = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sockRX = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sockRX.bind((UDP_RX_IP, UDP_RX_PORT))
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(16,GPIO.OUT)
GPIO.output(16,GPIO.HIGH)
GPIO.setup(6,GPIO.IN)
def newclient():
if GPIO.input(16):
sockTX.sendto(bytes('{"GPIO16T":1}', "utf-8"), (UDP_TX_IP, UDP_TX_PORT))
def one():
while True: # Run forever
MESSAGE = '{"D22":1}'
sockTX.sendto(bytes('{"A1":80}', "utf-8"), (UDP_TX_IP, UDP_TX_PORT))
sleep(3)
sockTX.sendto(bytes('{"A1":20}', "utf-8"), (UDP_TX_IP, UDP_TX_PORT))
sleep(3)
def two():
while True:
data, addr = sockRX.recvfrom(1024)
JsonStr = data.decode('utf_8')
print(JsonStr)
if (JsonStr.find('{"NewClient":1}') != -1):
newclient()
elif (JsonStr.find('{"GPIO16T":1}') != -1):
if GPIO.input(16):
GPIO.output(16,GPIO.LOW)
sockTX.sendto(bytes('{"GPIO16T":0}', "utf-8"), (UDP_TX_IP, UDP_TX_PORT))
else:
GPIO.output(16,GPIO.HIGH)
sockTX.sendto(bytes('{"GPIO16T":1}', "utf-8"), (UDP_TX_IP, UDP_TX_PORT))
def three():
while True:
if GPIO.input(6):
sockTX.sendto(bytes('{"GPIO6":0}', "utf-8"), (UDP_TX_IP, UDP_TX_PORT))
sleep(0.01)
else:
sockTX.sendto(bytes('{"GPIO6":1}', "utf-8"), (UDP_TX_IP, UDP_TX_PORT))
sleep(0.01)
newclient()
p1 = Thread(target = one)
p2 = Thread(target = two)
p3 = Thread(target = three)
p1.start()
p2.start()
p3.start()
while True:
sleep(10)
What I was thinking is if said GPIO and sensor there can be added into HA as Entities, or that the WebSocket API doesn’t actually work this way.