-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Support 0d devices #389
Comments
There are tuya devices that do not allow to query values via GET ... this is an device issue ... not this library. So they can only have values when they send them by themself. sorry |
I don't think this is a thing - at least, I haven't ran into it. What protocol version are you using? Have you tried both 3.1 and 3.3? Might be related: #234 |
I also saw that from my users. The devices only push data, not possible to GET. Protocal was 3.3 in my examples when I remember correctly (protocol came from proxy sync still, so from official Tuya data) |
Thanks for the comments... But we have anyway a problem: the handling of the unallowed operations by device+tuyApi. Example of unallowed operation:
For unallowed operations, a quiet abort is a correct strategy, not the message "json obj data unvalid" ( what json data???). So a correct flow in tuyapi can be:
Abut "response exists, but don't produce a valid JSON structure" I fond that: device (sirene) response to a change (type) done by smartLive:
The field "excode" is added by code: Very strange is the presence of many 0x00 bytes in a JSON value (not visible in the string !)
crazy behavior :) Best regards |
I think there might be a misunderstanding. But there's a couple issues with doing it this way. First, silently failing is very rarely the best option; if an error occurs the user needs to know about it. More importantly, TuyAPI doesn't really have a way to check if a given payload is valid or not. There's no known schema to check against. |
Thanks, codetheweb:, for your message.
Rules:
So the programmer can write always: It is important to consider the difference between development (programming) errors, where the messages are helpful to the programmer, and runtime errors: in this case a "silent failing" is a valid option. In hope to help create better tuyapi. :) Best Regards |
I'm having a hard time understanding what you mean by this, could you give an example?
Agreed, but hard to implement. Maybe could configure behavior based on In general, this package is supposed to be a more low-level driver than a comprehensive solution. I'm happy for additional packages to be built on top of this that include built in device schemas, retry functionality, computed state, etc. |
The tuyapi ver. "6.1.1" introduces two new options:
Putting both to false is a partial solution to commands (like 'GET' and 'schema') not handled by some devices and occasionally reported by the device using the misunderstandly "json obj data invalid". The only open issue is the 'ERROR' level in case of connection loss: using But I'm using the "node-red-contrib-tuya-smart-device" ver. 1.2.1, which uses tuyapi 5.3.1.
Best regards |
I'm a little confused on what you're saying here. Are you suggesting that TuyAPI should automatically attempt to re-connect after a 'bad' (user did not ask for it) disconnect? |
That is the normal behavior, having many devices: some can disconnect for many reasons, like power down, interferences etc. Better if Tuyapi doesn't throw an error in case of 'bad' disconnect, but only info or warning.
Changing argument, how about protocol version 3.3 ? (see previous post). best regards |
It looks like I found the solution. You need to send just |
@presidentio interesting ... but what you mean with "can be grabbed from any response"? Is it also in the "discovery telegram"? or do we need to get at least one "pushed telegram"? is that cid identically to the devId or gwId? |
@Apollon77 To get |
Sure, but I search for an automated way of getting it ;-) That's why my questions. Did you checked if the value is the same as devId or gwId? |
Presentio > It looks like I found the solution. You need to send just { cid: 'virtual_device_id' } That about virtual-devices, i.e. sub-devices, linked to tuya via a gateway.
This message is sent by the Zigbee Gateway, and cid identifies univocally the sub-device: the Thermostat#2.
I get the same response message from the device! This standard behavior is not the same for all sub-devices, all dps, all commands: SET/GET/MULTIPLESET/SCHEMA. In my experience, any device is someway special! Testings with many devices I found 4 kinds of answers:
Best regards. |
Hi everybody, I am sharing my experience with Tuya devices that will probably help you handle the "json data unvalid" problem. I am owner of an HA integration called localtuya, that handles communication Tuya devices locally, but without using tuyapi (see https://github.com/rospogrigio/localtuya ).
@codetheweb I don't know how much of the above was of your knowledge, but I think it might help you review the code in order to support the "type_0d" devices too. Feel free to have a look at https://github.com/rospogrigio/localtuya/blob/master/custom_components/localtuya/pytuya/__init__.py and get inspiration. |
Thanks for the info @rospogrigio, it ties together everything. Makes sense now. Open to ideas on how to implement Also, do you know if there's a way to autodetect the device type @rospogrigio? |
I think detection is exactly send get and if you get back "unvalid json" then remember the type. And yes this should be done on get I think, so that it is irrelevant fpr the library user which type it is. you can remember on the first get what it is for all subsequent calls in with using this istance and/or also support an (optional) init flag so that you can diretcly pass in the type when you know from before. These infos are awesome |
PS: hehe detection done as I proposed :-) https://github.com/rospogrigio/localtuya/blob/master/custom_components/localtuya/pytuya/__init__.py#L546 |
I'm very glad to be helpful. Then you might be able to help me handle devices that communicate through a Wifi Zigbee gateway ;-) since I'm getting the same "unvalid json" and I don't know how to get past this... |
I don't currently have enough bandwidth to work on implementing This issue is also getting kinda messy, so I started a new discussion here. Please move discussion about gateways there. |
@codetheweb you might be interested to read also what beatmag is reporting in rospogrigio/localtuya#194 , he has done some interesting discoveries too... |
@BarryW55 I don't currently have a timeline on implementing support; partly because I don't have any 0d devices. As always, happy to accept PRs. :) |
@codetheweb I think I could get this to work, but as I am new to the party and js is not my weapon of choice, please confirm my assumptions about what should be done:
Question: how to determine the actual dps payload to send? In one of the threads the following was proposed: |
Save for the current constructed instance yes, for future program executions no.
Definitely.
If you're asking whether Everything else sounds good, thanks for taking a look! |
@iknop If there is anything I can do to help test, please let me know |
No details, no follow up infos. closing. Please reopen if still relevant and happening with most recent versions. |
I'm using tuyaApi in node-red, via node node-red-contrib-tuya-smart-device.
I have 20+ Tuya devices, like switches, sensors, ad some ZigBee devices. All devices work well in smartLife app.
The node-red actual comportment is:
Example, using a real device, a switch, the command (sets the switch on for 10 s) :
payload: { multiple: true, data: { 1: true, 102: 10}}
produces the answer:
12 Dec 11:50:26 - [info] [tuya-smart-device:fe3fbeb2.ac31f] Data from device: "{"dps":{"1":true,"102":10},"t":1607770225}"
Using a virtual device, i.e. a radiator controller and ZigBee hub, the command (sets the target temperature)
payload: { "devId": "60a423fffeb5b90d", "dps": 103, "set": 220 }
produces the answer:
12 Dec 12:06:24 - [info] [tuya-smart-device:a9ea9736.7483f8] Data from device: "{"dps":{"103":220},"cid":"60a423fffeb5b90d","type":query,"t":1607771183}"
12 Dec 12:14:08 - [info] [tuya-smart-device:fe3fbeb2.ac31f] Data from device: "{"dps":{"1":true},"t":1607771648}"
12 Dec 12:16:12 - [info] [tuya-smart-device:a9ea9736.7483f8] Data from device: "{"dps":{"101":47},"cid":"00158d00056e5022","t":1607771771}"
Switch countdown end:
12 Dec 11:50:36 - [info] [tuya-smart-device:fe3fbeb2.ac31f] Data from device: "{"dps":{"1":false,"102":0},"t":1607770235}"
Temperature from a ZigBee sensor, about every 3600s (request by Tuya cloud?):
12 Dec 12:14:28 - [info] [tuya-smart-device:a9ea9736.7483f8] Data from device: "{"dps":{"103":215},"cid":"60a423fffeb5b90d","t":1607771667}"
It sounds good, so all ok? Sorry, not really.
12 Dec 11:32:32 - [error] [tuya-smart-device:fe3fbeb2.ac31f] json obj data unvalid
This is a big problem because I cannot poll any RO device data points, so some parameters are unreachable.
(see also issue #246 and issue #23)
I tryed also a tuyapi update to version 6, but no changes.
I found it very strange that the answer to a 'SET' command from node-red is always handled well, and the answer to a 'GET' command gets always an error (but the answer is well processed if the 'GET' is from the cloud).
Any idea?
Best regards
m.sillano
The text was updated successfully, but these errors were encountered: