Jump to content

Tuya Wifi Bulb control?

Recommended Posts

  • 5 weeks later...
  • 3 weeks later...
  • Administrator

Can you set up access to the API, using the instructions from the link you shared?

Step 1: CLIENT_ID and SECRET_KEY

  • Register or Login on Tuya.
  1. Create a cloud development project Cloud -> Project.
  2. After successful creation, you will receive the Client ID and Secret Key.

Step 2: DEVICE_ID

  1. Install Tuya Smart app or Smart Life app on your mobile phone.
  2. Go to Cloud -> Link Devices page.
  3. Selecting a tab Link Devices by App Account.
  4. Click Add App Account and scan the QR code with Tuya Smart app or Smart Life app.
  5. Now you can go to devices Cloud -> Device List and copy Device ID.
    • Notes: Try to select a your region if devices are not displayed.

Step 3: Request access to API calls
Go to Cloud -> API Group and enable Authorization management, Device Management and Device Control.

We can hopefully use the python script if you can get things set up.  The challenge with anything with anything like this is that if I don't have it I can't test it to figure out how to make it work.   The only Tuya thing I have is luckily Hue compatible.

Let me know if you get this set up and I'll suggest your next steps.

Link to comment
Share on other sites

19 hours ago, Matt said:

Can you set up access to the API, using the instructions from the link you shared?

Step 1: CLIENT_ID and SECRET_KEY

  • Register or Login on Tuya.
  1. Create a cloud development project Cloud -> Project.
  2. After successful creation, you will receive the Client ID and Secret Key.

Step 2: DEVICE_ID

  1. Install Tuya Smart app or Smart Life app on your mobile phone.
  2. Go to Cloud -> Link Devices page.
  3. Selecting a tab Link Devices by App Account.
  4. Click Add App Account and scan the QR code with Tuya Smart app or Smart Life app.
  5. Now you can go to devices Cloud -> Device List and copy Device ID.
    • Notes: Try to select a your region if devices are not displayed.

Step 3: Request access to API calls
Go to Cloud -> API Group and enable Authorization management, Device Management and Device Control.

We can hopefully use the python script if you can get things set up.  The challenge with anything with anything like this is that if I don't have it I can't test it to figure out how to make it work.   The only Tuya thing I have is luckily Hue compatible.

Let me know if you get this set up and I'll suggest your next steps.

I actually did get that part set up, I was playing with Home Assistant like someone suggested, so I do have an API key and Client ID.

 

I experienced some other Home Assistant issues so I don't think I'm going to be using that, but I would love to try out anything else you suggest.

Edited by starslayer74
Link to comment
Share on other sites

  • Administrator

Here's my best guess on how to make this work:

  1. Download tuya-bulb-control-main.zip, PreShow.py, and Tuya.pseaction below.
  2. Unzip tuya-bulb-control-main.zip and place it somewhere that your system can access. 
  3. Move PreShow.py to that folder.   
  4. Edit PreShow.py and change the following to the correct details:
    CLIENT_ID = ''
    SECRET_KEY = ''
    DEVICE_ID = ''
    REGION_KEY = ''
  5. Move Tuya.pseaction to the Actions folder in your PreShow Content directory.
  6. Edit "python://path/to/script.py" to the location of PreShow.py.
  7. Test the action.

I don't know if that will work and I can't do anything to test it.  If it does work, it won't do what you want it to do, but that's right now we just want to see if it does anything.  If it works, we can figure out how to make it do what you want afterwards.

Let me know how it goes.

And if there's anyone else with Tuya bulbs, please let us know so that we can get more people to help test.

tuya-bulb-control-main.zip PreShow.py Tuya.pseaction

Link to comment
Share on other sites

On 10/2/2023 at 4:19 PM, Matt said:

Here's my best guess on how to make this work:

  1. Download tuya-bulb-control-main.zip, PreShow.py, and Tuya.pseaction below.
  2. Unzip tuya-bulb-control-main.zip and place it somewhere that your system can access. 
  3. Move PreShow.py to that folder.   
  4. Edit PreShow.py and change the following to the correct details:
    CLIENT_ID = ''
    SECRET_KEY = ''
    DEVICE_ID = ''
    REGION_KEY = ''
  5. Move Tuya.pseaction to the Actions folder in your PreShow Content directory.
  6. Edit "python://path/to/script.py" to the location of PreShow.py.
  7. Test the action.

I don't know if that will work and I can't do anything to test it.  If it does work, it won't do what you want it to do, but that's right now we just want to see if it does anything.  If it works, we can figure out how to make it do what you want afterwards.

Let me know how it goes.

And if there's anyone else with Tuya bulbs, please let us know so that we can get more people to help test.

tuya-bulb-control-main.zip 9.74 kB · 0 downloads PreShow.py 391 B · 0 downloads Tuya.pseaction 26 B · 0 downloads

I just gave it a go, ran into a few issues:

 

1. I'm not sure what to put in for Region Key

Here is a screenshot of the error I got:

image.thumb.png.f36930c560cb5e634cea582cbb2d58f8.png

 

Link to comment
Share on other sites

  • 2 weeks later...
10 hours ago, starslayer74 said:

Assuming I could get the lights to talk to Home Assistant, is there a way to trigger it using HA commands in Preshow Experience?

Yes easy done. I run my lifx beam though HA triggered by Preshow. Get it working in HA and I can help with the rest.

Edited by Johno
Link to comment
Share on other sites

12 hours ago, Johno said:

Yes easy done. I run my lifx beam though HA triggered by Preshow. Get it working in HA and I can help with the rest.

I really appreciate that. I'm going to build a little HA server on an old Raspberry PI and I'll report back when I have it up and running.

 

Thank you for the assistance!

Link to comment
Share on other sites

On 10/29/2023 at 1:17 PM, starslayer74 said:

Ok, I have it up and running. I can turn the bulbs on and off, and change colors/brightness in the Home Assistant dashboard.... I am clay in your hands 🙂

STEP 1

You have to create a script first, I'll guide you though a simple script to turn on a light, to do this:

Goto Settings - Automations & Scenes - Scripts (from the tabs menu on the page)

1. Press the "+ ADD SCRIPT" button on the bottom right of the page.
2. Select "Create new Script"
3. Name your script eg: "Turn_on_Cinema_Light"  No spaces and give it a icon if you like.
4. Press "+ ADD ACTION" from the drop down select "Call a service"
5. From the Service drop down select "Light: Turn on" and select "Choose device" and select your light you want to turn on. you can also select brightness and color if you like.
6. Press Save
7. To test the script, from the Traces menu (right top side with 3 dots), select run script, the light should turn on.

Edited by Johno
Link to comment
Share on other sites

STEP 2 - Create a Long-lived access tokens

1. Select "Profile" menu from the side menu, its the last one on the bottom under Notifications.
2. Scroll to the "Long-lived access tokens" section
3. Press "CREATE TOKEN" Give it a name eg: "Cinema" doesn't really matter what you call it.
4. Make sure to copy the code and save it, as you wont be able to see it again, the token will be about 180 chars long.

Edited by Johno
Link to comment
Share on other sites

STEP 3

Create a action script to use with PreShow.

Change the ** ** to suit.

http://**YOUR HA IP ADDRESS**:8123/api/services/script/turn_on
HEADERS: {"Authorization": "Bearer **PASTE YOUR LONG-LIVED ACCESS TOKEN HERE**", "Content-Type": "application/json"}
POST: {"entity_id": "**YOU SCRIPT NAME  eg script.Turn_on_Cinema_Light **"}


Sample attached.

Let me know if you run into any problems and I will create a pdf guide with screen shots etc.

HA is fantastic to what you can do with it example: If someone presses my door bell camera and I am in my home cinema, I have a automation script that will pause the movie playing and display a popup message, saying someones at the front door and also shows the camera video feed. Once you start theirs no going back 🙂.

Movie_Pause.cvaction

Edited by Johno
  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share


 Share

×
×
  • Create New...