mqtt-bridge-smartthings icon indicating copy to clipboard operation
mqtt-bridge-smartthings copied to clipboard

mqtt-bridge-smartthings error on first install

Open raisingskell opened this issue 4 years ago • 19 comments

Very nice to see work continuing on the bridge. Thanks. On Windows 10, installed mqtt-bridge-smartthings but running it throws an error. I'm sure I've done something wrong. The gist of the error is:

No previous configuration found, creating one internal/fs/utils.js:525 throw new ERR_INVALID_ARG_TYPE(propName, ['string', 'Buffer', 'URL'], path); ^ TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type undefined

Thoughts? Thanks

raisingskell avatar Nov 13 '19 14:11 raisingskell

Thanks for the quick response. I do have the .yml files configured but maybe in the wrong location. Where should these 2 files be located?

Thanks

raisingskell avatar Nov 13 '19 15:11 raisingskell

These should be in the same folder as the example config files and mbs-server.js file

sgupta999 avatar Nov 13 '19 21:11 sgupta999

Thanks. That did the trick. Also, case sensitivity is a deadly thing. I can finally control my RS-232 devices from SmartThings! I really appreciate your work.

raisingskell avatar Nov 16 '19 06:11 raisingskell

Awesome - so you got it working. Do you mind sharing some details about your setup and what issues you encountered during setup - I will be updating some of the readme files to make it easier - are you running both the mbs-server and mosquitto as windows service ?

sgupta999 avatar Nov 16 '19 12:11 sgupta999

I spoke too soon. Had mosquitto and node-red as a service but not mbs. Overnight MS did an update/restart so figured it was time to install mbs as a service. No luck with srv. No luck with nssm. both cases mbs would install but never start. Uninstalled and removed service. Now mbs starts fine from prompt but as soon as an event occurs it crashes. In config.yml, set deviceconfig to false to see if it would help, No luck. Next step, uninstall and reinstall.

Capture

raisingskell avatar Nov 17 '19 03:11 raisingskell

sorry to hear that. Thanks for the log. I think I might have spotted a bug in my code. Are you by any chance using wildcards for any of the subscription topics?

If indeed that is the problem i have pushed a patch. please download mbs-server.js from the repository and try with that.

If you are not using wildcards in mqtt topics, than i would need to see some more of the log from before the error occurs. would be great if you could upload those

sgupta999 avatar Nov 17 '19 04:11 sgupta999

Hi Sandeep. No wildcards, unfortunately. Deinstalled, reinstalled everything late on 11/16. One crash was trying to update Smoke/Co detector with 5 status items. Set deviceconfig to false and restarted. The second came when doing "Saving Current State" 30 minutes after restart. Next crash 15 minutes later at same "Saving Current State".

Type Error: Cannot convert undefined or null to object at function.keys () at timeout.saveState [as_onTimeout] (C:....\npm\node_modules\mqtt-bridge-smartthings\mbs-server.js:269:19) at listOnTimeout (internal/timers.js:531:17) at processTimers (internal/timers.js:475:7)

raisingskell avatar Nov 17 '19 17:11 raisingskell

my sincerest apologies - I do not have a scenario to in which to test without a devices.yml file so sorry some of these null checks have crept in.

Good news is o found where the issue was and fixed. Every 15 minutes the server tries to save state and that is where you were getting the error.

Could you please try it one more time. The update mbs-server.js is on githun

Also somewhat confused by your setup - are you using the devices.yml or not? Since you mention 5 status items i am assuming you are. could you maybe send me the sample of you devices.yml , config.yml and the log from when the serer starts up to when it starts listening on port

thanks for all your help

sgupta999 avatar Nov 17 '19 20:11 sgupta999

I appreciate your patience. Good news - no more crash on "Savings current state". Sorry for the devices.yml confusion. With my devices file I was getting the error in the screenshot above. Tried running without devices file and it worked, but crashed on the "Saving current state". Now that the Save is working I'll retry my devices file.

Question on the devices file setup. In the example devices.yml file, the first example shows Device Name ->Attribute->Subscribe whereas in further samples it shows Device Name->Subscribe->Attribute. Does it matter what order it is in?

Thanks again.

raisingskell avatar Nov 17 '19 21:11 raisingskell

I am so sorry - could i have made it more confusing. The second ones and later are the correct form. I got lazy didn't want to fix the comments

I have updated the file in github. the comments might still be weird but the structure is right.

you should be able to try with the devices file. make sure the devices file is read correctly. If it is the log file will show you all the subscription that you specify in the devices file

sgupta999 avatar Nov 17 '19 23:11 sgupta999

Finally got all the device handlers and the mbs-server known issues fixed. Please download codebase and devicehandlers and example config files again form github and try.

While the MQTT wildcard works if there are overlapping subscriptions with wildcards for the same topic currently only the first one will get the update - i have a fix in mind but that will come later.

For now try these and see if things are rock solid.

thanks again for all your help.

sgupta999 avatar Nov 18 '19 02:11 sgupta999

So might have a handle on what might be another reason also causing your issue. If you removed a bunch of devices from devices.yml after a previous start on next restart you might get the first exception you got.

I have the issue addressed but it is part of some significant upgrade on MQTT wildcards that I am testing and will do so for the next few days before I release it.

One workaround for now is to go the data folder and delete the 2 json files there and restart the server. If that does not work let me know I will send you my test version.

sgupta999 avatar Nov 18 '19 12:11 sgupta999

Hi Sandeep,

ST to mqtt working great. Thanks. Having trouble getting anything from mqtt into ST. I had to uninstall OmniLink Bridge - allows Leviton's OmniPro 2 (security/climate/etc) to communicate with ST because it and MBS both use the the same ST device id - the MAC address. Fortunately, the OmniLink Bridge publishes to mqtt and I was hoping MBS would capture that as well as my audio generated info. No luck. I'm sure it must be how I have the devices.yml configured.

Can you suggest a devices.yml format that would capture the following as seen in MQTT Explorer? Running the latest files from github. I appreciate any suggestions.

image

raisingskell avatar Dec 14 '19 16:12 raisingskell

Are u using a virtual thermostat device handler or a custom one - answer will depend on that. If u r using a custom one the an easier approach would be to define processMQTT method.

If not then please let me know what exposed attributes from the device handler you want attributes mapped to

with regards to server to ST - have to make sure macaddress, ip, port are correct and also of course the Capability map in the app is correctly selected.

On the server side in the log to you see any log beginning with

MQTT -> ST

if you are seeing that then the problem is with the configuration in the IDE.

If you are not seeing that then the problem is either in the devices.yml or in the Smartapp - i will walk you through once i get more info from you.

Also if you are indeed getting MQTT -> ST in the server log please check live logging in IDE for both the bridge and smartpp to see if either or none are receiving those messages

sgupta999 avatar Dec 14 '19 21:12 sgupta999

Thanks for all your help. Shortly after posting about OmniLinkBridge it stopped publishing to mqtt. Weird. New version on github has no exe file. Oh well, I guess I'll have time to do all those chores I've been putting off. haha

raisingskell avatar Dec 16 '19 06:12 raisingskell

sorry to hear that. Unfortunately ST limits communication to LAN devices using Mac address only and you can only have one mac per network interface to connect. There are some options around for putting another layer if you have multiple services running on a single mac that need to talk to ST independently.

What I have done is - for other services running that need to talk to ST I just have them publish MQTT messages to the bridge, that way i do not need to put another layer in the middls and the MQTT bridge can be the primary service communicating with ST.

Also you could possible look at virtual network adaptor and VMs (don't know if they will necessarily work).

Happy to help you with devices.yml and the capability map once you've decided which way you want to go.

sgupta999 avatar Dec 16 '19 16:12 sgupta999

I managed to recover the OmniLinkBridge from a backup and have it running again. This is what I get from the MQTT Bridge:

Parsed '{"coolsetpoint":85,"fanmode":0,"heatsetpoint":58,"hold":0,"humidity":0,"id":3,"mode":1,"name":"SECOND FLOOR","status":"HEATING","temp":57}'

Then a second later I get this from the MBS Smart App:

Received device event from bridge: [coolsetpoint:85, fanmode:0, heatsetpoint:58, hold:0, humidity:0, id:3, mode:1, name:SECOND FLOOR, status:HEATING, temp:57]

So I'm guessing MBS sees it but doesn't know what to do with it. My goal is to have the following attributes as distinct ST devices: heatsetpoint, hold, mode, name, status and temp for each of 3 tstats and the ability to send commands to heatsetpoint (inc/dec), hold (0=off/1=on), mode (0=off/1=on) and status (heating/off).

I've played with capability mapping and the devices.yml file. Too many moving parts for this feeble hack. Is that the correct approach? Capability map then devices?

raisingskell avatar Dec 17 '19 07:12 raisingskell

This is great so rest is configuration and maybe a device handler.

So my understanding is u will create 3 thermostat devices to manage these

Do u know if you will be using an existing device handler or a custom one? That will decide approach

If you can send me MQTT topic payload that ST will subscribe to and MQTT topics payload that ST will publish to I can create devices.yml

If u don’t have a thermostat device handler I can tweak a custom DTH based on DT simulated DTH that I use.

The only attribute/command that u mention that is not usually in any thermostat DTH handler is the hold command? Not sure what it does.

Let me know your device handler approach - I was going to create an MQTT thermostat DTH anyway - might as well do it for this case

sgupta999 avatar Dec 17 '19 14:12 sgupta999

okay here's all you need. Just download the latest smartapp from https://github.com/sgupta999/gupta-st-devices-smartapps/tree/master/smartapps/gupta/mqtt/mbs-smartapp.src

download the thermostat device handler (or you can use your own as long as all standard thermostat methods are implemented) https://github.com/sgupta999/gupta-st-devices-smartapps/blob/master/devicetypes/gupta/mqtt/thermostat.src/MQTTThermostat.groovy

Add the following to the devices.yml

#
thermostat1:
  subscribe:
    temperature:
        smartthings/thermostat1/current_temperature:
    humidity:
        smartthings/thermostat1/current_humidity:
    thermostatMode:
        smartthings/thermostat1/mode_state:
    thermostatOperatingState:
        smartthings/thermostat1/current_operation:
    heatingSetpoint:
        smartthings/thermostat1/temperature_heat_state:
    coolingSetpoint:
        smartthings/thermostat1/temperature_cool_state:
    thermostatFanMode:
        smartthings/thermostat1/fan_mode_state:
  publish:
    thermostatMode:
        smartthings/thermostat1/cmd/mode_state:
    thermostatOperatingState:
        smartthings/thermostat1/cmd/current_operation:
    heatingSetpoint:
        smartthings/thermostat1/cmd/temperature_heat_state:
    coolingSetpoint:
        smartthings/thermostat1/cmd/temperature_cool_state:
    thermostatFanMode:
        smartthings/thermostat1/cmd/fan_mode_state:
  retain: 'false' 
#

Typically your subscribe and publish topics should be different to avoid loops - i have put the same topics here but make sure they match your environment - your publish topics might have some additional qualifier (i have added cmd in the above examples) make sure you add the thermostat to the smartapp in the mobile app and you should be all set

sgupta999 avatar Dec 17 '19 20:12 sgupta999