Coder Social home page Coder Social logo

sgupta999 / mqtt-bridge-smartthings Goto Github PK

View Code? Open in Web Editor NEW
27.0 9.0 15.0 167 KB

MQTT Bridge To SmartThings [MBS]

License: MIT License

JavaScript 48.87% Groovy 50.93% Dockerfile 0.20%
tasmota smartthings mqtt-bridge tasmota-device smartapp mqtt shelly shelly-mqtt

mqtt-bridge-smartthings's Introduction

MQTT Bridge to SmartThings [MBS]

Broker between Smartthings and MQTT Broker.

GitHub Tag Docker Pulls Docker Stars

This is an upate from the smartthings-mqtt-broker orginally developed by St. John Johnson. (https://github.com/stjohnjohnson/smartthings-mqtt-bridge). I have borrowed with abandon from his work, both in compiling this readme; and the server/client codeset, so a big thank you to him.

The primary motivation was having a pure MQTT solution for Tasmota devices in Smartthings. Unfortunately, the old solution was more targeted towards HASS-IO integration. Most of the architecture and basic concepts remain the same but significant refactoring and changes have been made.

Architecture

Architecture

Compatibility

The new server should be fully backward compatible. If you have been using the old library you should still be able to use and avail of all the new functionality.

Updates

  1. An external devices YAML config file has been introduced. It allows to define any custom mapping between and smartthings [device][attribute][command] and MQTT [topic][payload] and vice-versa.
  2. A device can subscribe and publish to any number of topics
  3. MQTT wildcards can be used in subscribe topics
  4. Within smartthings. smartapp and device handlers have a generic processMQTT method to process subscription messages. Smartthings attribute 'events' are use to publish messages to MQTT broker
  5. The logging and configurations have beem significantly streamlined. 'Log' and 'Data' directories store logs and state information
  6. All dependencies have been updated to the latest versions.
  7. The use case tested was for primarily Tasmota devices. I have a lite and full version of the SmartApp and sample tasmota Device Type Handlers. Use the 'lite' version if you are primary interested in configuring devices using the external device config file and primarily using Tasmota device handlers provided with this package.
  8. The Tasmota Device Type Handlers periodically update other information from device like SSID, RSSI, LWT etc. If you use the SmartThings virtual switches or contact sensors they will just process the commands

MQTT Events Flow

While the original flow is preserved as is - a new flow has been introduced to make the bridge more flexible. Please read the original readme on the previous project for the original flow. The new flow is as follows:

  1. Smartthings events are generated from attributes - both standard and custom. You may choose to define custom attriutes for handling functionality beyond standard attributes - e.g combo devices or more functional tiles
  2. Within the 'MBS - SmartApp' you describe a capability map and specify which attribute(s) (and corresponding event(s)), the SmartApp will subscribe to.
  3. For every event Smartthings generates a [device][attribute][command] event package that the SmartApp is subscribed to and sends it to the mbs-server.
  4. The devices.yml config file maintains a mapping of [device][attribute][command] to the MQTT [topic][payload] to be published.
  5. Once the server receives the event from Smartthings, if the device is in the config file it uses the mapping to publish to MQTT broker. If the device is not in the device config file it assumes the standard old flow and publishes a message {PREFACE}/{DEVICE_NAME}/${ATTRIBUTE}/SUFFIX corresponding to the old flow.
  6. On the flip side, when the server receives an MQTT message from the broker, it checks the device config file for mapping of [topic][payload] to [device][attribute][command] and sends the command back to Smartthings. If device is not found it follows the old flow.
  7. Smartthings MBS-SmartApp maintains mappings for each capability of what attribute[event] to subscribe (for publishing to MQTT Broker) and what action method to call for an event received form the MQTT broker via the MBS-Server. See _smartapp.example.md

Please read this to ensure appropriate configuration. The MBS-SmartApp controls the mappings between the Devices and the Server config. A lot of flexibility for advanced configuration has been built in, but it can also be used without any configuration for the basic switches and sensors.

Configuration

The bridge has two yaml files for configuration. The config files need to be stored in the config directory. You can specify a CONFIG_DIR environment variable to specify where the config directory or it will default to locating the config directory in the same folder where mbs-server. This is a change form vesions 1.02 and earlier where confif files were not in a separate sub-directory

---
# Port number to listen on
port: 8080

#Default (info) - error, warn, info, verbose, debug, silly
loglevel: "info"
        
#is there an external device config file: true, false
deviceconfig: true

mqtt:
    # Specify your MQTT Broker URL here
    host: mqtt://localhost
    # Example from CloudMQTT
    # host: mqtt:///m10.cloudmqtt.com:19427

    # Preface for the topics $PREFACE/$DEVICE_NAME/$PROPERTY
    preface: smartthings

    # The write and read suffixes need to be different to be able to differentiate when state comes from SmartThings or when its coming from the physical device/application

    # Suffix for the topics that receive state from SmartThings $PREFACE/$DEVICE_NAME/$PROPERTY/$STATE_READ_SUFFIX
    # Your physical device or application should subscribe to this topic to get updated status from SmartThings
    # state_read_suffix: state

    # Suffix for the topics to send state back to SmartThings $PREFACE/$DEVICE_NAME/$PROPERTY/$STATE_WRITE_SUFFIX
    # your physical device or application should write to this topic to update the state of SmartThings devices that support setStatus
    # state_write_suffix: set_state

    # Suffix for the command topics $PREFACE/$DEVICE_NAME/$PROPERTY/$COMMAND_SUFFIX
    # command_suffix: cmd

    # Other optional settings from https://www.npmjs.com/package/mqtt#mqttclientstreambuilder-options
    # username: AzureDiamond
    # password: hunter2

    # MQTT retains state changes be default, retain mode can be disabled:
    # retain: false


---
# Look for actual scenarios at the end without comments
# Complete example of complex device setup with multiple subscriptions and commands
Living Room Light:
# device name - make sure it is exactly the same as in smartthings
  attribute: switch
  # REQUIRED: mapped to an actual attribute of device [e.g. switch, contact or any custom attribute
  # this attribute is specified in the capability map section of the mbs-smartapp
  # an attribute is required for each topic subbscription
      subscribe:
      # topic details to which smartthings will be subscribed
      # (topic, payload) from MQTT will be transformed to (device, attribute, payload*) to smartthings
        smartthings/stat/sonoff-1/POWER:
        # OPTIONAL: subscribe to this topic, for tasmota you really need it to get status updates for third party on/off
          command:
          # OPTIONAL: Translate payload coming from MQTT to this new payload* send to smartthings
          # For e.g. here OFF command published from MQTT will be sent as off (lowercase) to smartthings
          # if not set payload from MQTT is sent as is
            'OFF': 'off'
            'ON': 'on'
        smartthings/stat/sonoff-1/STATUS:
        # You can subscribe to as many topics 
        smartthings/stat/sonoff-1/STATUS2:
        smartthings/stat/sonoff-1/STATUS5:
        smartthings/stat/sonoff-1/STATUS11:
  publish:
  # OPTIONAL: commands (device, attribute, payload) from smartthings is send to MQTT as (topic, payload*)
    switch:
    #REQUIRED: attribute specified in the capability map section of the mbs-smartapp
      topic: smartthings/cmnd/sonoff-1/POWER
      # REQUIRED: topic to be published to MQTT
      command:
      # REQUIRED: transforming payload from smartthings to the one sent to MQTT and physical device
        'off': 'OFF'
        'on': 'ON'
    update:
      topic: smartthings/cmnd/sonoff-1/Backlog
      command:
      # tasmota specific example of using Backlog to send multiple simultaneous commands to physical device
        refresh: Status; Status 2; Status 5; Status 11
  retain: 'false'
  # false set as default and here

Installation

Docker Setup

since version 1.0.3 I have uploaded docker images for alpine linux distro and raspberry pi distro to docker hub. Please see detailed instructions for Docker installation in DOCKER.md

NPM

To install the module, just use npm:

$ npm install -g mqtt-bridge-smartthings

If you want to run it, you can simply call the binary:

$ mqtt-bridge-smartthings
Starting SmartThings MQTT Bridge - v1.0.1
Loading configuration
No previous configuration found, creating one

If you are interested in running it on windows as a server the windows service directory has instructions and sample .ini file and .bat file with commands.

Usage

  1. Customize the MQTT host and devices

    $ vi config.yml
    $ vi devices.yml
    # Restart the service to get the latest changes
    
  2. Install the MBS-Bridge Device Handler in the [Device Handler IDE][ide-dt] using "Create via code"

  3. Add the "MQTT Bridge" device in the [My Devices IDE][ide-mydev]. Enter MQTT Bridge (or whatever) for the name. Select "MBS Bridge" for the type.

  4. Configure the "MQTT Bridge" in the [My Devices IDE][ide-mydev] with the IP Address, Port, and MAC Address of the machine running the mbs-server processm service or docker container

  5. If ST is receiving messages from the bridge but the bridge is not receiving any messages from ST then most liley IP Address, Port, and MAC Address configuration is not correct

  6. Install the MBS SmartApp Lite or MBS SmartApp Fullon the [Smart App IDE][ide-app] using "Create via code"

  7. If using a Tasmota device install the [Tasmota SwitchSensor] or any other Tamota device from the [Tasmota Device Type] folder.

  8. Configure the Smart App (via the Native App) with the devices you want to subscribe to and the bridge that you just installed

  9. Via the Native App, select your MQTT device and watch as device is populated with events from your devices

mqtt-bridge-smartthings's People

Contributors

rhamblen avatar sgupta999 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mqtt-bridge-smartthings's Issues

The dreaded "ETIMEDOUT" error

MBS humming along nicely for a few months until this error began showing a few weeks ago. It only happens during MQTT --> ST, never during ST --> MQTT. The error shows in the MBS log but not in ST IDE Live Logging. Something in the environment obviously changed but not by intention.

2020-02-26 00:55:27 AM error: undefined
2020-02-26 00:55:27 AM error: Error from SmartThings Hub: Error: connect ETIMEDOUT 192.168.0.xx:39500
2020-02-26 00:55:27 AM error: {
"errno": "ETIMEDOUT",
"code": "ETIMEDOUT",
"syscall": "connect",
"address": "192.168.0.xx",
"port": 39500
}

I've verified all the ip addresses and ports. I removed the devices.yml. Rebooted ST and server. I believe I'm running the latest mbs-server.js, config.yml and mbs-smartapp-full. To the best of my knowledge this is only happening with MBS.

Any suggestions on where else to search? Much appreciated!

Smartapps full and lite can't be installed because of syntax error

In the full smartapp (I haven't tried the lite yet), smartthings IDE doesn't let install or copy the smartapp because of a missing comma in actionOpenClosed

"contactSensors": [
    name: "Contact Sensor",
    capability: "capability.contactSensor",
    attributes: [
        "contact"
    ]**,**
    action: "actionOpenClosed"

why use backlog???

Hi
I was wondering the otherday why we use the 'backlog' command in the tasmota update?
we could simplify the setup and use

update:
smartthings/cmnd/iFan03/STATUS:
command:
'refresh': '0'

this lets the device flood the MQTT queue with extra info but we still decode it fine.
it then becomes easy to pull extra info if we so desire.

just a thought.

mqtt update

How can i get en update from a sensor eg
Xiaomi Temp Sensor or battery status etc... I have from another smartthings/nodered, that i can send a update topic and get a mqtt status

Constructor Error from Winston

Working in MacOS. Really so thrilled to see this still being worked on. On startup, I get the following:

``
plex:mqtt-bridge-smartthings-1.0.4 plex$ echo $CONFIG_DIR
/Users/plex/Projects/git/mqtt-bridge-smartthings-1.0.4/config
plex:mqtt-bridge-smartthings-1.0.4 plex$ ls -la $CONFIG_DIR
total 8
drwxr-xr-x 4 plex staff 128 Apr 22 23:47 .
drwxr-xr-x 27 plex staff 864 Apr 22 23:47 ..
-rw-r--r-- 1 plex staff 1364 Apr 22 23:42 config.yml
drwxr-xr-x 2 plex staff 64 Apr 22 23:47 log
plex:mqtt-bridge-smartthings-1.0.4 plex$ ./bin/mqtt-bridge-smartthings
Current Working Directory is /Users/plex/Projects/git/mqtt-bridge-smartthings-1.0.4
/Users/plex/Projects/git/mqtt-bridge-smartthings-1.0.4/mbs-server.js:80
eventsLog = new (winston.transports.DailyRotateFile)({
^

TypeError: winston.transports.DailyRotateFile is not a constructor
at Object. (/Users/plex/Projects/git/mqtt-bridge-smartthings-1.0.4/mbs-server.js:80:14)
``

EHOSTUNREACH from Docker container on Windows

I followed all the instructions as indicated on the README and DOCKER.md files. My container starts up and clearly receives both configuration messages from the MBS SmartApp, as well as from the MQTT server. However, it appears to attempt to change a device in Smartthings and get a bounceback due to EHOSTUNREACH:

2020-11-30 02:10:03 AM info: MQTT --> ST - Topic: [smartthings/Side Door/contact/cmd][closed] [Side Door][contact][closed]
2020-11-30 02:10:05 AM error: Error from SmartThings Hub: Error: connect EHOSTUNREACH 172.18.10.3:39500
2020-11-30 02:10:05 AM error: {
"errno": -113,
"code": "EHOSTUNREACH",
"syscall": "connect",
"address": "172.18.10.3",
"port": 39500
}
2020-11-30 02:10:05 AM error: undefined

This set of messages happens once each time a device status is attempted to set on Smartthings hub (172.18.10.3). I double-checked the firewall rule setup in Windows and even tried disabling the firewall completely. This feels like a routing issue in Docker Desktop and WSL2, but you have instructions for using it this way so I'm not sure what is wrong.

Broken in latest Smartthings?

This was working for quite some time but appears to be non-functional now. Attempting to end the settings using the SmartApp on either IOS or Android results in an error message like:

We're having trouble connecting. Check your network connection and try again.

The live log in SmartThings API shows this:

773dca6b-43b2-477f-84f7-b2851925764a 11:13:46 AM: error org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not update: [physicalgraph.device.Device#773dca6b-43b2-477f-84f7-b2851925764a]; uncategorized SQLException for SQL [update device set version=?, completed_setup=?, component_label=?, component_name=?, date_created=?, device_network_id=?, error_state=?, firmware_version_id=?, group_id=?, handler_version=?, hub_id=?, is_component=?, join_fingerprint_id=?, label=?, last_updated=?, location_id=?, name=?, parent_device_id=?, parent_smart_app_id=?, previous_handler=?, previous_zigbee_id=?, primary_tile_name=?, profile_id=?, profile_type=?, protocol_connection=?, raw_description=?, sort_order=?, type_id=?, virtual_smart_app_id=?, zigbee_id=? where id=? and version=?]; SQL state [25S03]; error code [0]; (conn=1122825) Communications link failure with primary host na02useast1-datamgmt.cluster-cojnp12rqtju.us-east-1.rds.amazonaws.com:3310. Connection timed out; nested exception is java.sql.SQLException: (conn=1122825) Communications link failure with primary host na02useast1-datamgmt.cluster-cojnp12rqtju.us-east-1.rds.amazonaws.com:3310. Connection timed out @line 559 (updateSubscription)

Alternative way to set config directory

Please provide an alternative means of setting the config directory, such as a CLI parameter. Having to set a global environment variable -- and then making that variable completely generic as "CONFIG_DIR" -- doesn't leave much room for flexible deployment. At the very least, it would be helpful if the environment variable was specific to this application (i.e. "MQTT_BRIDGE_ST_CONFIG_DIR").

Question

Hi,
I have a stupid question
Can i add mqtt devices from zigbee2mqtt to smartthings with this?

Error on MQTT publish: "Client <unknown> disconnected due to protocol error."

So the SmartApp/Device seem to play nicely together, and appear to be pushing the correct information when looking at SmartThings' Live Logging:
7:40:38 PM: debug Forwarding device event to bridge: {"path":"/push","body":{"name":"Desk Light","value":"86","type":"level"}} 7:40:38 PM: debug Received event 86 on attribute level for device Desk Light for BRIDGE 7:40:38 PM: debug Sending '{"path":"/push","body":{"name":"Desk Light","value":"86","type":"level"}}' to server

The mqtt-bridge-smartthings server (server? application? helper?) is running on the same Windows machine that my instance of Mosquitto is on.

2020-04-01 19:38:19 PM info: Loading configuration 2020-04-01 19:38:19 PM info: Loading previous state 2020-04-01 19:38:19 PM info: Last Request from ST - {} 2020-04-01 19:38:19 PM info: ===================================ACTUAL SUBSCRIPTIONS REQUESTED FROM SMARTAPP ============================================ 2020-04-01 19:38:19 PM info: Currently subscribed to 2020-04-01 19:38:19 PM info: ============================================================================================================================ 2020-04-01 19:38:19 PM info: Saving current state 2020-04-01 19:38:19 PM info: Connecting to MQTT at mqtt://192.168.1.45 2020-04-01 19:38:19 PM info: Configuring autosave 2020-04-01 19:38:19 PM info: Configuring API 2020-04-01 19:38:19 PM info: Listening at http://localhost:1883

And my Mosquitto instance is seeing connections and pings, seemingly correctly. However, whenever I change the device and it attempts to send something through MQTT, I get this in my Mosquitto logs:
2020-04-01T19:40:38: New connection from 192.168.1.33 on port 1883. 2020-04-01T19:40:38: Client <unknown> disconnected due to protocol error.

Hub is on .33, mosquitto/mqtt-bridge are on .45, mosquitto's only port is 1883 using mqtt protocol. I've googled around for what could be causing this error, but I couldn't get any posted solutions working.

Ideas?

ST not responding to Bridge, Duplicate Events?

So the bridge is up and running. Updates from the ST app (or from whatever else controls the actual device) are correctly being sent to MQTT. However, I'm having problems giving commands to ST from MQTT. The bridge appears to be doing most of its job as the messages are being received and handled, but the command isn't being sent to ST.

Here's the log from when I set the Brightness of my light to 100% from the ST app, then tried to set it to 32% from my MQTT client.

Live Logging:

9:49:10 PM: debug Duplicate of last event, ignoring 'mbs-server' event '32' on attribute 'level' for device 'Desk Light'
9:49:10 PM: debug Duplicate of last event, ignoring 'mbs-server' event '32' on attribute 'level' for device 'Desk Light'
9:49:10 PM: debug Received device event from bridge: [command:false, name:Desk Light, type:level, value:32]
9:49:10 PM: debug Parsed '{"command":false,"name":"Desk Light","type":"level","value":"32"}'
9:49:05 PM: debug Received device event from bridge: [status:OK]
9:49:05 PM: debug Parsed '{"status":"OK"}'
9:49:05 PM: debug Parsed '{"status":"OK"}'
9:49:03 PM: debug Forwarding device event to bridge: {"path":"/push","body":{"name":"Desk Light","value":"100","type":"level"}}
9:49:03 PM: debug Received event 100 on attribute level for device Desk Light for BRIDGE
9:49:03 PM: debug Sending '{"path":"/push","body":{"name":"Desk Light","value":"100","type":"level"}}' to server
9:49:03 PM: debug Received event 100 on attribute level for device Desk Light for BRIDGE>

Same happens if I try publishing "../switch/set_state , 'off' " etc. I can see in the bridge's console that the messages are going through. Seems like it's handling the message, but throwing it out as a duplicate for some reason? The message shows in the console but not the error, I only see that in the Live Logging. Even if I wait several minutes between sending/receiving commands, the same behavior happens.

I checked for duplicate subscriptions that might have been confusing the bridge, but the console shows no duplicates under "ACTUAL SUBSCRIPTIONS". I am not using a devices.yml.

For reference I'm using a Tuya smart bulb for these tests (connected via Globe's new ST integration, not tasmota flashed). I also tried making a virtual device, same results. Ultimately plan to use some ESP8266 based projects communicating with MQTT, with this bridge being the connecting point to the rest of the system so I can control the ESPs from ST. I really appreciate your work and the work of stjohn.

Real time logs

Hi
First time I installed the bridge I got to see real-time commands from the bridge. How can I get that live-log again?

I know "docker logs [container-id]" but it's not live though

No connection between the componenets

Hi
After a week of trying establish MQTT server I think I need your help
Running HA on Ubuntu in a docker, installed also MBS bridge in a docker but it feels as I don't really know what I'm doing. I attach here all configurations if someone please help me have a working MQTT server.

Is there any way to check that MQTT borker and the MBS-bridge are communicating with each other?

THanks

Logs from Mosquitto broker and HA are attached

Mosquitto broker
ST device handler
ST MBS app
ST MQTT device
HA log.txt
Mosquitto broker log.txt
config yml
docker container ls

Configuration on Smartthings app

I am not being able to configure it on the new Smartthings App. On the "bridge device" remains grayed and I cannot put anything in there. Am I doing something wrong?

Show the activity of the MQTT-bridge in Terminal - Ubuntu

Hi
When I installed the docker (alpine in Ubuntu) in the terminal it showed the mqtt-bridge activity after the installation was done.

After the installation I closed the terminal.

Now it's running and working, and I would like to see the live activity again directly in the terminal in Ubuntu (I don't mean MQTT explorer).
How is it possible?
๐Ÿ˜€
Thanks

Diagnosing Possible Loop Condition

@sgupta999 I really appreciate you continuing to comment here, even though it seems you've moved on. Perhaps at some point once how I understand this I'll be able to take it over/contribute.

Anyway, I'm trying to diagnose a Possible Loop detection. The device in the log "Playroom Wiring Dimmer" was auto added to the bridge when I enabled it in the ST iOS app. So there isn't an entry for it in the devices.yml. I imagine then its falling back to what you call the "old" behavior. I'm just not entirely sure how to address this and could just use some guidance.

mbs | 2020-11-18 01:43:03 AM info: ST --> MQTT: [Playroom Wiring Closet][switch][on] [smartthings/Playroom Wiring Closet/switch][on] mbs | 2020-11-18 01:43:03 AM warn: POSSIBLE LOOP. Device[Attribute] Playroom Wiring Closet[switch] is publishing to Topic smartthings/Playroom Wiring Closet/switch while subscribed to Topic [ 'smartthings/Playroom Wiring Closet/switch' ] mbs | 2020-11-18 01:43:03 AM info: Skipping duplicate message from: smartthings/Playroom Wiring Closet/switch = on

My devices.yml file just contains a single definition. For a Virtual Device Switch in ST (that I can't get to work at all). The Playroom Wiring Closet switch appears in ST from the Brilliant.tech keypads

VDS: subscribe: switch: indigo/VDS/switch: command: 'OFF': 'off' 'ON': 'on' publish: switch: indigo/VDS/switch: retain: 'false'

Any guidance would be appreciated, by on the the loop detection and perhaps why the VDS device isn't registering at all.

Installing into hassio-not really an issue more operator(me) ingnorance.

Hello. It's been a long time since anyone has commented here. I'm not even sure if this bridge is needed anymore with the
image integration now available.
So I'm new to Hassio. I have a couple questions. First is this bridge needed any more with the above integration I listed? If it is then conitnue reading if not just let me know if you would and I'll stop trying to install.

I have successfully install everyone thing on the grove ide without issue. But the problem I have is installing the hassio bridge side. And confusing(to me) instructions.
I have hassio running in a ubuntu vm on a windows host.
I have tried every command in the instructions in numerous different ways via putty ssh and in the command line when running the vm. I am stuck. I've even tried adding it directly in hassio gui as a repository addition. I keep failing. Can anyone give me instruction?

mqtt-bridge-smartthings error on first install

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

Unable to observe mqtt messages

So, I'm still excited to see you are working on this, but I'm stuck at the same spot I was with St. Johns Configuration.

I'm expecting that once I see something setup, I should see MQTT messages at the broker when I turn on and off devices that the MQTT Broker is Subscribed to.

In my case, the device I've subscribed to is a LIFX light strip. I'm running the mutt-broker in the foreground and when I toggle the LIFX light in the SmartThings iOS on and off, I can observe the light coming on and off but I don't see messages, or any real output from the broker (running debit fwiw)

What am I missing here? Any help would be appreciated.

Can't save ip/port/mac in SmartThings IDE

Hi !

No matter how many times I tried, I always get stuck at the same step : After installing the device handler and creating a device for it, I can't set the IP/port/mac of the MBS server that is running on my PC, I always the this error on saving:

Oh No! Something Went Wrong!

Error
    500: Internal Server Error
URI
    /device/list
Reference Id
    142a3cf6-53e6-459b-9fb0-c5ea7e5ed7b6
Date
    Mon Feb 17 01:54:30 UTC 2020

I confirmed that my server is running (and http on port 8080 is accessible) so I'm not sure where the problem is. It seems SmartThings really hates something I do because at this point the device and smartapp are completely frozen and I can't even delete them and I have to wait a few hours for them to timeout a rollback transaction.

Anybody is seeing something similar ?

External sensors

Most of the instructions and design focus on exposing ST devices to external systems. However, I would like to introduce external sensors (motion, open/close, etc.) into ST. It is unclear to me how I could create a device in SmartThings that equates to a device that originated in HomeAssistant. I've seen some discussion of using virtual switches for simple on/off switches, but how can this be done for sensors?

MQTT Bridge crash : TypeError: Cannot convert undefined or null to object

Hi to all,

MQTT bridge service is continuoulsy restarting and I have the error :

2020-01-20 11:06:42 AM info: Listening at http://localhost:8082
2020-01-20 11:06:42 AM debug: From MQTT: smartthings/maison-rpi4/winesensor_cellier_1/battery/set_state = 97
/usr/local/lib/node_modules/mqtt-bridge-smartthings/mbs-server.js:477
Object.keys(subscribe[topic]).forEach(function(name) {
^
TypeError: Cannot convert undefined or null to object
at Function.keys ()
at MqttClient.parseMQTTMessage (/usr/local/lib/node_modules/mqtt-bridge-smartthings/mbs-server.js:477:10)
at MqttClient.emit (events.js:189:13)
at MqttClient._handlePublish (/usr/local/lib/node_modules/mqtt-bridge-smartthings/node_modules/mqtt/lib/clie
at MqttClient._handlePacket (/usr/local/lib/node_modules/mqtt-bridge-smartthings/node_modules/mqtt/lib/clien
at work (/usr/local/lib/node_modules/mqtt-bridge-smartthings/node_modules/mqtt/lib/client.js:283:12)
at process._tickCallback (internal/process/next_tick.js:61:11)
mqtt-bridge-smartthings.service: Main process exited, code=exited, status=1/FAILURE
mqtt-bridge-smartthings.service: Failed with result 'exit-code'.
[+] 0.2.197 20-01-2020 11:06:48 am [CMD-ERRO] fatal mqtt error - messages may not be delivered as intended (network is down. e
mqtt-bridge-smartthings.service: Service RestartSec=10s expired, scheduling restart.
mqtt-bridge-smartthings.service: Scheduled restart job, restart counter is at 183.
Stopped SmartThings - MQTT Bridge.
Started SmartThings - MQTT Bridge.

1.03 first comments... its not working!!!

Did an npm to install the new package.
Didnt use the docker, just updated everyting!
Firstly wasnt expecting a config directory... threw me on first run when I had all your devices running and then it crashed.
Then when I modified the files in the config directory, I then had problem where your devices still existed as they were in last state file! and things still crashed.
Im looking at why it is crashing now... just saying 'thow er;' after I connected to the MQTT server @ ip address! events.js:187 being the location.

Will find out more and let you know... also what's the MSB V2... I get an error if I use it, but think it is for same reason.

change icon in device handlers

new device handlers work better... but you dropped the canChangeIcon: true from this version.
Not urgent but does need to be changed at some point.

ST --> MQTT Bridge messages not retained

Hi,

I am implementing a ESP8266 sensor with ESPHome library and everything works fine so far.
The sensor is running for 60s and enter deep sleep for 15min.

I am using a "ota_switch" via MQTT to prevent going to deep sleep. That way, I am able to update the sensor via OTA.

The problem is that the message the MQTT publishes following a state change on ST is not persistent. If I happen to "time" the message during the 60s runtime, my logic works perfectly. But if push the virtual button during deep sleep, it is not retained until next boot.

I have the same behavior using MQTT Explorer, the message is not retained.
The weird thing is "MQTT --> ST" is always retain and I have no issues at all

Strange MQTT "translations"

Im working with a tv light in ST with RGB.

I can turn i off in mqtt: smartthings/Tv/switch/cmd, payload off and i get
MQTT --> ST - Topic: [smartthings/Tv/switch/cmd][off] [Tv][switch][off]

But when i want to turn it on it changes switch to level
I send smartthings/Tv/switch/cmd, payload on, but i get
MQTT --> ST - Topic: [smartthings/Tv/level/cmd][on] [Tv][level][on]

And of course it wont turn on

devices.yml and multiple topics

Im writing a device for a custom item.
Im trying to put it the device and everything crashes...

Format I thought was...
Device Name:
attriubte: xxx
subscribe:
topic:
topic:
topic:

however in V1.0 of the code I got an error when I add a custom attribute and topic and it read the second topic in the list.
Using the new code it appears to work!
Am I right to assume you fixed the problem!!!

Working with WebCore

Not a bug but a note...
when using webcore, the switches (only tested these) dont show in the main actuator list.
You need to look in the 'Compatibiliy Group 3 -> switches' section.

Errors trying to install SmartApp

Neither the "lite" nor "full" apps install via the Smartthings "Graph" IDE. Both receive the following error:
Updated 0 and created 0 SmartApps, 0 published (1 skipped due to errors)

MQTT JSON Format

Thank you for this work!

Do you plan to add the json option for MQTT server?
As you know, many devices report today the data in compact json format - as sample

{"taskname":"system","Uptime":7658292.0,"RAM":767136.0,"Load":12.1,"CPU-Temp":51.5}
{"id":"A4:C1:38:5E:E1:0F","name":"ATC_5EE10F","rssi":-91,"distance":25.51913,"model":"LYWSD03MMC_ATC","tempc":20,"tempf":68,"hum":43,"batt":81,"volt":2.932}    
{"Time":"2021-03-07T11:08:07","Uptime":"42T14:24:15","UptimeSec":3680655,"Heap":27,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":52,"POWER1":"OFF","POWER2":"OFF","POWER3":"ON","POWER4":"OFF","Wifi":{"AP":1,"SSId":"FRITZ!Box Fon WLAN 7170","BSSId":"2C:91:AB:29:2D:1E","Channel":11,"RSSI":76,"Signal":-62,"LinkCount":24,"Downtime":"0T00:21:57"}}

Most of my external devices are reporting in JSON ;)

Thanks!
Michael

installing MQTT bridge on ubuntu

Mosquitto is installed and working fine... using MQTT spy and seeing the tasmota devices and talking and listening to them happily.

Changed the devices to have a preface of 'smartthings' and everything still fine.

Install MQTT and MQTT bridge and these both install perfectly on same machine.
configure the device.yml to only have the simple switch.
configure the config.yml to have
the correct ip address (with port) for MQTT broker (mosquitto).
the deviceconfig to be true - so it opens the devices.yml file

everything starts but when we get to the point in Mqtt.client @ around line 583 we dont get a response to the client.on(connect,xxx) call. this implies the the bridge software is not connecting to mosquitto.

The port doesnt appear to be active, and reading through the documentation for MQTT and the code, I am suspecting we want to activate the websocket on port 8080, but I am not 100% sure if I am barking up the wrong tree.

example log.txt
connectToMQTT.txt

Known Working devices

Although this should work with any mqtt exposed interface i will try to document all working device here that have been tested by users and know to be working.

Tested by sgupta999

  • Tasmotized sonoff mini
  • Tasmotized sonoff basic
  • Tasmotized RF brige - using bridge i have controlled the following
    • Etekcity RF outlets
    • Generic RF switches controlling any ST devices - have tried Hue switches, X10 etc.
  • WemosD1 / nodemcu flashed with Tasmota

Tested by rhamblen

  • Sonoff mini - no problems
  • Sonoff T1 3channel - no problems
  • Sonoff T1/Touch - no problems
  • Shelly 1 (flashed with Tasmota) - no problems
  • Shelly 4 pro (stock firmware as you cant flash it!) - built the device handler and happilly working and reading power and energy.
  • NodeMCU test rig flashed with tasmota - for testing device handlers! - working fine
  • Sonofff iFan03

Tested by robross0606

  • Contact and motion sensors natively from HassIO
  • no config file needed

Some attempt at change log and known bugs

I will keep updating this post for known / reported bugs.
I will fix and post update for latest fixes here on github - so github will have all the latest versions.
Once I have enough change I will updated the version on NPM (this is primarily because you cannot ever republish a version on NPM and i don't want to keep track of too many versions)
==============03/05/2020
Publishing from ST ->MQTT with not command key there were errors.
updated mbs-server.js still not updated to version 1.05
==============01/23/2020
Retain message setting was not working correctly.
waiting to update to version 1.05 (have not published as yet)
in the meantime update mbs-server.js is on github

===========11/28/2019
Erroneously uploaded my dev environment in version 1.0.3 on NPM
had to republish to NPM with new version 1.0.4

==================== 11/21/2019
I just released version 1.0.3 on NPM and alpine and rpi docker images on docker hub.
Please check the read me page for the latest directions.
This a major upgrade to vesion 1.0.2

Changes in version 1.0.3
Significant upgrades

1 Overlapping MQTT wildcard subscription enabled
2 Completely removed and refactored the joi packages and jcsrc - every node js package is now at their latest versions
3 Changed location of config files for docker implementation
4 Providing docker images for Alpine and RPI platform

=========================================11/18/2019

  1. If no config files is specified the server crashes
  2. If using wildcards in MQTT topic server could crash

Fix for above two pushed to github on 11/16/19 - just download updated mbs-server.js
11/17/2019 fix pushed to NPM as version 1.0.2

  1. If bunch of entries removed from device config file could crash on restart.
    11/18/2019 fixed but not released - will be part of next major release.
    workaround is to delete json files from data folder and restart.
    the working dev copy is available in test folder as mbs-server-v2.js
    https://github.com/sgupta999/mqtt-bridge-smartthings/blob/master/test/mbs-server-v2.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.