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

Data every second instead of 30s (command 18) #417

Closed
Dema323 opened this issue Feb 5, 2021 · 15 comments
Closed

Data every second instead of 30s (command 18) #417

Dema323 opened this issue Feb 5, 2021 · 15 comments

Comments

@Dema323
Copy link

Dema323 commented Feb 5, 2021

Not a bug, more a question

When my phone is off or the app is not open im getting new data every 30s from the power plug. (consumption data)
But when the i have Smart life open the data gets updated every 1-2s.
Has anyone been able to get new data every second or so without having the app open ?
Thanks

@codetheweb
Copy link
Owner

codetheweb commented Feb 5, 2021

Are you pulling data from Tuya's cloud API or locally directly from the device?

@codetheweb codetheweb reopened this Feb 5, 2021
@Dema323
Copy link
Author

Dema323 commented Feb 5, 2021

i think locally ? i used the example code from the github, also no api calls are counted on my tuya developer account

@codetheweb
Copy link
Owner

Hmm, are you polling the device for updates or waiting for updates to be sent? Can you post your script?

@tsightler
Copy link
Contributor

Based on the research I've seen and a few dumps I've received from other users, when the app is open it's constantly sending a request to update the data, some mysterious "Command 18" type that seems un-documented. Some additional details are here:

rospogrigio/localtuya#194

@codetheweb
Copy link
Owner

Huh, interesting.

I think in this case it's probably the user's responsibility to request updates with that if they want. @Dema323, would you be able to try adding that and see if it works? Might be worth adding a note to the README about.

@tsightler
Copy link
Contributor

@codetheweb How could the user request the updates if TuyAPI doesn't have any way to send a command 18 to the device?

From my perspective the work required is to first figure out the exact structure of the packet (it looks like a 3.1 protocol packet with command type 18 and otherwise empty, basically like a heartbeat packet).

I actually almost wonder if "command 18" is just a new type of heatbeat packet. Perhaps a config option that uses command 18 instead of command 9 for heartbeat, just like some Tuya implementations have a config option to use command 13 instead of command 7 for control packets (I think TuyAPI also has an issue open about supporting devices that use command 13).

I had originally planned to try to do this work myself, but I've decided that Tuya seems intent on making it difficult to control your devices locally and I'm just going to give up my Tuya devices completely (I only have 4 left anyway, and 2 are easily converted to Tasmota, I'll just replace the other 2). While I believe I could implement the required changes in TuyAPI, I'm just no longer sure it's worth the effort.

@tsightler
Copy link
Contributor

@codetheweb I just realized that perhaps there was a misunderstanding here. While a user can certainly query the DPS values every 1 second if they want to, the issue is that doing this does not help. Based on what I can tell these devices don't update their DPS values unless the command 18 packet is sent to them.

And not all devices even update every 30 seconds, some only do it every 5 or 10 minutes. For example, I had a user that had a power monitoring outlet strip. He received updates ~every 300 seconds via tuya-mqtt. In tuya-mqtt I have an option to force an update, which directly queries the DPS values, but even when he did this, his device returned the same values for 300 seconds. However, if he opened the app, suddenly he would get updates every few seconds and the DPS values would actually change.

When looking at the packet trace with tuyadump of the app locally controlling the device, you could see the command 18 packets being sent which seemed to be the trigger to force the device to update the internal DPS values with the most recent values for power consumption.

Basically, without the ability to send this mysterious "Command 18" to the device, there appears to be no way to get more frequent updates.

@tsightler
Copy link
Contributor

tsightler commented Feb 11, 2021

Some more details in another project that appears to have implemented command 18.
jasonacox/tinytuya#8

@Dema323
Copy link
Author

Dema323 commented Feb 12, 2021

im planning on just flashing tasmota and using mqtt.

@stevoh6
Copy link
Contributor

stevoh6 commented Feb 12, 2021

@Dema323 yes, that always good idea whenever its possible. Unfortunately tuya started massively using non esp chips.

@Dema323
Copy link
Author

Dema323 commented Feb 12, 2021

@Dema323 yes, that always good idea whenever its possible. Unfortunately tuya started massively using non esp chips.

I know, i bought 2 with no esp in them. But i got some that arrived today that should have esp's in them

@codetheweb
Copy link
Owner

While I believe I could implement the required changes in TuyAPI, I'm just no longer sure it's worth the effort.

Gotta agree with you there. 😛

Thanks for the additional information, I think I understand now. Unfortunately I don't have any devices that would require this so I can't really implement / test it.

@codetheweb codetheweb changed the title Data every second instead of 30s Data every second instead of 30s (command 18) Feb 14, 2021
@stevoh6
Copy link
Contributor

stevoh6 commented Feb 14, 2021

While I believe I could implement the required changes in TuyAPI, I'm just no longer sure it's worth the effort.

Gotta agree with you there. 😛

Thanks for the additional information, I think I understand now. Unfortunately I don't have any devices that would require this so I can't really implement / test it.

I think most of us was suprised, when we discover that those devices arent esp anymore. Thats why I can see lot of 2-3years old projects for local tuya are reborn :D Any kind of local tuya project - nodejs, python, mqttt, power monitoring, node red integrations :D

I started implementing it, but I just need find more time to understand how nodejs is workig :D

@stevoh6
Copy link
Contributor

stevoh6 commented Feb 15, 2021

Now seems to be working pretty well. Please check/test and provide feedback.

>node _debug.js
Connected to device!
DP_REFRESH data:  { dps: { '19': 127 }, t: 1613388138 }
Data from device: {
  dps: {
    '1': true,
    '9': 0,
    '17': 10,
    '18': 87,
    '19': 127,
    '20': 2466,
    '38': 'off',
    '41': '',
    '42': '',
    '43': ''
  }
}
Boolean status of default property: true.
Data from device: { dps: { '1': false }, t: 1613388139 }
Boolean status of default property: false.
Disconnected from device.

codetheweb added a commit that referenced this issue Mar 20, 2021
Co-authored-by: Max Isom <hi@maxisom.me>
@codetheweb
Copy link
Owner

Closed by #417.

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

No branches or pull requests

4 participants