TuyaGateway v2.0 now available

Edit: Update - I set anonymous to true from false and can now see the switch in HA. They are switched off by default, whenever I switch them on, they switch back off again.

MQTT Switch payload - https://i.imgur.com/KmCkNrw.png
Tuya Gateway log - https://pastebin.com/iJFw0ypZ
Listening to topic shows this - https://i.imgur.com/V4jq87P.png

2020-09-10 22:40:38,302 ERROR    (Thread-7) [tuyaface.tuyaclient] (192.168.86.62) Unexpected exception
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/tuyaface/tuyaclient.py", line 194, in run
    result = command(*args)
  File "/usr/lib/python3.8/site-packages/tuyaface/tuyaclient.py", line 217, in _status
    status_reply, all_replies = _status(self.device)
  File "/usr/lib/python3.8/site-packages/tuyaface/__init__.py", line 268, in _status
    new_replies = list(reply for reply in _receive_replies(device, 1))
  File "/usr/lib/python3.8/site-packages/tuyaface/__init__.py", line 268, in <genexpr>
    new_replies = list(reply for reply in _receive_replies(device, 1))
  File "/usr/lib/python3.8/site-packages/tuyaface/__init__.py", line 406, in _receive_replies
    raise ex
  File "/usr/lib/python3.8/site-packages/tuyaface/__init__.py", line 401, in _receive_replies
    for reply in _process_raw_reply(device, data):
  File "/usr/lib/python3.8/site-packages/tuyaface/__init__.py", line 169, in _process_raw_reply
    payload = aescipher.decrypt(device["localkey"], data, False)
  File "/usr/lib/python3.8/site-packages/tuyaface/aescipher.py", line 22, in decrypt
    return _unpad(raw).decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 0: invalid start byte

Hello. First of all, thank you for creating the Tuya Gateway. I’m trying to move from Tuya Local and I’m struggling a little. I’m hoping you can help me figure out what I’m doing wrong.

What do I want?
I have a tuya smart plug (switch) which I’d like to use via Home Assistant

Problem
I don’t see a switch in Home Assistant > Devices or Entities

Setup

HA - https://i.imgur.com/7EDSvHT.png
HA log -

2020-09-10 22:00:41 ERROR (MainThread) [homeassistant.components.switch] Error while setting up mqtt platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 192, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 301, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 472, in _async_add_entity
    await entity.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/mqtt/switch.py", line 135, in async_added_to_hass
    await self._subscribe_topics()
  File "/usr/src/homeassistant/homeassistant/components/mqtt/switch.py", line 183, in _subscribe_topics
    self._sub_state = await subscription.async_subscribe_topics(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/subscription.py", line 93, in async_subscribe_topics
    await requested.resubscribe_if_necessary(hass, current)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/subscription.py", line 48, in resubscribe_if_necessary
    self.unsubscribe_callback = await mqtt.async_subscribe(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/__init__.py", line 416, in async_subscribe
    async_remove = await hass.data[DATA_MQTT].async_subscribe(
KeyError: 'mqtt'
  1. I have installed Mosquito Broker via add-on store.
    Config - https://i.imgur.com/iBzSeFz.png
    Here’s the log - https://pastebin.com/mLjkmgTh

  2. I’ve installed Tuya Gateway via https://github.com/sjthespian/addon-tuyagateway
    Config - https://i.imgur.com/zdffMOB.png
    Here’s the log - https://pastebin.com/B9EMTAFk

  3. Here are my Gismo Caster Settings -
    https://i.imgur.com/Pehk66H.png
    Gismo Model
    https://i.imgur.com/7Lgi3pR.png
    Gismo
    https://i.imgur.com/sE9hEbS.png

  4. HA configuration.yaml -
    https://i.imgur.com/gGRZpI8.png

Things I’ve tried

  1. mosquitto_pub -t tuya/bf57555ad780d86beb4h8c/1/command -m ON
    output - Error: Address not available

  2. I’ve also tried adding the below code to config.yaml but that just adds a switch and says it’s unavailable

switch:
  - platform: mqtt
    unique_id: test
    name: "test"
    state_topic: "tuya/bf57555ad780d86beb4h8c/#"
    payload_on: "ON"
    payload_off: "OFF"
    state_on: "ON"
    state_off: "OFF"
    optimistic: false
    qos: 0
    retain: true

@Tradeface Could you be kind enough to let me know what I’m doing wrong here?

1 Like

Very well documented report! Though I’m sadly not sure what the problem is here.
In your screenshot of the ha config topic Imgur: The magic of the Internet it shows name: on/off and device: { name: on/off }. This could be a potential problem; perhaps HA can’t translate that to a “item”

In your gismomodel Imgur: The magic of the Internet it’s called “switch on/off” btw. Did you change that later on? This is in the example so it should work.

In Imgur: The magic of the Internet the state topic ends in /set. That can’t be right. What did you do to get those? Imgur: The magic of the Internet shows the 3 valid topics for the device.

  1. Mosquitto should accept any valid topic and payload. What happens when you pub any other topic?
  2. Gismocaster should auto configure the device. Of course you can add it to a config-file. Your state_topic should match as defined here Imgur: The magic of the Internet. And you’d need a command_topic.

hth in some way :slight_smile:

@Tradeface Hey. It’s me. Your best friend! :laughing:

I think I’ve come across a bug. Whenever I try to control the switch from tuya app to test if it’s working, I see this in TuyaGateway log -

2020-09-12 17:55:18,902 ERROR    (Thread-4) [tuyaface.tuyaclient] (192.168.86.62) Unexpected exception
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/tuyaface/tuyaclient.py", line 160, in run
    for reply in _process_raw_reply(self.device, data):
  File "/usr/lib/python3.8/site-packages/tuyaface/__init__.py", line 169, in _process_raw_reply
    payload = aescipher.decrypt(device["localkey"], data, False)
  File "/usr/lib/python3.8/site-packages/tuyaface/aescipher.py", line 22, in decrypt
    return _unpad(raw).decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x86 in position 4: invalid start byte
2020-09-12 17:55:19,782 ERROR    (Thread-4) [tuyaface.tuyaclient] (192.168.86.62) Unexpected exception
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/tuyaface/tuyaclient.py", line 160, in run
    for reply in _process_raw_reply(self.device, data):
  File "/usr/lib/python3.8/site-packages/tuyaface/__init__.py", line 169, in _process_raw_reply
    payload = aescipher.decrypt(device["localkey"], data, False)
  File "/usr/lib/python3.8/site-packages/tuyaface/aescipher.py", line 22, in decrypt
    return _unpad(raw).decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: invalid continuation byte
2020-09-12 17:55:20,560 ERROR    (Thread-4) [tuyaface.tuyaclient] (192.168.86.62) Unexpected exception
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/tuyaface/tuyaclient.py", line 160, in run
    for reply in _process_raw_reply(self.device, data):
  File "/usr/lib/python3.8/site-packages/tuyaface/__init__.py", line 169, in _process_raw_reply
    payload = aescipher.decrypt(device["localkey"], data, False)
  File "/usr/lib/python3.8/site-packages/tuyaface/aescipher.py", line 22, in decrypt
    return _unpad(raw).decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x86 in position 4: invalid start byte

Here’s my gismo -

I observed that everyone’s DeviceID starts with a number, mine starts with an alphabet. Not sure if that is causing the issue.

My device ID from tuya cloud -

It’s not a bug. It is a fact. The TuyaGateway depends on a python port of codetheweb/tuyapi.Unfortunately, that api only supports Tuya api 3.1 and Tuya api 3.3 protocols. If you have a alphanumeric deviceid (and not a numeric (hex) device id), you have a Tuya protocol 3.2 device, and that is not supported by either tuyaGateway or codetheweb/tuyapi.

Hi,
I have installed Gismocaster as a service, following the procedure here https://github.com/TradeFace/gismocaster/wiki/Installation but there is nothing displayed on http://127.0.0.1:8111/admin

The console is well alive

September 16, 2020 - 14:19:44
Django version 3.0.7, using settings 'web.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
2020-09-16 14:20:41,927 DEBUG    [paho.mqtt.client] Sending PINGREQ
2020-09-16 14:20:41,929 DEBUG    [paho.mqtt.client] Received PINGRESP
2020-09-16 14:21:42,004 DEBUG    [paho.mqtt.client] Sending PINGREQ
2020-09-16 14:21:42,006 DEBUG    [paho.mqtt.client] Received PINGRESP
2020-09-16 14:22:42,079 DEBUG    [paho.mqtt.client] Sending PINGREQ
2020-09-16 14:22:42,081 DEBUG    [paho.mqtt.client] Received PINGRESP
2020-09-16 14:23:42,157 DEBUG    [paho.mqtt.client] Sending PINGREQ
2020-09-16 14:23:42,158 DEBUG    [paho.mqtt.client] Received PINGRESP
2020-09-16 14:24:42,234 DEBUG    [paho.mqtt.client] Sending PINGREQ
2020-09-16 14:24:42,235 DEBUG    [paho.mqtt.client] Received PINGRESP
2020-09-16 14:25:42,309 DEBUG    [paho.mqtt.client] Sending PINGREQ
2020-09-16 14:25:42,311 DEBUG    [paho.mqtt.client] Received PINGRESP
2020-09-16 14:26:42,385 DEBUG    [paho.mqtt.client] Sending PINGREQ
2020-09-16 14:26:42,386 DEBUG    [paho.mqtt.client] Received PINGRESP

EDIT: OK that’s more http://127.0.0.1:8000/admin/login/?next=/admin/
Now I must login but I have no possibility to create my admin account.

EDIT 2: It’s so bad. I was really interested in Gismocaster, but I can’t go further because of this login page!

Hi, I just updated the addon from version 0.3 to version 0.6, but with ingres it won’t open, if instead I go to http://192.xxx.xxx.xxx:8111/admin/tuya/gismo/ or with xxx.duckdns.org:8111/admin/tuya/gismo/ I log in regularly … For completeness I have installed the program on a nuc with Debian 10

1 Like

HI! I was finally able to setup everything after few hours! I’m able to control my device locally, unfortunately I can’t get the wattage and power consumption that ofc I can get via the Tuya app.
Using Tuya-cli I get an error and on MQTT I get only the on/off state. Is there something that I can do to solve this problem? Thanks

I am not sure if I am fully understanding this or not but are the devices supposed to auto populate? I can see some replies in the log within the addon log section but none are showing up under the mqtt integration devices.
Thanks,

I there I just found this gold today im trying to add to my HA I have a vacum from tuya (alfawise gearbest v8s) And some loratap 2 switch elements did any one try to add this ?

Hi all, just part of the way through getting this working and gismocaster is particularly challenging. I’m using a venv for home assistant so about the first thing is to go into the homeassistant folder and do source bin/activate for me this gives me an active python3.9 install.

git clone https://github.com/TradeFace/gismocaster.git
cd gismocaster
make
make install

The first challenge is getting it working on an external interface.

set an ip address and port to bind to

python3 web/manage.py runserver 192.168.3.254:8111 --noreload

This will bring up the interface but you probably can’t log in
create a superuser

python manage.py createsuperuser --username=joe --password=joespassword [email protected]

Now try again and hopefully you can get into the interface.

Hi see my post further down I figured out how to set a user and password :slight_smile:

Now I seem to be missing an mqtt connection to gismocaster I need to go see if I can get some secrets from Tuya

I have tried to configure tuyagateway using gismocaster for a double gang tuya light switch. I can see the state of the switches coming through MQTT to Home Assistant just fine. When I turn the physical switch on and off the state in HA changes straight away.

However, when I set the state using HA (through a button etc…) the state in HA changes but the physical switch stays off. I have looked in the mosquitto and tuyagateway log files and see the following;

In mosquitto;
tuya/0162532698f4abdfe5e9/1/command ON
tuya/0162532698f4abdfe5e9/1/state ON
tuya/0162532698f4abdfe5e9/2/state OFF
tuya/0162532698f4abdfe5e9/attributes {“1”: true, “2”: false, “11”: false, “104”: false, “105”: false}

In tuyagateway;
Dec 31 11:08:10 raspberrypi python3[11118]: tuya/0162532698f4abdfe5e9/1/state ON
Dec 31 11:08:10 raspberrypi python3[11118]: tuya/0162532698f4abdfe5e9/2/state OFF
Dec 31 11:08:10 raspberrypi python3[11118]: tuya/0162532698f4abdfe5e9/attributes {“1”: true, “2”: false, “11”: false, “104”: false, “105”: false}

If I press the physical switch I see the following in mosquitto and tuyagateway;

In mosquitto;
tuya/0162532698f4abdfe5e9/1/state ON
tuya/0162532698f4abdfe5e9/2/state OFF
tuya/0162532698f4abdfe5e9/attributes {“1”: true, “2”: false, “11”: false, “104”: false, “105”: true}

In tuyagateway;
Dec 31 11:08:40 raspberrypi python3[11118]: tuya/0162532698f4abdfe5e9/2/state OFF
Dec 31 11:08:40 raspberrypi python3[11118]: tuya/0162532698f4abdfe5e9/attributes {“1”: true, “2”: false, “11”: false, “104”: false, “105”: true}

I note that dps 105 gets set to ‘true’ (along with dps 1) when i press the physical switch. So I assume that the issue with HA is that it does not set dps 105 at the same time at setting dps 1.

Is there any configuration I can do using gismocaster to make this work? Or does the implementation only work for single gang switches?

Thanks!

I would just like to get this working, installed a couple of times but I cannot get further than that. If I click on the Open Web UI button I get cannot connect.

I have tried using the default config as I already have MQTT Broker running and I have also tried setting the values in the config, both have the same result.

I have searched for hours in the forums etc but cannot find any suggested way of getting this working.

The development concept is great but with people who have limited knowledge of Home Assistant it’s very frustrating trying to get things working.

homeassistant.local refused to connect.

Running on Raspberry Pi 4

Any help would be very much appreciated

i can see gismo web over ingress. with https. but all work if i go to ip:8111. WHY?

@tayanov From what I remember the last time I worked on this, Gismo doesn’t support SSL. If you are running HA on SSL, it will try and use SSL for that as well which will fail. I don’t know that there is a way for me to get the ingress functionality working in that case. I just checked and the ingres config in config.json in the addon is configured to use http, HA just isn’t respecting that.

@malballuk As tayanov mentioned above, try just going to port 8111 instead of using the Open Web UI link. That should work. For example, if you currently go to https://homeassistant.local:8123 to get to HA, try going to http://homeassistant.local:8111 to get to the Gismo interface (note – “http”, not “https”)

I’ll be honest, while I wrote the addon, I’m not using it any more. If found it frustratingly difficult to get the TuyaGateway and GismoCaster configured and just decided to use the Tuya integration for the few Tuya-compatible bulbs I have until I eventually replace them.

Thanks for the answer, I only have 3 Tuya covers so I think I am doing the same as you and keeping the Integration. I did manage to get the LocalTuya working but couldn’t find a way of using it with my curtains, I couldn’t find the right combination of commands to open and close.

I’m looking at abandoning Tuya altogether. I was only using it for a couple of ceiling fans that have candelabra base bulbs, and I just decided to grab a ConBee II and some new Zigbee bulbs and give those a try.

Could we use cloud?i m newbie here.

Is there a list of compatible devices for v2.0?

It seems the project is abandoned as ingress fails for 2 years.