TuyaAPI / cli

🔧 A CLI for Tuya devices
MIT License
261 stars 44 forks source link

device simulate #92

Closed briggitteorellana closed 3 years ago

briggitteorellana commented 3 years ago

does the tuya-cli mock option only simulate a socket device? or can it simulate another type of device?

briggitteorellana commented 3 years ago

Hello, help me please. I am trying to manage a virtual device in home assistant that is in virtualbox, but when managing it I get an error ayuddaa333

192.168.1.137 is the ip of my computer where I have running tuya-cli mock. when I send something to the device it disconnects and sends this error ayudaaaa ayudaaaaaaaa

codetheweb commented 3 years ago

does the tuya-cli mock option only simulate a socket device? or can it simulate another type of device?

You can mock whatever state type you want by passing the -s parameter:

➜ tuya-cli mock --help
Usage: tuya-cli mock [options]

mock a Tuya device for local testing

Options:
  -i, --id [id]        ID to use for mock device
  -k, --key [key]      key to use for mock device
  -s, --state [state]  inital state to use for device (default: "{\"1\":true,\"2\":false}")
  -u, --disableUDP     disable the UDP broadcast
  -h, --help           display help for command

when I send something to the device it disconnects and sends this error

It looks like whatever implementation of the Tuya protocol that you're using in Node RED doesn't set the timestamp field correctly. Can you provide a link to the package you're using in RED?

briggitteorellana commented 3 years ago

I'm using tuya local https://github.com/subzero79/node-red-contrib-tuya-local

help1

briggitteorellana commented 3 years ago

All that works for me when I manage it from node-red on my computer, but when I use the virtual machine where I have it Home assistant, the virtual device no longer manages me and it disconnects. When I use a real device if it works for me on both sides, it is only when I use the virtual

briggitteorellana commented 3 years ago

ayudaaaaaaaa why that error?

codetheweb commented 3 years ago

It's possible the date on your virtual machine isn't set correctly. Make sure date or similar outputs the correct value.

Also, can you provide the debug log of the stub device running? (Set DEBUG=*, for example DEBUG=* tuya-cli ....)

briggitteorellana commented 3 years ago

enviar1

codetheweb commented 3 years ago

Everything looks right there. Can you check the date in the command prompt you're running tuya-cli to make sure the date is correct there as well?

briggitteorellana commented 3 years ago

Thanks I managed to solve it. Can I run more than one simulated device on my computer? I need to simulate more at the same time

codetheweb commented 3 years ago

Without knowing your use case, the easiest way might be using Docker containers. You can assign each one a different IP.

Otherwise, you'd have to add an option to tuya-cli mock that allows you to manually specify the port it listens on. Then you would have multiple devices listening on the same IP but different ports.

codetheweb commented 3 years ago

Closing because of inactivity.