Comments (11)
This project is mostly unmaintained at this point, while you are welcome to use it, it's pretty dead around here so there's not much help.
Your template only needs a single entry per DPS key, no need for two, although for a simple switch you can use the predefined "SimpleSwitch" type and then you don't even need a template.
As to what you're doing wrong, you are adding /command to state topic, instead of replacing the word "state" with the word "command" in the existing topic, so with your above examples these should work:
sensors/tuya/kogan-02/command off
sensors/tuya/kogan-02/power_command OFF
Basically, every "state" topic creates a corresponding "command" topic automatically, so "power_state" will create a "power_command" topic for commands, but you instead tried "power_state/command".
from tuya-mqtt.
Thanks, yeah I saw that. Disappointing, to see that it's gone maintenance only....there's doesn;t seem to be a similar replacement now. And given I'm not homeassistant with it's official integration, I'm still left to wanting an mqtt solution.
So I tried as you suggested:
2021-10-21T21:34:58.374Z tuya-mqtt:command Received MQTT message -> {"topic":"sensors/tuya/kogan-02/command","message":"off"}
2021-10-21T21:34:58.375Z tuya-mqtt:error TypeError: Cannot read property 'processDpsCommand' of undefined
at MqttClient.<anonymous> (/home/node/tuya-mqtt/tuya-mqtt.js:162:32)
at MqttClient.emit (events.js:400:28)
at MqttClient._handlePublish (/home/node/tuya-mqtt/node_modules/mqtt/lib/client.js:1277:12)
at MqttClient._handlePacket (/home/node/tuya-mqtt/node_modules/mqtt/lib/client.js:410:12)
at work (/home/node/tuya-mqtt/node_modules/mqtt/lib/client.js:321:12)
at Writable.writable._write (/home/node/tuya-mqtt/node_modules/mqtt/lib/client.js:335:5)
at doWrite (/home/node/tuya-mqtt/node_modules/readable-stream/lib/_stream_writable.js:409:139)
at writeOrBuffer (/home/node/tuya-mqtt/node_modules/readable-stream/lib/_stream_writable.js:398:5)
at Writable.write (/home/node/tuya-mqtt/node_modules/readable-stream/lib/_stream_writable.js:307:11)
at Socket.ondata (internal/streams/readable.js:731:22)
neither kogan-02/command or kogon-02/power_command worked.
REgarding using the smart switch, that might give me access to the switch component, but I did actually want the power readings off the device as well, which I have managed to get via DPS 18, 19 and 20.
from tuya-mqtt.
Did you remove the double entries in your template, I have no idea what defining two values pointing at the same DPS key will do, but it might break in the way your seeing.
Regarding, using a predefined device like SimpleSwitch does not keep you from using the DPS values, the predefined devices are just templates themselves, just ones already created. Direct access to the device DPS values is always available in any case.
Unfortunately I haven't used this code in what feels like forever, so I can barely remember what it takes to configure it, even though I wrote it.
from tuya-mqtt.
Yeah just left with
template: {
power: {
key: 1,
type: 'bool'
},
volts_state: {
key: 20,
type: 'float',
topicMin: 1,
topicMax: 3000,
stateMath: '/10'
},
watts_state: {
key: 19,
type: 'float',
topicMin: 1,
topicMax: 3000,
stateMath: '/10'
},
amps_state: {
key: 18,
type: 'float',
topicMin: 1,
topicMax: 3000
}
And I still get the same error with:
sensors/tuya/kogan-02/command false
2021-10-21T21:34:58.374Z tuya-mqtt:command Received MQTT message -> {"topic":"sensors/tuya/kogan-02/command","message":"off"}
2021-10-21T21:34:58.375Z tuya-mqtt:error TypeError: Cannot read property 'processDpsCommand' of undefined
at MqttClient.<anonymous> (/home/node/tuya-mqtt/tuya-mqtt.js:162:32)
at MqttClient.emit (events.js:400:28)
at MqttClient._handlePublish (/home/node/tuya-mqtt/node_modules/mqtt/lib/client.js:1277:12)
at MqttClient._handlePacket (/home/node/tuya-mqtt/node_modules/mqtt/lib/client.js:410:12)
at work (/home/node/tuya-mqtt/node_modules/mqtt/lib/client.js:321:12)
at Writable.writable._write (/home/node/tuya-mqtt/node_modules/mqtt/lib/client.js:335:5)
at doWrite (/home/node/tuya-mqtt/node_modules/readable-stream/lib/_stream_writable.js:409:139)
at writeOrBuffer (/home/node/tuya-mqtt/node_modules/readable-stream/lib/_stream_writable.js:398:5)
at Writable.write (/home/node/tuya-mqtt/node_modules/readable-stream/lib/_stream_writable.js:307:11)
at Socket.ondata (internal/streams/readable.js:731:22)
Same with OFF, on etc. I did try adding in a smpleSwitch and template items, and that still didn't seem to work.
Giving it's not really posting updates unless I go into the app, I think I'll end up trying to switch to tinytuya library and have to write a python library around it.
Thanks for your help
from tuya-mqtt.
Hi
I use that config:
{
name: 'dev name',
id: 'xxx',
key: 'xxx',
template: {
state: { key: 1, type: 'bool' },
amperes: { key: 4, type: 'float', stateMath: '/1000' },
watts: { key: 5, type: 'float', stateMath: '/10' },
volts: { key: 6, type: 'float', stateMath: '/10' }
}
}
Commands to switch on/off are:
tuya/dev_name/command ON
tuya/dev_name/command OFF
Best regards
SLaweck
from tuya-mqtt.
Yeah, after looking at the above error the reason the config @psyciknz is using doesn't work has nothing to do with the template, rather it is because it looks like there's an extra topic level to the topic config. This isn't supported because the code currently determines the type of command by parsing the number of topic levels so adding two topic levels for the prefix instead of a single one completely changes the logic. This was a limitation I was planning to remove in the future (it's easy to fix), but once I decided to abandon Tuya devices, and thus maintenance of this project, it fell by the wayside.
Removing the sensors/ topic level and just leaving it with tuya/ would likely resolve the issue.
from tuya-mqtt.
Ahh right, so because I've changed the default from tuya to sensors/tuya is why it's broken?
from tuya-mqtt.
Well, that's at least the reason for the error you reported above. The processDpsCommand() function should only be called if you are sending commands to the raw dps JSON command topic but the current code is hard coded to count the topic levels and call the appropriate function (processCommand(), processDpbCommand(), or processDpsKeyCommand()) based on if there are 3, 4, or 5 topic levels. Because you've added an extra topic level in the configuration the command to friendly topics have 4 levels instead of 3, so the code calls processDpsCommand() instead of just processCommand() function.
I can't say you might not have other issues, but that's the issue with the error above. I didn't notice it in your output previously and you didn't provide your config or indicate that you were otherwise changing the default settings, and it's been quite a while since I've even thought about this code, so it didn't even cross my mind.
Basically, the current code supports replacing "tuya" with "sensors", but you can't add an entire topic level with a / between them.
from tuya-mqtt.
That's worked. The other problem I may have had was uppercase Kogan in devices and lower case in mqtt message.
Thanks for all your help.
Do you know if there a command for asking for devices to post their states?
I did try the official home assistant integration, but all it offers if on off, no power monitoring, so it's worse that this wonderful bridge (which allows me to control it via home assistant, openHAB and homebridge)
from tuya-mqtt.
Do you know if there a command for asking for devices to post their states?
If you mean for example to refresh power monitoring state, unfortunately tuyapi did not have support for this at the time I stopped maintaining this project. It was somewhat on the radar at the time, and the plan was to do something like add an additional property to set how often you wanted to send the command to force a device to update the power monitoring. My understanding is the tuyapi now has this capability, but, being unmaintained, it was never added to this project.
As far as I know the official Tuya integration for HA only uses cloud control. Everyone that is serious about using Tuya devices with HA uses the localtuya integration, which does support power monitoring via local control.
I'm not opposed to PRs to implement power monitoring, but as I no longer have Tuya devices (or at least any that actually have Tuya firmware left on them) so I don't have a platform to develop and test it and, unfortunately from the perspective of this project, I just don't care about Tuya devices anymore which is why this project requires a new maintainer going forward but so far none have stepped up, so I just don't think there's really that much interest here.
from tuya-mqtt.
Closing this since the initial issue has been resolved.
from tuya-mqtt.
Related Issues (20)
- TypeError: Cannot set property 'updated' of undefined HOT 9
- Problem installing on Synology RS914 HOT 32
- Home Assistant integration how? HOT 2
- tuya-mqtt publishes states only when app is opened. HOT 22
- What mqtt broker HOT 3
- Disconnected from device and never connects again ... HOT 6
- Samples for nodejs script HOT 9
- New Maintainer Needed HOT 4
- Not sure when you went into Maintenance mode HOT 3
- Command Syntax for friendly topics HOT 3
- zombe state reconnecting issue? HOT 1
- Switch w/ Energy: DPS values reported only once at tuya-mqtt startup HOT 3
- Sudenly wrong responses from tuya device HOT 1
- tuya-mqtt not working (OpenHab) HOT 7
- Tuya bulb stopped working from tuya-cli, tuja-mqtt HOT 9
- Devices behind zigbee gateway available with tuya-cli but not tuya-mqtt HOT 1
- Different names after service restart HOT 9
- tuya-mqtt crushing HOT 1
- hsb type not suported in generic template HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tuya-mqtt.