-
Notifications
You must be signed in to change notification settings - Fork 191
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
set dimmer level #572
Comments
It looks like the DPS that dimmer uses is slightly different than the DPS the bulbs use. Can you post the output of |
Device status: {'dps': {'1': False, '2': 301, '4': 'LED', '6': 0}} |
I think 301 is the brightness level, which translates to 30%. Other devices (bulbs) seem to allow for a level of 1-100%. Haven’t tried it, just typing out loud. Could be something completely different. |
Possible, though I can't say I've seen the app use something besides 0 for the last digit when the range is 1.0 - 100.0. Can you use the app to set it to 0%, say 60%, and 100%, and call |
No matter what I set as level (0,60,100), the last item (6) is always 0. The value of 2 does change accordingly. One thing I must add: an action on this dimmer takes its time to execute, while others simply fly. Strangely only with the on action, when turning it off it’s instant. The endgoal is to have it run locally mainly for not having to go outside my network, but speed is also a factor. |
I would recommend running a monitoring loop (see https://github.com/jasonacox/tinytuya/blob/master/examples/monitor.py) and then change the dimmer levels to see what events get sent from the device. |
Can you post the actual values from those different levels so I know what you're dealing with? If you answered 'Y' to the "Download DP Name mapping?" question during the wizard there should be a hint as to what DP 6 does in the devices.json file. |
I’m using tinytuya standalone and didn’t use the wizard as my devices are on a separate VLAN. The value I’m sending is “30”. Haven’t had time to run monitor.py. What I also haven’t tried is sending a value like 300 btw. |
Does this help?
While the script was running, I set the brightness using the Tuya app which resulted in this output. Meanwhile I have also tried setting the brightness to 500 using TinyTuya, this didn't change anything. I also found out what was causing the delay mentioned ealier. I'm also setting "set_colourtemp_percentage" with every action to force the colour to the same for every device. Since this particular dimmer doesn't support this, this causes a delay as my turn_on action came after set_colourtemp_percentage. I have since changed this so turn_on comes first and level + set_colourtemp_percentage come second/third. |
I would try some code like this to manage this devices: import tinytuya
import time
# Connect to Device
d = tinytuya.OutletDevice(
dev_id='DEVICE_ID_HERE',
address='IP_ADDRESS_HERE',
local_key='LOCAL_KEY_HERE',
version=3.3)
# Get Status
data = d.status()
print('set_status() result %r' % data)
# Turn On
d.turn_on()
# Read Value of DPS 2
data = d.status()
print("Value of DPS 2 is ", data['dps']['2'])
# Change DPS 2 - go from 100 to 1000
for i in range(100,1000,100):
print("Setting DPS 2 to ", i)
# convert i to string
d.set_value(2, str(i))
time.sleep(1)
# Read Value of DPS 2
data = d.status()
print("Value of DPS 2 is ", data['dps']['2'])
# Turn Off
d.turn_off() |
This does seem to do the trick:
Level needs to be a value from 10-1000. But is there a way to combine this in the project instead of having to add this only for this specific dimmer? Btw it’s a dimmer from MOES. |
I started a rewrite of BulbDevice that would make it easy to remap the DPs for cases like this, but in my usual fashion I then got distracted and never finished it 🤣 Unfortunately the current BulbDevice doesn't have a way to override the DP. I'll see if I can get my rewrite finished and pushed within the next week or so. |
The Wizard is how you retrieve the local keys, it does not try to connect to devices unless you answer 'Y' to the "Poll Devices?" question. If you did not run it then how did you get your local keys? |
I got the local keys from the Tuya developer login. |
Much appreciated! For now I’ve added an if statement to my script so I can go ahead and migrate all of my devices to local control instead of using the cloud api. My wife will be sooo happy. Oh and I’ve learned some Python so win-win 👌🏻🤣 |
I'm looking into this script to control my Tuya devices locally. I'm not familiar with Python, but so far it's looking promising and I'm already able to control my RGBWW lightbulbs (on/off/level) and outlets (smartplugs). Continuing with the code used for my lightbulbs I was also able to switch on/off my dimmers, but I'm not able to control the level. The following turns on the device, but does nothing with the brightness level:
I'm familiar with the Tuya Cloud API and from this I've been using bright_value_v1 to set the level of my dimmers and bright_value_v2 to set the level of my lightbulbs.
Am I on the right track? Or should I take a completely different approach?
The text was updated successfully, but these errors were encountered: