Can't get tuya lights in openhab 3.2.0 to link to items

I’m running openHAB 3.2.0 on my freeBSD 13 server with mosquitto 2.0.13 both installed from the pkg manager(think it also installed some version of the java runtime 11 for it, can’t easily find the exact version) and have the tuya-mqtt 3.0.4 script from TheAgentK running.

I’m new to openHAB so I don’t know exactly what I’m doing, I just have a rough idea of what needs to be done from reading and I really don’t seem to have the easiest device for a first time.

From a fresh install, doing everything from the webui using chrome, I installed the MQTT Binding addon and Added an MQTT broker thing which is online so I assume it’s ok.
tuya-mqtt is configured with the broker settings(pretty much the defaults) and I added my 2 light devices in the device config from the tuya-cli wizard output and only added the ip and the type to RGBTWLight to it for each.

When I start the tuya-mqtt node.js script, openHAB detect 2 new things which are the lights I configured so I tell it to create the thing and a channel for color gets automatically added for both, but the thing status is set to unknown pretty much all the time, only seen it as online or offline once or twice while messing around.
The thing type for the lights is HomeAssistant MQTT Component so I looked up the manual for it and installed the JSONPath and Jinja Transformation addon it says is required for it.

Now from what I understand, I need to link an item to the channel to be able to control something but when I try to do add a link to item…, create a new item and press link, it tells me “There is no profile available for the selected item” and after looking up the learn more about profiles link, it seems I need transformation addons for that but the 2 that are required for the type those lights use are already installed so I’m at a loss for what I’m doing wrong here.

I tried sending commands to the lights with tuya-cli to make sure the protocol version from my lights is supported, but I can’t find a concrete example for it and whatever I try just returns error so I’m not sure if I’m doing something wrong or if the lights are the issue so if someone has an example for turning a light on with it, that would be appreciated so I know if I’m wasting my time or not.

I’ve read about people getting this working with openhab 3 so it shouldn’t be broken, but there’s so much contradicting information from the different openHAB versions that’s it’s hard to debug issues so if anyone can help, it would be very much appreciated.

I use tuya-mqtt and manually set up the things and items in openhab with generic mqtt. I don’t use the homeassistant automatic discovery.

Firstly on the tuya-mqtt side (nothing to do with openhab at this point) have you

  • configured your device in tuya-mqtt correctly by adding the device id and local key
  • verified that tuya-mqtt sends status out via mqtt
  • Allows you to control the device when you send an mqtt message to the relevant topic?

You can monitor your mqtt messages using:

$ mosquitto_sub -h yourbrokers_ip_addr -t '#' -v
1 Like
  1. Yes, I do have the device id and key in the device.conf file configured.

  2. I did not and if the mosquitto_sub command is supposed to show me that, I get no output from it(I did put my ip and eventually just removed the -h option since it’s all on the same host and that’s the default). I let it sit running while I was eating and got no output. I don’t know if I need to do something to provoke an output or not though.

  3. I’m not sure how to do that. I was trying to test using tuya-cli set or get command which I assume does that but what I tried failed and I couldn’t find an example for it to know if I’m the problem or not.

Edit: I restarted node tuya-mqtt.js and I got a bunch of output from mosquitto_sub with online status, their proper state(one is on, other is off which fits) the home assistant stuff and a bunch of possible config for both devices.

That’s great. You could send a command to tuyamqtt using mosquitto_pub with -t topic -m payload

If that works (i.e. turns on/off your light) then time to move on to openhab setup.

1 Like

Would you mind elaborating a bit more on what would be a correct topic to send and what the payload should be to turn a switch on or off.

I assume the payload is the value, true or false and that topic is something like tuya/bedroom_smart_lighting/state but I don’t know if I need to add the id, key and ip before state in that or if state should be command instead or if I need to use tuya/bedroom_smart_lighting/dps/1/state instead with or without the id/key/ip again so I’m just blindly trying stuff not knowing if it’s not working or if I’m doing it wrong.

Edit: Finally managed to figure out it’s “tuya/bedroom_smart_lighting/dps/1/command” for the topic and I was right about the payload. worked first in my openhab generic test because I apparently skipped that one for that specific light in mosquitto_pub and the other light isn’t responding, possibly because I re-added it to the tuya app after I got the key and I’ve read that might change it.

Edit2: Yep, key changed. Got the new one so I can control both lights with mosquitto_pub now.

So in openHAB, I’ve set a channel in a generic thing for one of the lights to turn it on and off and it works so I assume I have to set a channel for each of the dps state I see in mosquitto_sub that I want to control, unless there’s a more general channel type that can cover more than one.
There’s also the issue of knowing what each one does and the possible values but I guess I can figure it out with the app if there’s no ressource available with those information.

Yes, you’re correct. You need one channel for each “topic” (i.e. dps item?) you’d like to get the status of, and/or control.

Turn it on/off and you’ll see (using mosquitto_sub) what changed.

If you specified the “type” in your tuya-mqtt devices.conf, it will also give you a more “user friendly” topic in addition to the dps topics. You can just use the user friendly one.


This is what I SEND from openhab:
tuya/hallway_light_2/command OFF

This is what I get back:
tuya/hallway_light_2/state OFF
tuya/hallway_light_2/dps/state {"20":false}
tuya/hallway_light_2/dps/20/state false

Knowing this, my channel then looks like this:

Type switch: power [ stateTopic="tuya/hallway_light_2/state", commandTopic="tuya/hallway_light_2/command" ]

The ON/OFF is the default of what openhab sends so they don’t need to be specified.

1 Like

I see, so that’s what the topics without dps are, user friendly ones from the type and I can use those too, good to know.

I should be able to figure out the rest from here, thanks a lot for your help.

Just one other thing I was wondering, should I set something in the advance config of the generic thing for the “Availability Topic”?

It is possible that you could use the “homeassistant” mode of integrating with it. I haven’t tried it. I usually use the manual method as above.

I have only just learnt about this feature myself - literally yesterday (or two days ago).

I believe you can set it as follows:

  • availabilityTopic=“tuya/YOURDEVICENAME/status”
  • payloadAvailable=“online”
  • payloadNotAvailable=“offline”

But it seems that tuya-mqtt didn’t send this as a retained message, so perhaps it’s better to leave them empty

1 Like

I still have the same issue I had in the first post with the homeassistant mode, the “There is no profile available for the selected item” error when I try to create an item. I did test that with the light that was working before all this so nothing changed for it. If it can work, there’s something I’m missing still.

Good timing for me asking then, I’ll leave it alone for now and fiddle with it once I’ve messed around with openHAB more.

Thanks again for all your help, it’s great to be able to see results after 2 days of messing around with it.

Nothing wrong with just setting it up manually (not using homeassistant integration). It has been working fine for me that way.

Enjoy your openhab journey! Don’t be shy to ask if you’re stuck

1 Like

This usually means that you are trying to link an Item to a trigger (event) type channel in error.

1 Like

It does say Trigger in parenthesis, more specifically the id followed by #color (Trigger) so not sure what that’s supposed to be used for, the home assistant mqtt component page didn’t have much info.

At least now I know why it wasn’t working, thanks.

Typically, a trigger channel is used for something like a button press. There’s no state really, so its not sensible to link it to an Item with a static state. It’s an event that happens.

You can trigger rules directly from channel events to control other activity.

I just saw it was the only channel that got auto-generated, it had color in the name and the homeassist thing says it supports color changes so not knowing much since I didn’t get to look into rules yet, I assumed it was something that would at least allow me to change the color.

I guess it’s a trigger for when the color gets changed for the light. Seems kind of weird to me that they auto-generate something that would only work for that and not also control basic things about the device, but there’s probably a reason for it.

Don’t think so; we don’t normally transmit anything to the outside world on trigger channels, they are an openHAB internal thing.

You are up against two black box processes here.

Whatever this tuya-mqtt script does to your real devices , in terms of making them look like a HomeAssistant device that it can advertise. Do you know, can you find out what that is expected to do?

Then there’s the discovery part of the openHAB MQTT binding that detects HomeAssistant devices, and creates Things and channels from its findings. This may itself be less than perfect.
You don’t need that to work at all, if you configure Things and channels manually.

Yeah, I’m definitely going to configure it manually, especially since it seems I wouldn’t even be able to control the light as a switch if I used the home assistant thing, just confused me before I knew more and I’m a bit curious of what it’s supposed to do.

They didn’t mention details about it in the readme of tuya-mqtt but it is open source on github so I could did around in the code to find out if I’m ever that motivated.