otaviojr / node-red-contrib-smartthings

Allows you to control your devices and get their status using NodeRed
MIT License
32 stars 16 forks source link

mqtt to contact node #25

Closed raisingskell closed 2 years ago

raisingskell commented 4 years ago

This may be a node-red inexperience issue but would appreciate any assistance.

I have contact sensors reporting into node-red via mqtt, works well. I have node-red-smartthings installed, simulator proves connection is good. Native ST devices report status change in node-red.

My goal is to have the mqtt contact sensor node update ST via the OpenClose node.

[mqtt contact node] -> [OpenClose Node] -> ST.

Is this possible? The OpenClose node only reports status for what it sees in ST.

I'm assuming I'll have to convert the string from the mqtt node to an object for the OpenClose node (been at that for hours) and I'll continue working that once I know if my goal is possible. I've read thru the docs and all other posts with no luck. Maybe I'm just too tired to see what's right in front of me.

Much appreciated.

nateguru commented 4 years ago

You can write a smart app that you can access from node-red via a http request. You map the endpoints in the smart app. In the smart app, you can call methods in a custom device handler to update the virtual device. I did this with a temperature/humidity sensor mqtt subscription to node-red to smart things. I don't think it is possible to update the device directly, since it doesn't have a command to set the value.

This may help, https://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/tutorial-part1.html

This program made it easy to get the bearer token needed for accessing the smart app end point. https://github.com/BrettSheleski/SmartThings-SmartApp-OAuth-Helper

raisingskell commented 4 years ago

Thanks nateguru. The 2 wire points on the smartthings nodes threw me off. I assumed I could wire the mqtt-in node to the left wire point of the open/closed node and that would update ST. Apparently it must be one-way communication from ST to the node only.

image

Oh well, back to the drawing board. Thanks for the pointers in those links. I guess its time to start building custom handlers.

nateguru commented 4 years ago

I haven't tested these, but here is a simple smart app and device handler.

Open Close Device Handler.txt Open Close Smart App.txt

nateguru commented 4 years ago

Example from my mqtt temperature sensor to ST Node Red Flow.

MQTT to ST Flow

In Set msg.query,

var baseurl = 'https://\<BASE-URL>/api/smartapps/installations/\<APP INSTALLATION ID>/updateTemp/' msg.query = baseurl + msg.payload.value; msg.headers = { 'Authorization': 'Bearer \<TOKEN>' } msg.body = msg.payload;

return msg;

In http request,

Set URL to {{{query}}}

sbparsons commented 3 years ago

A bit off topic but @nateguru you mentioned " temperature/humidity sensor mqtt subscription". I'm looking for temperature sensors with mqtt support - would you mind me asking what devices you have?

nateguru commented 3 years ago

A bit off topic but @nateguru you mentioned " temperature/humidity sensor mqtt subscription". I'm looking for temperature sensors with mqtt support - would you mind me asking what devices you have?

I couldn't find one I liked so I ended up getting an Adafruit board with the Sensirion SHT31-D sensor and making my own. The easiest and cheapest option is connecting it to an esp8266 doing MQTT.

https://www.adafruit.com/category/product/2857

Adafruit also makes a nrf52840 board that has an SHT30 Temp/Humidity sensor, but it would require a BLE to MQTT bridge to get it to MQTT.

https://www.adafruit.com/product/4516