Smarthome/J Tuya Binding for openHAB 4

Got it working. Thank you so much.

Hi. I’m unable to install the binding. OpenHAB version 4.0.3 - Release Build

Tried both console:
openhab> bundle:install https://docs.smarthomej.org/4.1.0-SNAPSHOT/org.smarthomej.binding.tuya-4.1.0-SNAPSHOT.kar
Bundle IDs:
Error executing command: Error installing bundles:
Unable to install bundle https://docs.smarthomej.org/4.1.0-SNAPSHOT/org.smarthomej.binding.tuya-4.1.0-SNAPSHOT.kar: org.osgi.framework.BundleException: OSGi R3 bundle not supported

And from the GUI. When installing from GUI I get the following:

Installation of add-on marketplace:150699 failed

Any ideas how to proceed? Iäm using the snapshot repo.

br.
Tom

Why don‘t you use the JSON 3rd Party Marketplace? That is the recommended way to install it. Add https://download.smarthomej.org/addons.json and be happy.

I have added that to the Settings, as mentioned above. And I get the " Installation of add-on marketplace:150699 failed" error when installing.

1 Like

But an add-on with the marketplace: prefix is from the community marketplace (in this forum). If you scroll down, you should see a section labeled “Other add-ons”. Pick it from there.

I’m feeling unusually stupid atm… I have added:
https://download.smarthomej.org/addons-snapshot.json
to the “Json 3rd Party Add-on Service” setting. It said somewhere that you should use that for OH4, instead of just addons.json. So let’s start there: which one is correct? I tried both with the same error.

And now for the Bindings installation menu: I only see “openHAB Distribution” and “Community Marketplace”. When I search for “tuya”, I get one hit. WHICH I know realize, gives me an entirely different Binding called “Smarthome/J Tuya Binding support for WIFI TUYA Energy Meter 63A”

So sorry about this, entirely my fault for not noticing this before. I couldn’t see the “Other add-ons” option, but I have now found the option that enables it and can now see the plugin.

And it installed fine. Thanks for pointing out some details which lead me to figure out the problem.

1 Like

No. addons-snapshot is for openHAB versions where no release is available (i.e. 4.1 at the moment). For openHAB versions that are a release (i.e. 3.4.x or 4.0.x) use addons.

Suggestions how to add a Tuya-based device without auto-discovery?
I have an infrared panel installed in my office and using the Smarthome/J binding I created the Thing which is showing as online. So far, so good.
But, since my OpenHAB instance is running in a different subnet (and in a pod/container) I cannot discover it automatically.
And since I use configuration files (instead of UI) I was wondering how a Channel configuration would look like. Does anyone have any hints?

UPDATE: After restart the ‘WiFi Thermostat heater’ shows up as discovered Thing. My last question still stands: thoughts on Thing/Channel definitions using config file?
To try and figure out the configuration (deducting from the YAML code generated via Main UI when adding Thing), I added the discovered Thing manually and added the IP address and protocol version (used 3.3), which brings the Thing ONLINE.

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