Smarthome/J Tuya Binding for openHAB 4

Managed to get the Bridge configuration using a config file like this:

Bridge tuya:project:infraheater "Tuya Cloud Project" @ "Office" [accessId="{{tuya_id}}",schema="smartLife",password="{{tuya_password}}",dataCenter="https://openapi.tuyaeu.com",countryCode="31",accessSecret="{{tuya_secret}}",username="{{tuya_user}}"]

With the Thing configuration I have no luck so far. This does not work:

Thing tuyaDevice officeHeater "Infrared Heater" @ "Office" [pollingInterval=60, protocol="3.3", productId="{{heater_product_id}}", deviceId="{{heater_device_id}}", ip="{{heater_ip}}", localKey="{{heater_local_key}}"]

The Tuya Thing remains UNITIALIZED with error “BRIDGE_UNINITIALIZED”. Somehow the Thing is not associated with the Bridge.

UID: tuya:tuyaDevice:infraheater:officeHeater
label: Infrared Heater
thingTypeUID: tuya:tuyaDevice
configuration:
  pollingInterval: 60
  protocol: "3.3"
  productId: **REDACTED**
  deviceId: **REDACTED**
  ip: 10.20.1.245
  localKey: "**REDACTED**"
bridgeUID: tuya:project:infraheater
location: Office

It’s not a bridge/thing. They are all only things.

1 Like

Thanks.

Any suggestions how to format the tuyaDevice Thing?

This:

Thing tuya:project:infraheater "Tuya Cloud Project" @ "Office" [accessId="{{tuya_id}}",schema="smartLife",password="{{tuya_password}}",dataCenter="https://openapi.tuyaeu.com",countryCode="31",accessSecret="{{tuya_secret}}",username="{{tuya_user}}"]
Thing tuya:tuyaDevice:officeheater "Infrared Heater" @ "Office" [protocol="3.3", productId="{{heater_product_id}}", deviceId="{{heater_device_id}}", ip="{{heater_ip}}", localKey="{{heater_local_key}}"]

creates a Thing for the Tuya Cloud Project that gets the status ONLINE, but the tuyaDevice Thing shows CONFIGURATION_ERROR “No channels added and schema not found.”.

Adding the discovered Thing in the UI does work (after adding the IP address and protocol version. It shows the same YAML-configuration in the Code-tab as the config-file Thing, except for the added Channels. One difference I noticed is that the working tuyaDevice Thing has two additional discovered Thing Properties: mac and category (not in the YAML-config).

No idea. I always recommend to use discovery and managed configuration. File-based configuration is the source of 90% of the trouble we have with binding configuration.

OK, it was quite simple to create a .things file:

Thing tuya:project:infraheater "Tuya Cloud Project" @ "Office" [accessId="{{tuya_id}}",schema="smartLife",password="{{tuya_password}}",dataCenter="https://openapi.tuyaeu.com",countryCode="31",accessSecret="{{tuya_secret}}",username="{{tuya_user}}"]
Thing tuya:tuyaDevice:infraheaterheater "Infrared Heater" @ "Office" [protocol="3.3", productId="{{heater_product_id}}", deviceId="{{heater_device_id}}", ip="{{heater_ip}}", localKey="{{heater_local_key}}"] {
  Channels:
    Type switch : switch "Paneel Aan/Uit" [dp=1]
    Type number : temp_set "Doeltemperatuur" [dp=2]
    Type number : temp_current "Huidige temperatuur" [dp=3]
}

The Thing Channels just needed dp= parameter and the temperature channels can also take two other parameters (min= and max=) which seem to represent a temperature range.

1 Like

Did Tuya change something in their API?

I see this in logs
[WARN ] [ding.tuya.internal.cloud.TuyaOpenAPI] - Request failed: Result{timestamp=1705332850312, code=1106, msg=permission deny, success=false, result=null}, no token received

I checked Secret and ID 5 times and they are correct. I got no errors with curl.

Works fine for me. Did you also check password, username and most important data center and country code?

Yes, it’s me being stupid.
LastPass was overwriting my pass input… Duh.

Hi all!
Stupid question, but how do you start the discovery service? In OpenHab UI I go to Settings > Things press on +, select Tuya Smarthome/J binding, see this:
image

And press scan. Correct?
In my case, it doesn’t find anything. The project binding is ok.

(I’m using OH4.1.1 with the new fixed json from @J-N-K today :wink: )
Thanks for any answer!

Found it. You need to add authorization to IoT Core and Authorizations API :slight_smile:

2 Likes

Hi @pverhoye! I am facing the exact same problem, what were the steps you took exactly?

Hi Jannis!
In the Tuya IoT platform, go to Cloud Services and activate IoT Cloud and Authorization Token Management
image

That did it for me.

BB
Peter

Thanks, it worked!

That’s in the documentation, but it’s a little buried in a bullet point.

@J-N-K, I’d suggest breaking this section up with sub-bullets to help it stand out more.

  • Go to iot.tuya.com (the Tuya developer portal) and create an account.
    • You can choose any credentials (email/password) you like (it is not necessary that they are the same as in the app).
  • After confirming your account, log in to your new account.
  • On the left navigation bar, select “Cloud”, then “Create new Cloud project” (upper right corner).
  • Enter a name (e.g. “My Smarthome”), select “Smart Home” for “Industry” and “Development Method”.
    • For security reasons, select only the “Data Center” that your app is connected to (you can change that later if you select the wrong one).
  • Select “IoT Core”, “Authorization” and “Device Status Notification” as APIs.
    • You should be redirected to the “Overview” tab of your project.
    • Write down (or copy) “Access ID/Client ID” and “Access Secret/Client Secret” (you can always look it up in your account).
  • In the upper menu bar, select the “Devices” tab, then go to “Link Tuya App Account” and link your App account.

Hi Everyone,

I don’t understand why my dimmer switch (Gosund) don’t work.
I can switch it ON/OFF from Openhab and the physical button.
I can use the physical dimmer and it modified the bright_value in Openhab.
But when I modify the bright_value in Openhab, nothing happen.
I have 2 of them, and it’s exactly the same behavior for both.

Each Things have been added by the Binding, using the scan button.
Here’s the configuration of the channel :

The DPs have been validated using the Tuya Platform and the manual method described here : Find Tuya Data Points | Zigbee2MQTT

I have nothing in the logs except the value changed in the events.log :

2024-02-28 08:08:47.530 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Bar_Light_bright_value' received command 59
2024-02-28 08:08:47.531 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Bar_Light_bright_value' predicted to become 59
2024-02-28 08:08:47.532 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Bar_Light_bright_value' changed from 36 to 59

I suspected a missconfiguration between the item, the min/max value, the fact that it’s a dimmer, etc…
But I tried a lot of configuration and find nothing…
Can someone help me ?

Here’s the TRACE log I have from Openhab;
Everything seems to work, I can do an update from the Smart Life app, fom Tuya Platform, from Postman…
But the “bright_value” command from Openhab just didn’t work.

[a.internal.local.handlers.TuyaEncoder] - [DEVICE_ID]/[IP]:6668: Sending CONTROL, payload {devId=[DEVICE_ID], uid=[DEVICE_ID], t=1709576826, dps={1=true, 3=89}, gwId=[DEVICE_ID]}

[a.internal.local.handlers.TuyaDecoder] - [DEVICE_ID]/[IP]:6668: Received MessageWrapper{commandType=CONTROL, content='[B@2737708e'}

This looks like a DEBUG entry. Before you should see a TRACE entry with something like decoded raw payload. Can you share that one? [B@2737708e indicates the payload is a byte array, which is odd.

I am trying to use the binding with a Tuya RainPoint irrigation Hub (that have and integrated Switch) with irrigation controllers, but it is impossible to control. The binding detects all, it seems “online” (except Gateway), no errors on Debug log, but doesn’t receive any data or change state of switch or irrigaiton.
I have tried also with TinyTuya with Python, but same “bad” result.
I have searching information, and it seems that any of both not support devices “not directly connected” to the WiFi. In this case, the devices are connected to Gateway that is the device connected to WiFi. Anybody knows more about that? This issue can be resolved (or any workaround)?

Thanks
Ruben
PD: This is the irrigation controller:
RainPoint Smart WiFi Sprinkler Timer – RainPoint Irrigation (rainpointonline.com)

I recently tried setting up a Tuya Zigbee hub to see if that could be an alternative solution, but since the Zigbee child devices didn’t have their own IP addresses they remained offline. This sounds like it might be a similar issue.

These threads on Home Assistant and LocalTuya might provide some hints, but it sounds like lots of people have struggled with this.

Thanks @rpwong , exactly that seems the same issue.
Just yesterday test the only working solution that I found, that is binding Tuya App with Alexa, and so actuate to the irrigation through Alexa. But, is very very bad solution: I only see the irrigation as a switch, but can’t see anymore, not integrated switch on Gateway, not any of the available parameters on irrigation controller as flow, timers, battery, etc…