TuyaGateway v2.0 now available

from fixture:

{
    "model": "homeassistant.topic",
    "pk": 127,
    "fields": {
        "name": "set_position_topic",
        "abbreviation": "set_pos_t",
        "specialized_for": null,
        "topic_type": "subscribe",
        "publish_topic": 128,
        "default_value": "~set_position"
    }
},
{
    "model": "homeassistant.topic",
    "pk": 128,
    "fields": {
        "name": "position_topic",
        "abbreviation": "pos_t",
        "specialized_for": null,
        "topic_type": "publish",
        "publish_topic": null,
        "default_value": "~position"
    }
},

They have been mapped the wrong way. set_position_topic should be a "topic_type": "publish" and v.v.

Home Assistant Log

extra keys not allowed @ data['payload_off']

Also a mapping problem. See https://github.com/TradeFace/tuyagateway/issues/76

(Sidenote, but one peculiar thing I noticed from the logs …

This might be caused by old settings that where not fully cleared from mqtt.

I have alarm panel with dps:
{
1 disarmed
2 20
3 1
4 false
9 true
10 false
15 true
16 100
17 true

}

as I understand dps1 its mode of alarm: armed, disarmed, stay, home. Which topic I must to setup for work in gismo?

@Aare check some of the earlier posts, it’s in my github repo (along with a couple of other addons):

1 Like

Where do I find this v2.0?
From the OP I landed on https://github.com/TradeFace/tuyagateway/ , is this v1.0?
Opened the wiki from that page which has the installation link on the right hand side but with very a basic explanation so was wondering if I’m missing something.

Is there a more detailed howto to install this?

use addon
https://github.com/sjthespian/addon-tuyagateway

I was never able to get this working, but I was able to get my cover device working using the below Home Assistant add-on which locally controls Tuya devices.

The developer is pretty active and helped me debug some issues, and there are a few pull requests outstanding to add more functionality.
https://community.home-assistant.io/t/tuya-local-with-energy-monitoring-and-without-tuya-convert

localtuya has delay when send status of switch. tuyagateway work without any delay. But energy monitoring localtuya setup easy

I found bug. I setup loglevel WARN in tuyagateway in settings, but in log I see DEBUG rows.

mqtthost: ‘mqtt://core-mosquitto’
mqttport: ‘1883’
loglevel: WARN

I have no inherent issue with using TuyaGateway, but I could not get it to work after hours of trying. The documentation is lacking, and there aren’t many (or any) examples of working setups. And i’m not a approaching this as a novice, I studied computer science for a few years.

1 Like

Can you open a bug at https://github.com/sjthespian/addon-tuyagateway/issues so I don’t lose track of this? The add-on should just be passing that value on to the tuyagateway code, but I need to dig in a bit and see if I’m not handling the command line arguments correctly.

1 Like

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.