TuyaGateway v2.0 now available

To be honest, I haven’t had time to look at it and am just using the tuya gateway for now. I couldn’t get MQTT discovery working either, and not just for Tuya. It’s on my todo list if I ever come up for air again…

No worries, thanks for the response. I’ll keep digging through the code behind it all to see if I can figure out exactly what the config in GismoCaster translates to.

In Developer Tools > MQTT - Listen to a topic: tuya/#
Click “START LISTENING”

If you have v2.0.1 installed you should see the tuya/<device_id>/attributes topic

I dont understand as describe it. For localtuya I use in switch.conf

  - platform: localtuya
    host: 192.168.1.83
    local_key: 9a13524a92253ddf
    device_id: 13422004e09806cada82
    name: switch_boyler1
    friendly_name: switch_boyler1
    protocol_version: 3.3
    current: 18
    current_consumption: 19
    voltage: 20

and use current and voltage as sensor. Which need to describe for mqtt?

You can declare a sensor https://www.home-assistant.io/integrations/sensor.mqtt

hth

Edit: at this point GismoCaster follows the HA mqtt spec. In that sense it is just a data bridge between your tuya device and HA. By following the component structure as defined we make sure that display elements get all the needed data. Many devices have sensors/data that doesn’t fit within the spec. Thus you’ll have to work around the component spec. e.g. by manually adding a sensor in a config-file. I understand that less than ideal. But to alter that behavior you would have to develop a complete HA configuration tool within GismoCaster, something HA even doesn’t have (to put it perspective).

May I have version 2.0.0, I use addon for tuyagateway from sjthespian
What I need to do for update tuya gateway? I need to remove addon or enought run this commands:

git clone --depth=1 https://github.com/TradeFace/tuyagateway.git
cd tuyagateway
pip install --no-cache-dir -r requirements.txt
pip install tuyagateway

?

If need to remove addon what I need to backup? I dont want lose any settings from gismo

@Shaman2 The plugin will do a pull from github on every build, so if you click on “rebuild” in the addon page it should automatically upgrade to the new version. Since the database is in persistent storage, you shouldn’t need to back up anything.

Although backups are something I really want to provide at some point. I haven’t figured out where the /data volume in the addon really lives. I may just need to write a “dump” and “restore” into the plugin that can be called from the plugin UI.

yes, rebuild is working. tuyagateway is updated, thank you

Hi. What is the repositories? Can’t find TuyaGateway or GismaCaster in HA supervisor Add-on store.

Hi @Tradeface and everyone else. I’ve spent the whole night trying to get my Tuya-based cover device to work with TuyaGateway, but I have been unable to make it work. I’ve read every post in this thread twice, as well as all open and closed issues on GitHub. I’m going to provide pretty extensive system information, device information and logging, to hopefully help you figure out what the issue is, but also to hopefully help others. I would like to help flesh out some documentation and provide a real-world example for everyone once I get my setup working.

My setup:

  • Everything on my system is up to date (Raspberry Pi OS, tuyagateway, Home Assistant, etc.)

With regards to the device, I have the Key & ID. I have also been able to connect to it with tuya-cli (https://github.com/TuyaAPI/cli). I can both get and set data using tuya-cli. My dps are as follows:

dps: {
    '1': 'close',
    '2': 40,
    '3': 100,
    '5': false,
    '7': 'closing',
    '8': 'cancel',
    '9': 0,
    '10': 0,
    '11': 38610

My understanding of the dps are as follows:

  • ‘1’ is either ‘open’, ‘close’, or ‘stop’. You can set ‘1’ to ‘stop’ to stop an opening or closing that is in progress. I usually then set it back to ‘close’, though i’m not sure that’s necessary.
  • ‘2’ is the dps you set from 0-100 to control the amount the blinds are closed on a % basis.
  • ‘3’ is the previous value of the opening, and usually updates after the opening or closing command is finished. So, for example, if the blind was 50% open, ‘2’ and ‘3’ might both be 50. If you then set ‘2’ to 100, ‘2’ immediately becomes 100, and then ‘3’ will stay at 50 until the blind is done closing, at which point ‘3’ will update to 100.
  • ‘5’ i’m not sure about
  • ‘7’ tells you what action the blind most recently took–was it most recently ‘opening’ or ‘closing’
  • ‘8’ has to do with a countdown which is not relevant for my use of this device
  • ‘9’ is time left, and also irrelevant for my use
  • ‘10’ is total time, also irrelevant for my use
  • ‘11’ I have no idea

What follows are a bunch of screenshots laying out my gismocaster settings. For now, to make things easy and just to get the device working, i’m trying to make this cover work solely by using dps ‘2’, which is the one that lets me set the position, and also lets me read the position. (While it’s probably a better idea to use ‘3’ to get the position, I wanted to start small and get this working just using dps ‘2’). Once I have things working solely with ‘2’, i’ll want to add functionality to publish/subscribe to ‘1’, ‘3’ and ‘7’ as well.

I did my best to align with the proper Home Assistant MQTT Cover topics laid out at https://www.home-assistant.io/integrations/cover.mqtt/ .

One thing that confused me is that even though I enabled set_position_topic as a Cover topic, under the gismo model settings, it lets me select position_topic for the dps key, but not set_position_topic. Perhaps I have a misunderstanding here of how things are supposed to work.

Finally, here are all of my logs.

Home Assistant Log

2020-09-02 22:57:01 INFO (MainThread) [homeassistant.setup] Setting up mqtt
2020-09-02 22:57:01 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 0.0 seconds
2020-09-02 22:57:02 INFO (Thread-5) [homeassistant.components.mqtt] Connected to MQTT server core-mosquitto:1883 (0)
2020-09-02 22:57:02 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: cover DEVICEIDREDACTED_2
2020-09-02 22:57:02 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: cover DEVICEIDREDACTED_3
2020-09-02 22:57:03 INFO (MainThread) [homeassistant.components.cover] Setting up cover.mqtt
2020-09-02 22:57:03 ERROR (MainThread) [homeassistant.util.logging] Exception in async_discover when dispatching 'mqtt_discovery_new_cover_mqtt': ({'qos': 0, 'name': 'Position', 'availability_topic': 'tuya/DEVICEIDREDACTED/availability', 'payload_available': 'online', 'payload_not_available': 'offline', 'command_topic': 'tuya/DEVICEIDREDACTED/2/command', 'payload_off': 'OFF', 'payload_on': 'ON', 'json_attributes_topic': 'tuya/DEVICEIDREDACTED/2/attributes', 'set_position_topic': 'tuya/DEVICEIDREDACTED/2/set_position', 'position_topic': 'tuya/DEVICEIDREDACTED/2/position', 'state_topic': 'tuya/DEVICEIDREDACTED/2/state', 'state_off': 'OFF', 'state_on': 'ON', 'unique_id': 'DEVICEIDREDACTED_2', 'device': {'identifiers': ['DEVICEIDREDACTED'], 'name': 'Position', 'model': 'Tuya', 'sw_version': '1.0.0', 'manufacturer': 'GismoCaster', 'via_device': 'Left Blind'}, 'platform': 'mqtt'},)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/mqtt/cover.py", line 183, in async_discover
    config = PLATFORM_SCHEMA(discovery_payload)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 208, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 287, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 283, in _exec
    v = func(v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: extra keys not allowed @ data['payload_off']

Tuya Gateway Log

2020-09-02 23:00:19,883 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:00:19,883 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:00:26,889 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:00:26,890 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 106): [9:HEART_BEAT] payload: [None]
2020-09-02 23:00:26,901 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:00:26,902 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:00:33,910 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:00:33,911 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 107): [9:HEART_BEAT] payload: [None]
2020-09-02 23:00:33,921 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:00:33,921 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:00:40,930 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:00:40,931 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 108): [9:HEART_BEAT] payload: [None]
2020-09-02 23:00:41,172 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:00:41,173 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:00:48,181 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:00:48,182 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 109): [9:HEART_BEAT] payload: [None]
2020-09-02 23:00:48,545 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:00:48,546 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:00:51,230 DEBUG    (Thread-1) [paho.mqtt.client] Sending PINGREQ
2020-09-02 23:00:51,232 DEBUG    (Thread-1) [paho.mqtt.client] Received PINGRESP
2020-09-03 06:00:52,240 DEBUG    [paho.mqtt.client] Sending PINGREQ
2020-09-03 06:00:52,241 DEBUG    [paho.mqtt.client] Received PINGRESP
2020-09-02 23:00:53,641 DEBUG    (Thread-6) [paho.mqtt.client] Sending PINGREQ
2020-09-02 23:00:53,643 DEBUG    (Thread-6) [paho.mqtt.client] Received PINGRESP
2020-09-02 23:00:55,554 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:00:55,554 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 110): [9:HEART_BEAT] payload: [None]
2020-09-02 23:00:55,924 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:00:55,925 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:01:02,932 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:01:02,933 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 111): [9:HEART_BEAT] payload: [None]
2020-09-02 23:01:03,290 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:01:03,291 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:01:10,296 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:01:10,297 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 112): [9:HEART_BEAT] payload: [None]
2020-09-02 23:01:10,668 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:01:10,669 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:01:17,677 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:01:17,678 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 113): [9:HEART_BEAT] payload: [None]
2020-09-02 23:01:17,687 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:01:17,688 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:01:24,694 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:01:24,695 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 114): [9:HEART_BEAT] payload: [None]
2020-09-02 23:01:24,709 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:01:24,709 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:01:31,714 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:01:31,715 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 115): [9:HEART_BEAT] payload: [None]
2020-09-02 23:01:31,965 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:01:31,966 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:01:38,974 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:01:38,975 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 116): [9:HEART_BEAT] payload: [None]
2020-09-02 23:01:38,993 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:01:38,993 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:01:45,998 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PING
2020-09-02 23:01:46,000 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) sending msg (seq 117): [9:HEART_BEAT] payload: [None]
2020-09-02 23:01:46,011 DEBUG    (Thread-7) [tuyaface] (192.168.1.29) received msg (seq 0): [9:HEART_BEAT] rc: [0] payload: [None]
2020-09-02 23:01:46,012 DEBUG    (Thread-7) [tuyaface.tuyaclient] (192.168.1.29) PONG
2020-09-02 23:01:51,307 DEBUG    (Thread-1) [paho.mqtt.client] Sending PINGREQ
2020-09-02 23:01:51,311 DEBUG    (Thread-1) [paho.mqtt.client] Received PINGRESP
2020-09-03 06:01:52,316 DEBUG    [paho.mqtt.client] Sending PINGREQ
2020-09-03 06:01:52,320 DEBUG    [paho.mqtt.client] Received PINGRESP

Mosquitto Broker Log

[INFO] found homeassistant on local database
1599098031: New client connected from 172.30.32.1 as auto-E41C6BC7-2727-A18F-81CB-71E8C5F37C7F (p2, c1, k60, u'homeassistant').
1599098039: New connection from 172.30.33.2 on port 1883.
[INFO] found addons on local database
1599098040: New client connected from 172.30.33.2 as auto-AB8E6B33-9194-81FD-3BFE-590B495EA0B9 (p2, c1, k60, u'addons').
1599098040: New connection from 172.30.33.2 on port 1883.
1599098040: New client connected from 172.30.33.2 as auto-047E1B97-EF5E-A3EC-66F9-A76059F7EB23 (p2, c1, k60, u'addons').
1599098772: New connection from 172.30.32.1 on port 1883.
[INFO] found mqtt-user on Home Assistant
1599098774: New client connected from 172.30.32.1 as 4AE7nxk3OCLmhR1ZsN36JX (p1, c1, k60, u'mqtt-user').
1599098774: Client 4AE7nxk3OCLmhR1ZsN36JX disconnected.
1599098790: Socket error on client auto-E41C6BC7-2727-A18F-81CB-71E8C5F37C7F, disconnecting.
1599098790: New connection from 172.30.32.1 on port 1883.
1599098790: New client connected from 172.30.32.1 as auto-E831D8D1-236D-CBD2-3E52-0F61A4D7FAAB (p2, c1, k60, u'mqtt-user').
1599099082: Socket error on client auto-AB8E6B33-9194-81FD-3BFE-590B495EA0B9, disconnecting.
1599099082: Socket error on client auto-047E1B97-EF5E-A3EC-66F9-A76059F7EB23, disconnecting.
1599099131: New connection from 172.30.33.2 on port 1883.
[INFO] found addons on local database
1599099131: New client connected from 172.30.33.2 as auto-DAB7F3E5-DA08-C060-1FBD-E362082E5F69 (p2, c1, k60, u'addons').
1599099132: New connection from 172.30.33.2 on port 1883.
1599099132: New client connected from 172.30.33.2 as auto-02B8C160-16FD-B2F5-8F65-580A602817F6 (p2, c1, k60, u'addons').
1599099830: Saving in-memory database to /data/mosquitto.db.
1599101635: Saving in-memory database to /data/mosquitto.db.
1599103436: Saving in-memory database to /data/mosquitto.db.
1599105237: Saving in-memory database to /data/mosquitto.db.
1599107038: Saving in-memory database to /data/mosquitto.db.
1599108375: Socket error on client auto-E831D8D1-236D-CBD2-3E52-0F61A4D7FAAB, disconnecting.
1599108392: New connection from 172.30.32.1 on port 1883.
[INFO] found mqtt-user on Home Assistant
1599108394: New client connected from 172.30.32.1 as auto-9CDD5897-2D9B-F085-66F3-EB402B6FC4C2 (p2, c1, k60, u'mqtt-user').
1599108840: Saving in-memory database to /data/mosquitto.db.
1599108954: Socket error on client auto-DAB7F3E5-DA08-C060-1FBD-E362082E5F69, disconnecting.
1599108955: Socket error on client auto-02B8C160-16FD-B2F5-8F65-580A602817F6, disconnecting.

It looks to me like TuyaGateway, Mosquitto Broker and Home Assistant are all acting nicely with each other, and the problem is in setting up this particular device. I imagine the only relevant part of the logs for diagnosing the issue is the traceback in the Home Assistant log.

I have a feeling that the reason this setup does not work is because some of the settings I entered in gismocaster are incorrect. There was a dearth of documentation to follow, so I did my best based on what others had posted here.

(Sidenote, but one peculiar thing I noticed from the logs is that it seems to be trying to connect to multiple instances of the same device (see below lines from the Tuya Gateway log, where it finds my device underscore 2 and my device underscore 3. Weird.

2020-09-02 22:57:02 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: cover DEVICEIDREDACTED_2
2020-09-02 22:57:02 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: cover DEVICEIDREDACTED_3

Appreciate any and all help in advance. As I mentioned, once I get this working, I would be happy to contribute to the wiki or readme and provide all of my settings as a working example.

Thanks,

Loaxley

2 Likes

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