dresden-elektronik / deconz-rest-plugin

deCONZ REST-API plugin to control ZigBee devices
BSD 3-Clause "New" or "Revised" License
1.9k stars 498 forks source link

Tuya Smart Plug missing metering data (_TZ3000_cphmq0q7) #4838

Closed muratcorlu closed 2 years ago

muratcorlu commented 3 years ago

Describe the bug

I bought 4 Tuya Zigbee smart plugs and easily connected to Phoscon (running with Conbee II on Rpi4). I use them on my HomeKit setup via Homebridge. One of them worked perfectly with metering functionality but 3 of them doesn't report metering data. Working one has _TZ3000_8nkb7mof vendor name and others has _TZ3000_cphmq0q7.

Steps to reproduce the behavior

  1. Start pairing a smart plug with _TZ3000_cphmq0q7 vendor name.
  2. Pair with with Phoscon GW
  3. Restart HomeBridge
  4. Check if you have consumption data on Eve Home app. (Or in HomeAssistant)

Expected behavior

I expect to see consumption data on Eve Home App or HomeAssistant.

Screenshots

Here is the list of devices in Phoscon App:

image

Detail screen of working one:

image

Detail screen of one of the non working devices (be aware this has version info):

image

Eve Home screenshot of working device:

image

Eve Home screenshot of one of the non-working devices:

image

Environment

deCONZ Logs

I use headless deconz. I currently couldn't figure out how to fetch debug logs. I'll update if I can.

Additional context

NijsKei commented 3 years ago

I have exactly the same problem. Why it always must be difficult. 2 are working well a 2 are working not. Only the switches are doing their job but no measering.

Mimiix commented 3 years ago

Unfortunately,this is the downside of having cheaper devices.

The support was added to the one that works. The others have new chips/manufacturer names. That needs to be whitelisted.

Can you provide screenshots from deconz as a device request?

oywino commented 3 years ago

I have exactly the same problem. Setup: Conbee Firmware: 266B0700 deConz Version: 2.11.02 beta / 4/30/2021

Device is registered in Phoscon as a Light. No measuring data is present. On/Off works fine. Here are my deConz screen dumps:

image

image

image

On/Off Cluster: image

Simple Metering Cluster: image

image

REST-API:

{
    "etag": "db47fd907f3381714dc29b86101ac2f3",
    "hascolor": false,
    "lastannounced": null,
    "lastseen": "2021-05-19T18:38Z",
    "manufacturername": "_TZ3000_cphmq0q7",
    "modelid": "TS011F",
    "name": "On/Off Tuya 1",
    "state": {
        "alert": "none",
        "on": true,
        "reachable": true
    },
    "swversion": "67",
    "type": "On/Off plug-in unit",
    "uniqueid": "84:71:27:ff:fe:8d:96:1d-01"
}

When I manually press the button on the device ( from On --> Off ) I get this event:

{
    "20:50:43:832": {
        "attr": {
            "id": "18",
            "lastseen": "2021-05-19T18:50Z",
            "manufacturername": "_TZ3000_cphmq0q7",
            "modelid": "TS011F",
            "name": "On/Off Tuya 1",
            "swversion": "67",
            "type": "On/Off plug-in unit",
            "uniqueid": "84:71:27:ff:fe:8d:96:1d-01"
        },
        "e": "changed",
        "id": "18",
        "r": "lights",
        "t": "event",
        "uniqueid": "84:71:27:ff:fe:8d:96:1d-01"
    },
    "20:50:43:873": {
        "e": "changed",
        "id": "18",
        "r": "lights",
        "state": {
            "on": false,
            "reachable": true
        },
        "t": "event",
        "uniqueid": "84:71:27:ff:fe:8d:96:1d-01"
    }
}
Smanar commented 3 years ago

For me the code is blocking for the reason exposed by @muratcorlu, the device have

And the code don't like that, there is a hack for light device but not for sensor. There is many way to help

Ugly one like

        if (node->nodeDescriptor().manufacturerCode() == VENDOR_SAMJIN)
        {
            swBuildIdAvailable = false; // empty string
            dateCodeAvailable = false; // unsupported attribute
        }
        else if (modelId == QLatin1String("HG06323")) // LIDL Remote Control
        {
            swBuildIdAvailable = false; // unsupported attribute
            dateCodeAvailable = false; // empty string
        }

But for me it s possible with using dateCode.isNul(), but in this situation we will have swversion with null value.

Need to ask first the autorisation at others devs.

oywino commented 3 years ago

@Smanar, thanks for stepping in - but what you just said is "gibberish" to me. Could you "translate" it into layman's English? 😊

Smanar commented 3 years ago

Lol. I have a code to test

sudo apt install deconz-dev
git clone --branch tuya_plug_1 https://github.com/Smanar/deconz-rest-plugin.git
cd deconz-rest-plugin
qmake && make -j2
sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins

This code (if it work) try to get the Swbuild, then the date code and finaly the Application version to fill the "swversion" field.

You will have in log with "info"

DBG_Printf(DBG_INFO, "[4.1] Get sw build id\n");
DBG_Printf(DBG_INFO, "[4.1] Get date code\n");
DBG_Printf(DBG_INFO, "[4.1] Get Application version\n");

And after the device will be included.

oywino commented 3 years ago

Sorry, I don't understand. The issue in this thread is: Tuya Smart Plug missing metering data (_TZ3000_cphmq0q7) That is my problem too. Is your "code" going to solve this problem if your "test" is successful ?

muratcorlu commented 3 years ago

@oywino Smanar has a fix on his/her fork and asks for test it if it fixes our problem.

But I also couldn't understand this part:

This code (if it work) try to get the Swbuild, then the date code and finaly the Application version to fill the "swversion" field.

@Smanar What is swbuild?

oywino commented 3 years ago

swbuild is Software Build number, I guess. I'd love to test whatever it is @Smanar want us to test, but I have no clue how to do this. Is it possible to prove a step-by-step in human understandable terms ? 😊 sudo apt install deconz-dev isn't something I can do on my system. I have deconz running in a docker container and it needs a ton of environment variables set correctly in order to run at all.

Smanar commented 3 years ago

Sorry.

To make short, the deconz code ATM, prevent sensor creation for device without "swbuild", it s a field visible in the Json. By defaut it s the attribute 0x4000, visible on capture on first post, if this attribute is not available, the code take the datacode (0x0006) but for this device the value is empty, so the code stop here. With my change it will use the application version.

The procedure is explained here https://github.com/dresden-elektronik/deconz-rest-plugin#install-deconz-development-package-optional-linux-only

But you need a linux OS with full OS, I can't explain how to do on docker.

oywino commented 3 years ago

Ok, I see. But what did @Mimiix mean when he wrote that "It needs to be whitelisted" ? I was hoping that meant that a quick-fix was imminent.... 😢

Smanar commented 3 years ago

And not sure my fix will work too ^^. In all situation, we realy need a test, and for that we need you, we haven't the device.

oywino commented 3 years ago

I would need another ConBee dongle and a test system to do this. ANd I don't have that. My existing set up is a productions system that I cannot take down. It would be easier for me to send a device to you. But it would be nice if @Mimiix would join us again and clarify his opinion.

Smanar commented 3 years ago

Don't worry, you are not alone with this bug. No one here have the device, the problem, and a linux machine ?

Mimiix commented 3 years ago

@oywino where do you need my opinion on?

oywino commented 3 years ago

@oywino where do you need my opinion on?

Hi @Mimiix , you wrote (if I understood correctly) that all that was needed was to whitelist the device (?) https://github.com/dresden-elektronik/deconz-rest-plugin/issues/4838#issuecomment-844002948

I was hoping that this could turn out to be an easy fix ?

Mimiix commented 3 years ago

@oywino where do you need my opinion on?

Hi @Mimiix , you wrote (if I understood correctly) that all that was needed was to whitelist the device (?) https://github.com/dresden-elektronik/deconz-rest-plugin/issues/4838#issuecomment-844002948

I was hoping that this could turn out to be an easy fix ?

Well that's what I thought. But @Smanar says it isn't that easy, so I'm with him on this one. I'm not a developer so I can't change anything about this unfortunately.

oywino commented 3 years ago

Well that's what I thought. But @Smanar says it isn't that easy, so I'm with him on this one. I'm not a developer so I can't change anything about this unfortunately.

Ok, I see. @Smanar - are you a developer (maintainer) ? I wish I could be of any help....

Smanar commented 3 years ago

For the moment need someone with the device, with the issue and with a linux machine to test the code modification.

oywino commented 3 years ago

I guess a "linux machine" can be arranged by simply installing Linux on a laptop. Which Linux do you recommend, and what would be the preferred installation config?

Smanar commented 3 years ago

I think all Linux version are supported, I have see some issues with dev package not found for some X64 but I think now it s corrected. There is that in doc

Ubuntu
Supported Ubuntu versions

    Ubuntu 16.04 LTS 64-Bit PC (AMD64)
    Ubuntu 18.04 LTS 64-Bit PC (AMD64)
    Ubuntu 20.04 LTS 64-Bit PC (AMD64)

Classic install, not "light" "custom", headless (the desktop can be usefull for debugging) or docker.

oywino commented 3 years ago

Ok, I need to find one more ConeBee II because I cannot disconnect the one I have in production. I hope setting up two ConBee coordinators in my house isn't going to cause any problems (interference) with my existing network (?)

Smanar commented 3 years ago

No, no danger, but just to make test, idk what is managed by your zigbee network, but you can just unplug the conbee from your production machine, make the test, and replug it. You just need 2 mn to check if the code is working (if you have the sensor or not), and 15 mn to test it.

oywino commented 3 years ago

Ok, do you have step-by-step on how to install and config deConz on Ubuntu 20.04 (inkluding links)?

Smanar commented 3 years ago

Yep, first update the OS then

https://phoscon.de/en/conbee2/install#ubuntu

Then after with command line

sudo apt install deconz-dev
git clone --branch tuya_plug_1 https://github.com/Smanar/deconz-rest-plugin.git
cd deconz-rest-plugin
qmake && make -j2
sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins
oywino commented 3 years ago

Should I do all this first:

image

Smanar commented 3 years ago

Yep, it s to configure the package stuff. Can choose beta or stable, no difference, we will recompile code.

oywino commented 3 years ago

Ok, and you are 100% sure that using my production Conbee isn't going to screw up my existing config when I plug it back again in my production server (after our "experiment") ?
I have a large number of ZigBee devices connected to it now. My whole house will stop working when I disconnect it 😢

Smanar commented 3 years ago

Ok, and you are 100% sure that using my production Conbee isn't going to screw up my existing config when I plug it back again in my production server (after our "experiment") ?

Sure, the network configuration is stored on the device (but not modified if you just plug/unplug/replug, and devices configurations are stored on host.

I have a large number of ZigBee devices connected to it now. My whole house will stop working when I disconnect it

But yes, all your devices will stop working, and the mesh can need some time to be full working. But like I have said, can wait some days to see if someone else can test the code, for exemple @muratcorlu or @NijsKei And if the code not work, can need to make more tests ...

SwoopX commented 3 years ago

Just make a backup via Phoscon as a safety measure.

oywino commented 3 years ago

I tried to follow the procedure. But when I got the command:

qmake && make -j2

It just gives me the help list of commands and options as if it didn't understand the command. Then this command:

sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins

gives the following error:

cp: cannot stat '../libde_rest_plugin.so': No such file or directory

Now what?

Smanar commented 3 years ago

I think it have an error here

sudo sh -c "echo 'deb [arch=amd64] http://phoscon.de/apt/deconz $(lsb_release -cs) main' > /etc/apt/sources.list.d/deconz.list"

I think now it s better to edit direclty the sources.list file to correct the error.

oywino commented 3 years ago

Ok, so I tried again, and now, the command:

qmake && make -j2

gave the following error messages

Project ERROR: Cannot run compiler 'g++'. Output:
=============
=============
Maybe you forgot to setup the environment?

So, I installed build-essential Then I could almost run:

sudo make && mak -j2

But it failed again on:

Could not create output file
make[1]: *** [Makefile.Release:543: ui_de_web_widget.h] Error 1
make[1]: *** Waiting for unfinished jobs...
Assemler messages:
Fatal error: can't create release/air_quality.o: permission denied
make[1]: *** [Makefile.Release:573: release/air_quality.o] Error 2
make[1]: Leaving directory '/deconz-rest-plugin'
make: *** [Makefile:42: release] Error 2

I can launch deconz, and it sees the coordinator, and immediately begins to populate the dashboard with all my devices in my house. It's a mess and it's impossible to identify these devices because they have only hexadecimal numbers and no names.

Obviously, something is wrong. Please be aware that I am on European time zone. It's getting late.

Smanar commented 3 years ago

I can launch deconz, and it sees the coordinator, and immediately begins to populate the dashboard with all my devices in my house. It's a mess and it's impossible to identify these devices because they have only hexadecimal numbers and no names.

This is normal, remember the devices config is on the host, not on the gateway. So somes devices appear on deconz, because devices are trying to connect, but deconz can't reconize them without the database. Just ignore them.

For the error compilation, IDK, first time I see that.

Try to retry it from clean project (I don't use sudo on my side)

make clean
qmake && make
oywino commented 3 years ago

I tried, but I get the make error just as described above (and I don't understand what this error means). In addition, the copy command fails:

sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins

because the directory does not exist. So, I do not know if I did get your code installed in deconz properly, or not. I can see the Tuya in the deconz, dashboard and in Phoscon, but I do not know how to check if the REST-API has all the attributes or not.

Smanar commented 3 years ago

So, I do not know if I did get your code installed in deconz properly, or not.

No, if it don't compile, the file is not created, so it can't be copied, so for the moment you can let the conbee on your production machine.

I can see the Tuya in the deconz, dashboard and in Phoscon, but I do not know how to check if the REST-API has all the attributes or not.

If the compilation fails, you can't have it.

You have updated the OS ?

sudo apt update
sudo apt full-upgrade

Perhaps a right permission ? on the folder you have installed the github archive ?

oywino commented 3 years ago

I did

sudo apt update
sudo apt upgrade

but not

sudo apt full-upgrade
Smanar commented 3 years ago

and same error message ?

oywino commented 3 years ago

Yes, those folders do not exist.

oywino commented 3 years ago

So, what now?

Smanar commented 3 years ago
Could not create output file
make[1]: *** [Makefile.Release:543: ui_de_web_widget.h] Error 1
make[1]: *** Waiting for unfinished jobs...
Assemler messages:
Fatal error: can't create release/air_quality.o: permission denied
make[1]: *** [Makefile.Release:573: release/air_quality.o] Error 2
make[1]: Leaving directory '/deconz-rest-plugin'
make: *** [Makefile:42: release] Error 2

Sorry, realy have no idea where it can be from.

oywino commented 3 years ago

Where does this leave us? Couldn't you just add your code to a branch beta version, ready compiled for docker and upload to Docker HUB, and I can test it. If it works then fine, if not I should at least be able to feed you the result (log). Would that be of any help?

Mimiix commented 3 years ago

Not running sudo could be it?

@oywino smanar is doing all he can. He's trying his best. That would go beyond what he should do and he is going above and beyond already.

oywino commented 3 years ago

@oywino smanar is doing all he can. He's trying his best. That would go beyond what he should do and he is going above and beyond already.

Sorry - I tried earlier to find out his position in this so that could adjust my expectations accordingly, but I guess I never got an answer, so I assumed he was the maintainer with all privileges and the ultimate knowledge (which I myself don't have ). I am prepared to do what ever is being asked of me in order to assist, but as much of this is beyond my expertise, I need a step-by-step in order to succeed.
And yes, I did after a while understand that I had to add 'sudo' to every command, and I did. Isn't there anyone who can step in shortly and assist us so that I can complete the test that smanar wants me to do? I am prepared. I'm just a bit lame. 😶

Smanar commented 3 years ago

I realy don't understand, your procedure is good, you are not the first one that do that, but it s the first time I m seing this result. Try to restart but in another folder (with more permissions) Just this part

sudo apt install deconz-dev
git clone --branch tuya_plug_1 https://github.com/Smanar/deconz-rest-plugin.git
cd deconz-rest-plugin
qmake && make -j2
sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins
oywino commented 3 years ago

Hi @Smanar, sorry for being so ignorant, but please know that I'm not a Linux guy. So, you must provide more guidance; What folder do you think I should use? How do I assign more permissions on folder level and subfolder and files ?

Smanar commented 3 years ago

I m not a linux guy too ^^. Try to mke a new folder, on the "basic root" that open when you run the console. And try to change it's right using

mkdir folder_name   
sudo chmod -R 777 folder_name

then go in it cd folder_name

and retry

sudo apt install deconz-dev
git clone --branch tuya_plug_1 https://github.com/Smanar/deconz-rest-plugin.git
cd deconz-rest-plugin
qmake && make -j2
sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins
oywino commented 3 years ago

Hi @Smanar, Sorry for my late reply. I have been on a business trip. But I haven' given up yet. Hope to find some more time next week. Meanwhile. - I don't understand why HA is unable to detect these values, when they are easily visible in deConz: image

If i plug/unplug something, I can sit and watch the values change in deConz.

Smanar commented 3 years ago

Ha take value in the API, not in deconz.

oywino commented 3 years ago

Ok, and it's the mapping from deConz to the API that is incorrect or missing?