Replies: 4 comments 9 replies
-
Tuya devices notify two ways:
Here is a simple monitor loop if you want to try yourself: import tinytuya
d = tinytuya.OutletDevice('DEVICEID', address='DEVICEIP', local_key='DEVICEKEY', persist=True, version=3.3)
print(" > Send Request for Status < ")
payload = d.generate_payload(tinytuya.DP_QUERY)
d.send(payload)
print(" > Begin Monitor Loop <")
while(True):
# See if any data is available
data = d.receive()
if data:
print('Received Payload: %r' % data)
# Send keyalive heartbeat
print(" > Send Heartbeat Ping < ")
payload = d.generate_payload(tinytuya.HEART_BEAT)
d.send(payload) |
Beta Was this translation helpful? Give feedback.
-
It depends on the device. Most devices push async updates on state change, though some only update when polled. To watch for async updates, start a loop which calls import time
import tinytuya
d = tinytuya.Device( 'DEVICEID', 'DEVICEIP', local_key='DEVICEKEY', persist=True, version=3.x, connection_timeout=1 )
print( d.status() )
print(" > Begin Monitor Loop <")
pingtime = time.time() + 9
polltime = time.time() + 3
while(True):
if( pingtime <= time.time() ):
payload = d.generate_payload(tinytuya.HEART_BEAT)
data = d.send(payload)
pingtime = time.time() + 9
if data:
print( data )
# only needed for devices which do not update asynchronously
#if( polltime <= time.time() ):
# polltime = time.time() + 3
# print( '================' )
# print( d.updatedps([17,18,19,20]) )
# print( d.status() )
data = d.receive()
if data:
print( data ) |
Beta Was this translation helpful? Give feedback.
-
Thanks, I think I'll go with MQTT as I've it already set up. I have another question though. What is the reason for not consistent device status when using tinytuya and Smart Life app? I noticed, that when I'm using
|
Beta Was this translation helpful? Give feedback.
-
I believe these devices are only sold in Poland:
Thanks for your time Folks, I think I can close that discussion. |
Beta Was this translation helpful? Give feedback.
-
I have a device whose status I want to know. If the device changes its status, I want to do something. I'm wondering what's the best option with this library? From what I read, there is only constant pooling, which is not the fastest way to know the device status. Is there a more "reactive" way to be notified from the device if the status changes?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions