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

Sending topic "switch" with payload as 0 or 1 doesn't change switch state in SmartThings #20

Closed sv87411 closed 4 years ago

sv87411 commented 4 years ago

Hi, I'm going mad with this. I have so far:

However, I cannot inject a switch state change into a NodeRed device and that state change be sent successfully to SmartThings to turn on/off a light or socket.

I'm new to NodeRed, so I may be doing something wrong. I have setup a simple manual inject that sends the topic of "switch" with numeric payload value of 1 to the SmartThings switch node. I've got a debug output on the switch node and whenever I manually trigger the inject, nothing changes in the SmartThings node and the switch state doesn't change, nothing is output in debug.

The injector is sending the following to the switch node which appears to be what is required based on the information for the node.

object _msgid: "94103186.f2953" topic: "switch" payload: "1"

I have managed to get NodeRed to send commands to SmartThings through a light node and I can see individual device events, but each event is simply a turn off event. I have no idea how to send a turn on event or a level event from a NodeRed initiated inject. They simply don't work.

Please help, this is driving me mad! :(

chacques commented 4 years ago

Hi,

I think you should inject message like this (pay attention to payload). I did struggle with this as well :)

{ "topic": "switch", "payload": { "value": 1 } }

-Juha

nst2020 commented 4 years ago

Going mad aswell.

My setup is local and the URL is correct. I can see events in Node-Red from SmartThings as well the devices. I can switch on/off my Garden Light with a inject node with {"value":1} for on and {"value":0} for off I have a Smartthing Arlo Go Cam which is also a motion detector. The motion detector send for motion off {"deviceId":"756a0a58-0c18-4849-8fbf-829ee8311fa3","deviceType":"motion","name":"Arlo Go","value":0} For motion on {"deviceId":"756a0a58-0c18-4849-8fbf-829ee8311fa3","deviceType":"motion","name":"Arlo Go","value":1} My plan is if the motion detector detect movement than my smartthing garden light should switch on. After 5 min the light should be switch off. Can someone please explain how to manage this in node-red.

thx guys

arkieguy commented 4 years ago

Maybe this will get you started:

https://pastebin.com/bXbVMJS2

nst2020 commented 4 years ago

Hi arkieguy,

thx for the reply. There is something broken on your export flow. Cant import it. Can you resend it ?

arkieguy commented 4 years ago

Sorry, it looks like some quotes got stripped... Try this:

https://pastebin.com/bXbVMJS2

nst2020 commented 4 years ago

wow working !!! Thx for the lesson. Now i know how 2 move forward with switches

arkieguy commented 4 years ago

Glad I could help.

sv87411 commented 4 years ago

Hi,

I think you should inject message like this (pay attention to payload). I did struggle with this as well :)

{ "topic": "switch", "payload": { "value": 1 } }

-Juha

Thank you for the the reply and clarification. Only after looking at the SmartApp code and smartthings-onoff.js node code was I able to fully understand. The text in the node help is very misleading. It says:

"switch can be used to change device state. The message will be something like this: { topic: "switch", payload: { value: (1|0) } }"

That suggests that the value of the payload itself is 0 or 1. Critically, double quotes are missing from "value".

As I've been working with Home Assistant integration this is how states are represented in the HA messages - with the state being the payload itself. Additional information is in a 'data:' array.

It's far from obvious that there has to be a variable called 'value' in the payload. Using 'value' as a variable name is also very confusing as value means simply that... a value! This part of the payload should be called 'state' and the help text should say:

"switch can be used to change device state. The message should be structured as follows: { topic: "switch", payload: {"state":(1|0)} }"

Note the rather critical double quotes around "state". Or even use "on" and "off" as states.

I can see by looking at the code that 'value' must have been chosen early on, but I think an alternative name, like 'state', would be easier to work with. And the help text could be clearer. Unfortunately while I can prod around in Javascript and Groovy, and mostly understand it, I'm not proficient enough to completely recode the SmartApp or nodes. If I was, I would happily update them as having direct Node Red to SmartThings integration is really useful and avoids having to go through Home Assistant.

Thanks all anyway, I now have it working!

Tontze commented 3 years ago

Propably a stupid question, but where can you send a message formatted like In these examples?