Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This happened while trying to scan my network from Raspbian on a Pi 4 #12

Closed
ShaneSpina opened this issue Dec 11, 2020 · 9 comments
Closed

Comments

@ShaneSpina
Copy link

Scanning local network for Tuya devices...
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/shane/.local/lib/python3.7/site-packages/tinytuya/main.py", line 48, in
tinytuya.wizard(color)
File "/home/shane/.local/lib/python3.7/site-packages/tinytuya/init.py", line 1479, in wizard
devices = deviceScan(False, 20)
File "/home/shane/.local/lib/python3.7/site-packages/tinytuya/init.py", line 1139, in deviceScan
client.bind(("", UDPPORT))
OSError: [Errno 98] Address already in use

@ShaneSpina
Copy link
Author

OK so I figured that bit out on my own.. I had to Stop the HASS container.. now to figure out why this is:

[Dog Run Lights] - 192.168.86.114 - No Response

I can Ping the IP, I can control the device (On/Off) from HA and the Tuya app.. I get the same output from Raspbian on my Pi and my Win10 laptop. The tuya app shows good network connectivity..

@jasonacox
Copy link
Owner

HASS was likely configured to open the UDP port 6666 for listening so the OS would not allow tinytuya to open it as well.

No response can indicate an invalid key. What do you get with python -m tinytuya scan ? Also, did you use the wizard (python -m tinytuya wizard) to grab the device LOCAL_KEY?

One other suggestion: make sure you are using the latest version of tinytuya (1.1.1):

pip install --upgrade tinytuya

@ShaneSpina
Copy link
Author

I just did the upgrade to tiny tuya and still get the same result from "python -m tinytuya wizard" I'll show you the piped result of the scan method:

Polling local devices...
←[0m←[32m[Dog Run Motion Sensor] - ←[0m←[97m←[2m0 - ←[0m←[91m←[1mError: No IP found←[97m←[0m
←[0m←[32m[Front Door Sensor] - ←[0m←[97m←[2m0 - ←[0m←[91m←[1mError: No IP found←[97m←[0m
←[0m←[32m[Bedroom Strip Left] - ←[0m←[97m←[2m192.168.86.111 - ←[0m←[91m←[2mNo Response
←[0m←[32m[Bedroom Strip Right] - ←[0m←[97m←[2m192.168.86.57 - ←[0m←[91m←[2mNo Response
←[0m←[32m[Dog Run Lights] - ←[0m←[97m←[2m192.168.86.114 - ←[0m←[91m←[2mNo Response
←[0m←[32m[Bedroom TV Strip] - ←[0m←[97m←[2m192.168.86.113 - ←[0m←[91m←[2mNo Response
←[0m←[32m[Den Lamp 1] - ←[0m←[97m←[2m192.168.86.105 - ←[0m←[91m←[2mOff←[0m←[97m←[2m - DPS: {'1': False, '11': 0}
←[0m←[32m[Den Lamp 3] - ←[0m←[97m←[2m192.168.86.107 - ←[0m←[91m←[2mOff←[0m←[97m←[2m - DPS: {'1': False, '11': 0}
←[0m←[32m[Den Lamp 2] - ←[0m←[97m←[2m192.168.86.106 - ←[0m←[91m←[2mOff←[0m←[97m←[2m - DPS: {'1': False, '11': 0}
←[0m←[32m[Den Light 4] - ←[0m←[97m←[2m192.168.86.108 - ←[0m←[91m←[2mOff←[0m←[97m←[2m - DPS: {'1': False, '2': 'white', '3': 62, '4': 0, '5': '1b07000010ff1b', '6': '00ff0000000000', '7': 'white', '8': 'ffffff03ff003e8', '9': 'ffff5001ff0000', '10': 'ffff0505ff000000ff00ffff00ff00ff0000ff000000'}
←[0m←[32m[Outside Light 4] - ←[0m←[97m←[2m192.168.86.104 - ←[0m←[97m←[1mOn←[0m←[97m←[2m - DPS: {'1': True, '2': 255}
←[0m←[32m[Den Lights 6] - ←[0m←[97m←[2m192.168.86.110 - ←[0m←[91m←[2mOff←[0m←[97m←[2m - DPS: {'1': False, '2': 'white', '3': 255, '4': 0, '5': '1b07000010ff1b', '6': '00ff0000000000', '7': 'ffff500100ff00', '8': 'ffff8003ff000000ff000000ff000000000000000000', '9': 'ffff5001ff0000', '10': 'ffff0505ff000000ff00ffff00ff00ff0000ff000000'}
←[0m←[32m[Den Lights 5] - ←[0m←[97m←[2m192.168.86.109 - ←[0m←[91m←[2mOff←[0m←[97m←[2m - DPS: {'1': False, '2': 'white', '3': 255, '4': 0, '5': '1b07000010ff1b', '6': '00ff0000000000', '7': 'ffff500100ff00', '8': 'ffff8003ff000000ff000000ff000000000000000000', '9': 'ffff5001ff0000', '10': 'ffff0505ff000000ff00ffff00ff00ff0000ff000000'}
←[0m←[32m[Dimmer-Switch] - ←[0m←[97m←[2m192.168.86.201 - ←[0m←[91m←[2mNo Response
←[0m←[32m[Outside Light 2] - ←[0m←[97m←[2m0 - ←[0m←[91m←[1mError: No IP found←[97m←[0m
←[0m←[32m[Outside light 1] - ←[0m←[97m←[2m0 - ←[0m←[91m←[1mError: No IP found←[97m←[0m
←[0m←[32m[Outside Light 3] - ←[0m←[97m←[2m0 - ←[0m←[91m←[1mError: No IP found←[97m←[0m
←[0m←[97m←[1m

←[97m←[0mSaving device snapshot data to snapshot.json

**←[0m←[32m[Bedroom Strip Left] - ←[0m←[97m←[2m192.168.86.111 - ←[0m←[91m←[2mNo Response** this is what I don't get.. it was pulling before then stopped..

@jasonacox
Copy link
Owner

It does see some of your devices and is pulling back the data points, but a few errors as you noted:

  • No IP found - tinytuya tries to determine the IP address by listening to UDP traffic from the devices. Naturally, if the device is unplugged it wont find the IP address. Otherwise, if the network is noisy you may need to have it wait longer by specifying a larger wait time (e.g. python -m tinytuya scan 30). In some cases, I've seen Tuya devices stop broadcasting in which case a power cycle was required to have them announce again (firmware upgrades sometime help this)

  • No Response - I have seen this happen in two cases: 1) If you have the SmartLIfe app open, some devices will not allow a connection - closing the app can help. 2) The device uses a CONTROL command instead of the QUERY command to pull back data (seem a bit wrong but I have seen this) and for some reason, most of the devices have an ID string length of 22 instead of the standard 20.

Can you provide the output of a scan in addition to the wizard output to see if the "No Response" devices have an ID length of 22? Also, I notice the color escape sequences in our output, are you using Windows "Command Prompt" or the "Powershell" terminal? For Command Prompt (or if you are just piping output via RPi, Mac, Linux), you can use the -nocolor option to remove the color formatting escape sequences:

python -m tinytuya scan -nocolor 

@ShaneSpina
Copy link
Author

I have 3 lights unplugged (outside light 1 2 3) so I get it not pulling data, everything else is plugged in

@ShaneSpina
Copy link
Author

TinyTuya (Tuya device scanner) [1.1.1]

[Loaded devices.json - 17 devices]

Scanning on UDP ports 6666 and 6667 for devices (15 retries)...

Scanning... |
Outside Light 4 [Valid payload]: 192.168.86.104
ID = 50260100cc50e34998dd, Product ID = er62DNOUD6LiAJ3a, Version = 3.1
Status: {'1': True, '2': 255}
Scanning... /
Den Lights 5 [Valid payload]: 192.168.86.109
ID = 30065233807d3a198b34, Product ID = MQbuNaeaHJPSW5SC, Version = 3.1
Status: {'1': True, '2': 'white', '3': 255, '4': 0, '5': '1b07000010ff1b', '6': '00ff0000000000', '7': 'ffff500100ff00', '8': 'ffff8003ff000000ff000000ff000000000000000000', '9': 'ffff5001ff0000', '10': 'ffff0505ff000000ff00ffff00ff00ff0000ff000000'}
Scanning... -
Den Lights 6 [Valid payload]: 192.168.86.110
ID = 04434570b4e62d4c855b, Product ID = MQbuNaeaHJPSW5SC, Version = 3.1
Status: {'1': True, '2': 'white', '3': 255, '4': 0, '5': '1b07000010ff1b', '6': '00ff0000000000', '7': 'ffff500100ff00', '8': 'ffff8003ff000000ff000000ff000000000000000000', '9': 'ffff5001ff0000', '10': 'ffff0505ff000000ff00ffff00ff00ff0000ff000000'}
Scanning...
Den Light 4 [Valid payload]: 192.168.86.108
ID = 3006523384f3eb606f00, Product ID = MQbuNaeaHJPSW5SC, Version = 3.1
Status: {'1': True, '2': 'white', '3': 62, '4': 0, '5': '1b07000010ff1b', '6': '00ff0000000000', '7': 'white', '8': 'ffffff03ff003e8', '9': 'ffff5001ff0000', '10': 'ffff0505ff000000ff00ffff00ff00ff0000ff000000'}
Scanning... |
Scanning... /
Den Lamp 3 [Valid payload]: 192.168.86.107
ID = 40383726dc4f22e76454, Product ID = 6sV9KTLJQdb0INPB, Version = 3.3
Status: {'1': True, '11': 0}
Scanning... -
Bedroom Strip Right [Valid payload]: 192.168.86.57
ID = eb13e86690453773d8a2vt, Product ID = keys8pj5xkq8cmrm, Version = 3.3
Status: {'20': False, '21': 'colour', '22': 1000, '23': 0, '24': '00fe03e801f4', '25': '000e0d0000000000000000c80000', '26': 0}
Scanning...
Bedroom TV Strip [Valid payload]: 192.168.86.113
ID = eb644bae8f2d4c7242d1ft, Product ID = keys8pj5xkq8cmrm, Version = 3.3
Status: {'20': False, '21': 'colour', '22': 1000, '23': 0, '24': '00fe03e801f4', '25': '000e0d0000000000000000c80000', '26': 0}
Scanning... |
Bedroom Strip Left [Valid payload]: 192.168.86.111
ID = ebe817ae915f4013674rh4, Product ID = keys8pj5xkq8cmrm, Version = 3.3
Status: {'20': False, '21': 'colour', '22': 1000, '23': 0, '24': '00fe03e801f4', '25': '000e0d0000000000000000c80000', '26': 0}
Scanning... /
Dog Run Lights [Valid payload]: 192.168.86.114
ID = eb33b396ab9c8b109fizhk, Product ID = keys8pj5xkq8cmrm, Version = 3.3
Status: {'20': False, '21': 'colour', '22': 1000, '23': 1000, '24': '00ee00c40323', '25': '05646401000003e803e800000000646401007803e803e80000000064640100f003e803e800000000646401003d03e803e80000000064640100ae03e803e800000000646401011303e803e800000000', '26': 0}
Scanning... -
Dimmer-Switch [Valid payload]: 192.168.86.201
ID = 60558167f4cfa2072386, Product ID = tebc75erlgslgpn5, Version = 3.3
No Stats for 192.168.86.201: Unable to poll
Scanning...
Den Lamp 1 [Valid payload]: 192.168.86.105
ID = 53350301dc4f22d9a157, Product ID = 6sV9KTLJQdb0INPB, Version = 3.3
Status: {'1': True, '11': 0}
Scanning... |
Den Lamp 2 [Valid payload]: 192.168.86.106
ID = 05200285dc4f22c83e12, Product ID = 6sV9KTLJQdb0INPB, Version = 3.3
Status: {'1': True, '11': 0}
Scanning... /
Scanning... -
Scanning...
Scanning... |
Scanning... /
Scanning... -
Scanning...
Scanning... |
Scanning... /
Scanning... -
Scanning...
Scanning... |
Scanning... /
Scanning... -
Scanning... \

Scan Complete! Found 12 devices.

@jasonacox
Copy link
Owner

Thanks! I'm probably missing something obvious, but is there still a problem? It looks like you are getting a response for your devices:

Bedroom Strip Left [Valid payload]: 192.168.86.111
ID = ebe817ae915f4013674rh4, Product ID = keys8pj5xkq8cmrm, Version = 3.3
Status: {'20': False, '21': 'colour', '22': 1000, '23': 0, '24': '00fe03e801f4', '25': '000e0d0000000000000000c80000', '26': 0}

That looks like a RGB Color light. Here are the details for those DPS values:
https://github.com/jasonacox/tinytuya#version-33---light-type-rgb

If you are interested, here is an example script on how to control an RGB light:

# TinyTuya Example
# -*- coding: utf-8 -*-
"""
TinyTuya - Smart Bulb RGB Test
Author: Jason A. Cox
For more information see https://github.com/jasonacox/tinytuya
"""
import tinytuya
import time
import os
import random
DEVICEID = "01234567891234567890"
DEVICEIP = "10.0.1.99"
DEVICEKEY = "0123456789abcdef"
DEVICEVERS = "3.3"
# Check for environmental variables and always use those if available
DEVICEID = os.getenv("DEVICEID", DEVICEID)
DEVICEIP = os.getenv("DEVICEIP", DEVICEIP)
DEVICEKEY = os.getenv("DEVICEKEY", DEVICEKEY)
DEVICEVERS = os.getenv("DEVICEVERS", DEVICEVERS)
print("TinyTuya - Smart Bulb RGB Test [%s]\n" % tinytuya.__version__)
print('TESTING: Device %s at %s with key %s version %s' %
(DEVICEID, DEVICEIP, DEVICEKEY, DEVICEVERS))
# Connect to Tuya BulbDevice
d = tinytuya.BulbDevice(DEVICEID, DEVICEIP, DEVICEKEY)
if(DEVICEVERS == '3.3'): # IMPORTANT to always set version
d.set_version(3.3)
else:
d.set_version(3.1)
# Keep socket connection open between commands
d.set_socketPersistent(True)
# Show status of device
data = d.status()
print('\nCurrent Status of Bulb: %r' % data)
# Set to full brightness warm white
print('\nWarm White Test')
d.set_white()
time.sleep(2)
# Power Control Test
print('\nPower Control Test')
print(' Turn off lamp')
d.turn_off()
time.sleep(2)
print(' Turn on lamp')
d.turn_on()
time.sleep(2)
# Dimmer Test
print('\nDimmer Control Test')
for level in range(11):
print(' Level: %d%%' % (level*10))
d.set_brightness_percentage(level*10)
time.sleep(1)
# Colortemp Test
print('\nColortemp Control Test (Warm to Cool)')
for level in range(11):
print(' Level: %d%%' % (level*10))
d.set_colourtemp_percentage(level*10)
time.sleep(1)
# Flip through colors of rainbow - set_colour(r, g, b):
print('\nColor Test - Cycle through rainbow')
rainbow = {"red": [255, 0, 0], "orange": [255, 127, 0], "yellow": [255, 200, 0],
"green": [0, 255, 0], "blue": [0, 0, 255], "indigo": [46, 43, 95],
"violet": [139, 0, 255]}
for x in range(2):
for i in rainbow:
r = rainbow[i][0]
g = rainbow[i][1]
b = rainbow[i][2]
print(' %s (%d,%d,%d)' % (i, r, g, b))
d.set_colour(r, g, b)
time.sleep(2)
print('')
# Turn off
d.turn_off()
time.sleep(1)
# Random Color Test
d.turn_on()
print('\nRandom Color Test')
for x in range(10):
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
print(' RGB (%d,%d,%d)' % (r, g, b))
d.set_colour(r, g, b)
time.sleep(2)
# Test Modes
print('\nTesting Bulb Modes')
print(' White')
d.set_mode('white')
time.sleep(2)
print(' Colour')
d.set_mode('colour')
time.sleep(2)
print(' Scene')
d.set_mode('scene')
time.sleep(2)
print(' Music')
d.set_mode('music')
time.sleep(2)
# Done
print('\nDone')
d.set_white()

@ShaneSpina
Copy link
Author

I figured it all out days ago.. sorry I should have updated.

@jasonacox
Copy link
Owner

Awesome! Thanks for the note. I'll close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants