TheAgentK / tuya-mqtt

Nodejs-Script to combine tuyaapi and openhab via mqtt
MIT License
173 stars 81 forks source link

Command Syntax for friendly topics #73

Closed GeraldST closed 3 years ago

GeraldST commented 3 years ago

I cannot figure out how to send commands to friendly topics that I have defined with a Generic Device Template. There is no clue in the documentation either.

First of all, I have set up a Fairland Inverter Heat Pump (for my pool) and this is my devices.conf file:

[
  {
    name: 'Waermepumpe',
    id: 'xxxxx',
    key: 'xxxxx',
    template: {
      state: {
        key: 1,
        type: 'bool'
      },
      mode: {
        key: 2,
        type: 'str'
      },
      WInTemp: {
        key: 102,
        type: 'int'
      },
      change_tem: {
        key: 103,
        type: 'bool'
      },
      SpeedPercentage: {
        key: 104,
        type: 'int'
      },
      SetMode: {
        key: 105,
        type: 'str'
      },
      SetTemp: {
        key: 106,
        type: 'int',
        topicMin: 18,
        topicMax: 40
      },
      SetDnLimit: {
        key: 107,
        type: 'int'
      },
      SetUpLimit: {
        key: 108,
        type: 'int'
      },
      fault1: {
        key: 115,
        type: 'str'
      },
      fault2: {
        key: 116,
        type: 'str'
      }
    }
  }
]

What is working:

What is not working:

So is this a bug? I had a look into the code and the function processDeviceCommand is only called when topicLength is 3 AND there is the word "command" in the command topic. I cannot figure out how to do this with topicLength 3. "tuya/waermepumpe/SetTemp/command" has a length of 4 ...

Btw. sorry to hear that this project is in maintenance mode. I am quite new to Tuya devices and I really appreciate this for communicating to my heat pump and integrating into FHEM - it already works quite well! I am aware that this project depends on tuyapi - but as long as it is working I will stick to it (I tried cloud API, but my device does not support all functions yet) and appreciate all the work done! Thank's a a lot!

tsightler commented 3 years ago

I don't think it's a bug, probably just poor documentation that could probably be more clear. The documentation does hint at the right thing to do in the example:

The template above defines two topics "state" and "brightness_state", and the template engine automatically creates the corresponding command topics, in this case specifically "command" and "brightness_command".

Basically, the expectation is the the template defines topics with the suffix of _state, and the engine automatically creates corresponding _command topics, so in your example it should be (just did one for and example):

SetTemp_state: {
        key: 106,
        type: 'int',
        topicMin: 18,
        topicMax: 40
      }

And then you can get state at tuya/waermepumpe/SetTemp_state and send commands to tuya/waermepumpe/SetTemp_command.

GeraldST commented 3 years ago

Thank you, that's it! So I just added _state to all of my topics and it works now "as expected" ;-)

I read the example several times and misunderstood the description. On the other hand now that you explained it in other words the documentation seems quite clear.

Thank you for your unbelievable fast support!

tsightler commented 3 years ago

Glad you got it working.