Smartlife/tuya and tuuya-mqtt

Hi

I’m running lubuntu on virutalbox
Java version openjdk 11.0.11
openhab version 3.1.0
tuya-mqtt version 3.0.4
I have this plugs

I have been trying for months now, but I’m still stuck. What have I done wrong?

I can’t get my smartlife/tuya WiFi to connect to mqtt/openhab

I think I understand the basics in mqtt. I’m able to test mosquitto_sub and mosquitto_pub and get my message through, for test use (hello_world), when I don´t need keys, IP etc

I have been looking at this.

but I installed mosquitto separate on my server.

so:

/etc/openhab/services
I added
mqtt.cfg file

broker.url=tcp://192.168.1.183:1883
broker.clientId=openhab
broker.user=openhab

Then this

I installed it in /etc/openhab/scrips and not /opt
In my case

/etc/openhab/scripts/tuya-mqtt
config.json file

{
“host”: “192.168.1.183”,
“port”: 1883,
“topic”: “tuya/”,
“mqtt_user”: “”,
“mqtt_pass”: “”
}

I got my tuya info from tuya-cli and iot.tuya.com

/etc/openhab/scripts/tuya-mqtt
devices.conf file

[ { name: 'Taklampan ',
id: ‘bfa6f7b5d701a3fxxxxxx’,
key: ‘4cb04f6c71xxxxxx’ },
{ name: ‘Hallen’,
id: ‘bf4c71b76e7c6bfxxxxxxx’,
key: ‘b9d6cc3c26dxxxxx’ },
{ name: 'Sovrumstv ',
id: ‘0377748668c63xxxxxxx’,
key: ‘426cdbcdexxxxxx’ },
{ name: ‘Sovrumslampan’,
id: ‘0226785468c63xxxxxxxx’,
key: ‘ccff77103cxxxxxxx’ },
{ name: 'extra kontakt ',
id: ‘60568156b4e6xxxxxxx’,
key: ‘337e320255xxxxxx’ },
{ name: ‘lampan lilla rummet’,
id: ‘0226785468c63xxxxxx’,
key: ‘f6ea4623751xxxxx’ } ]

run sudo node tuya-mqtt.js

To openhab
MQTT-broker is online

Generic MQTT Thing add channel
mark on/off switch

MQTT State Topic
tuya/hallen/bf4c71b76e7c6bfxxxxxxx/b9d6cc3c26dxxxxx/192.168.1.10/state # I have also tested without IP address

MQTT Command Topic
tuya/hallen/bf4c71b76e7c6bfxxxxxxx/b9d6cc3c26dxxxxx/192.168.1.10/command

restart openhab

I have also tested to set custom on/open value
{“dps” : 1, " set" : 1,} #test true as well

and off
{“dps” : 1, " set" : 0,} #test false as well

I have also tested gismocaster/tuyagateway but no luck

I don’t understand what I’m doing wrong.

Thank you for your help

were you able to receive any readbacks from your thing by a non-openhab mqtt client (such as mqtt lens)?

First, as @h4pevz suggested, check that your mqtt values are coming through, using MQTT Explorer or a similar mqtt watcher.

To check, make a change to one of your devices in Smart Life app. The state of the object and it’s change should be visible in mqtt Explorer.

If this fails, you have an issue with tuya-mqtt.

If that is working, then you just need to sort our your binding:

If you are using the latest version, you should be able to bind like this:

tuya/lampan_lilla_rummet/dps/<dps channel>/state

TOP TIP: mqtt explorer will also give you the full topic info, which you can copy into the channel binding.

1 Like

Finally some steps forward. I got some info on mqtt explorer
I installed a new version of ubunutu, mqtt-tuya and mosquitto.

mqtt explorer info

my device.conf file

[ { name: ‘Sovrumslampan’,
id: ‘0226785468c63axxxxx’,
key: ‘ccff77103cxxxxx’ },
{ name: ‘Taklampan’,
id: ‘bfcbd76cf1c31e7xxxxxx’,
key: ‘bdbba457fc0xxxxx’ },
{ name: ‘Hallen’,
id: ‘bf924ac6513b79cxxxxxx’,
key: ‘c845928af19xxxxx’ },
{ name: 'Sovrumstv ',
id: ‘0377748668c63xxxxxxx’,
key: ‘426cdbcde1bxxxxx’ } ]

sudo sed -n ‘9p’ < devices.conf

I got error on key c845928af19xxxxx (key for “hallen”), what have I done wrong there?

why can’t I run:
DEBUG=tuya-mqtt:* tuya-mqtt.js

I just get this error:
tuya-mqtt.js: commandot not found
so I can’t get any debugs info.

Why can’t I see “sovrumslampa” and “sovrumstv” in mqtt explorer?

mqtt explorer:
I have tried topic (for “sovrumsplampan”):
tuya/0226785468c63axxxxx/ccff77103cxxxxx but no connection

So two questions, (hopfully I’m home after this)

openhab topic
tuya/hallen/dps/1/state # or dps/102/state
tuya/hallen/dps/1/command

I can only use openhab once t.ex smartlife app, on (light is on)

openhab, change to on (light went off) but I can’t turn it on again

Openhab dosen’t pay attation to status, just change it from whatever. Light is on, openhab button off, I turn it on, the ligth went off, but the openhab button shows on, and just one time. Then I have to use smartlife app again.

When I use openhab, mqtt explorer shows command = OFF or ON (but no action)

when I use smartlife app, mqtt explorer chance state = true/false and the lights turn off/on

I’m running openhab 3.1.0
I’m not sure which binding version I’m running

Thanks for all your support

Problem solved.
I had to power off/on my plugs. Then it pop up on mqtt explorer so I cloud set up openhab.

Thanks!