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

Can't force updates using topic: update on input #1

Closed wonderwareguru closed 4 years ago

wonderwareguru commented 4 years ago

Greetings,

First off, I really really appreciate your Smartthings contribution. It means a lot to me, and is a life saver in tying together my z-wave, mqtt, modbus project together. Much respect. My issue involves status updates. Whenever I deploy, the output status / values for smartthings shows in debug...

"device : msg.payload : Object object deviceId: "546fbc2b-fe82-412d-8f04-9133909ebdd2" deviceType: "contact" name: "KITCHEN DOOR" value: 0"

however, when I change the device state, the node-red status does not change, unless I re-deploy.

I read your help statement: "Besides, if you need it to output the status, like when responding a http request, you can use the topic with the update value to force it to report."

I can't get the update to work for the life of me. I've tried everything and the kitchen sink.

Can you please clarify. With "Inject", I type "update" in the topic field, and leave the payload type "string" and the field blank. Is this correct?

When I trigger the input I get...

"update : msg.payload : string[0]"

in debug, on the output of the smartthings node.

I tried the update in topic for contact, motion... with the same result.

Can you please help... what am I missing.

Thanks a lot.

otaviojr commented 4 years ago

Hi,

The update topic on the input will only force the node to output its current state.

The real update will happens through the webhook. Have you installed the smartapp?

The smartapp will listen to all events and send them to NodeRed.

Nodes will them listen for those events to update theirs status

Are your smartapp/webhook working?

Regards

wonderwareguru commented 4 years ago

Hi, Thanks for the reply. Your patience is greatly appreciated :)

My nodes are reporting correct events in Node-Red, but the nodes do not automatically update on their own. If I reload Node-Red's HTML, or re-deloy the nodes in Node-Red, the node events update without issue.

You stated that "The update topic on the input will only force the node to output its current state." This is what I'm having an issue with.

For me, the "update" topic on the input of your node will not force the node to output its current state. It will only if I redeploy or reload the HTML

In order to force the output, do I use an "Inject" node, and type "update" in the topic box? If so, what is also the data type and content of the payload. I believe this is where the issue is.

Can you please give a quick example of how you would set up the input of your node. Are you using Node-Red's "Inject" node? What is the msg.payload for the input of your nodes?

Thank you Sir.

otaviojr commented 4 years ago

Hey, don't worry about that.

As I'm developing this, I really want to understand what is going on.

Right Now, I don't believe that the problem is at NodeRed End. I believe that the problem is at SmartThings setup.

We can execute some procedures just to make sure that Smartthings Webhook is working all right.

smartthings_1

1) Click on My Locations and choose the location you want 2) Click on My Smart apps

smartthings_2

3) Click at the webhook you created with our smartapp application

smartthings_3

4) Start the simulator

smartthings_4

5) Set the location to debug 6) Configure the webhook address. It should be your NodeRed public address plus "/smartthings/webhook"

smartthings_5

Choose a device, could be a virtual one, which is easier to test.

7) Click install

Screenshot from 2019-10-20 18-56-19

Change the device state and look for the logs... if there is any error it will output here.

Actually, if everything works all right nothing will be logged in.

Sorry about this giant procedure... but this webhook is the one who send update messages to NodeRed. We must be sure it is working all right in order to the node to update correctly..

I thank you to help me to make this code better.

regards,

wonderwareguru commented 4 years ago

Hi, Otaviojr Thanks for the tutorial. I followed it and got errors. Attached are screen shots. When you say

"Configure the webhook address. It should be your NodeRed public address plus "/smartthings/webhook""

<--------------------------------------->

![Uploading Screen Shot 2019-10-20 at 7.40.58 PM.png…]()

Screen Shot 2019-10-20 at 7 48 12 PM

<---------------------------------------->

The following is my NODE-RED setup and issue:

Screen Shot 2019-10-20 at 7 51 30 PM Screen Shot 2019-10-20 at 7 50 53 PM

When the value is 0, the contact is closed; when the value is 1, the contact is open. This is reporting correctly to Node-Red.

Any ideas about forcing Node-Red to poll the Kitchen Door node?

Thanks

otaviojr commented 4 years ago

1) If we make the webhook works, you will not need the update node. It's correct, but the device will receive a message from smartthings and output the updated state. This is only useful when you want to get the status without an event from smartthings.

2) Without the webhook the behavior is all right. The device will update at the deploy to have the initial state. After that only when it receives messages from SmartThings webhook.

2) About the error, SmartThings have some rules. One of them is, the SmartApp is not executed in the hub, but in the cloud. Outside your local network. So, it must be publicly acessible. Like a domain, for example. I will check if there are any way to perform it from the hub, but, SmartThings doesn't like that too much..

We need to focus on how to make the webhook works (solve those console errors). They will make the device node update and output the message as soon as they have been changed.

regards

wonderwareguru commented 4 years ago

Otaviojr, I'm confused, where can I find the public IP address? https://xxx.xxx.xxx.xxx/smartthings/webhook?

otaviojr commented 4 years ago

I have done a new option at smartapp configuration.

It will have now a local network option.

Screenshot_20191020-225457

You can turn it on and use your local address:

http://192.168.0.xx/smartthings/webhook.

Can you get the new smartapp from github?

regards

otaviojr commented 4 years ago

you can find it here:

SmartApp

otaviojr commented 4 years ago

Hey @wonderwareguru, did you test the new smartapp. Did it work?

wonderwareguru commented 4 years ago

Hey brother... sorry, I have been unable to test yet. I'm going to test in an hour or so...

Thanks

wonderwareguru commented 4 years ago

OK, I got it working. Do not change anything. I'll take some time later this evening to document (pics, video) how I set it up and I'll post it to this thread.

Thanks...

Tokter commented 4 years ago

I followed these steps trying to debug the same issue. What I missed was that I didn't select the switch in the smartapp. I assumed all events would be forwarded to node red. Once I selected the switch in the "Choose what events you want to trigger" section, everything is working. Thanks for you great work!

mpkayeuk commented 4 years ago

I'm having exactly this issue, with the Local Network Call. It updates when I deploy, but not with an injected update. Also, I can't get injectors to change the state of even a simple switch device. When I do the simulation step, the simulator appears to work perfectly!

mane-wt commented 4 years ago

If you add the port, it will work, http://192.168.0.xx:1880/smartthings/webhook.

I have problem with the Button-node and the Motion-Sensor node with sensors from IKEA. I have a Samsung motion sensor and a IKEA motion sensor but only the Samsung one produces output from the node. I only have IKEA button/remote to test but I assume it is the same problem as with the motion sensor.

The thing left for me after non-Samsung sensors is the inject-node with update that does not work. I have put topic=update and tried with different payloads but all I get throuch is the same msg passed trough with the same topic/payload as I entered for input. If topic <> update, nothing goes through.

mane-wt commented 4 years ago

I can add that the IKEA button battery delivers the battery percentage OK in the Battery-node

otaviojr commented 4 years ago

You can not force update by this way. It will update automatically when anything changes. This is what the smartapp does.

You can send a message to the node to change its state. For example, turn on a switch.

When you deploy it will update, after that, when anything changes, the SmartApp will send the new state to the node. So, there is no need to force update it.

Do you have configured your SmartApp selecting all devices you have? The SmartApp will only send messages to the selected devices...

If you have a device who has more than one function you have to select it in more than one place. If it has a motion sensor and temperature meter, you have to select it on motion devices and temperature devices. Other else, it will only receive messages from the selected function.

PS.: The battery is a different selection. If you only select the device at motion sensor section you will not receive battery messages.

regards, Otávio Ribeiro

mane-wt commented 4 years ago

OK, really no need to force update anyway.

The other problem still remain with the motion sensors from IKEA. In more detail:

My flow looks like: Flow

And the motion nodes: 2019-12-28 10-31-15 2019-12-28 10-32-26

When I deploy, both generates output: Deploy

With movement I only get output from Samsung Motion Sensor, not IKEA: Motion

I got output in the Samsung SmartThings App in the mobile for both sensors, here IKEA: IKEA rörelse

And after a few seconds: IKEA ingen rörelse

The only difference I have seen between the sensors is that Samsung has build in temperature, and IKEA have not but this probably does not matter with this node that only looks at motion.

Any idéas?

BR Magnus

otaviojr commented 4 years ago

Above, in this thread, has some steps to debug the SmartApp. Could you debug it with the IKEA device selected? Than we can see if there are any problem with the IKEA device which is preventing the SmartApp from sending the update message.

Have you tried to play with the name of the device? Shorten it, remove the special character, etc? These is the only difference I saw.

If you help me to understand this problem I can fix it. Unfortunately I don't have any IKEA device. I have many motion sensors, but no one from them.

regards, Otavio Ribeiro

mane-wt commented 4 years ago

Thanks for the offered help!

I have shortened and removed the special characters so the new name is "IKEA Motion Sensor" but unfortunately that was not the issue.

I will now try the debug steps and report back.

BR Magnus

mane-wt commented 4 years ago

Some debugging done now.

The debug output look very similiar with Samsung and IKEA motion sensors: Samsung debug "gear" Samsung motion sensor gear

IKEA debug "gear" IKEA motion sensor gear

Samsung debug: Samsung motion sensor debug 2

IKEA debug: IKEA motion sensor debug 2

Live logging reveals: Live Logging

One strange thing I found was that my IKEA sensor is not in this list: Event subscriptions

BR Magnus

otaviojr commented 4 years ago

Just to let us on the same page.

Do you have the classical SmartThings app installed?

On Automation -> SmartApps -> NodeRed -> Motion Sensor section, do the IKEA device appears on the list, is it selected?

It not being selected could explain why it is not appearing at event list.

Do you have access to the RedNode output console?

I left some debug messages behind for situations like these. If you move yourself in front of your IKEA sensor the webhook should output something at the console. We could check there to see if there is any error message from the webhook.

In those debug prints you sent, those events happens when you cross in front of the sensor? We must isolate the battery and temperature messages. But, anyway, messages appears to be going without any error. So, we need to check the console to get something on the other side, the webhook.

Regards, Otávio Ribeiro

mane-wt commented 4 years ago

Thats it!!

For some reason only some of my sensors where selected, it looked like: Screenshot_20191229-184313_SmartThings After ticking the box the motion sensors worked flawlessly, thank you!

I checked all the sensors in this view and tested the IKEA Button. Flow

This also worked but I got several "red"-marked output in Node-Red debug window with only one klick on the IKEA button: IKEA Remote button

The last 2 messages expanded: Expanded

In Samsungs Debug I got the same as with the motion sensor.

In Samsungs Live Debug I got: IKEA Live Debug

It works but the red-marking is a bit anoying. Could it be debug-text from the Node-Red node itself or can I just ignore this?

BR Magnus

otaviojr commented 4 years ago

Those messages are mine. I’output them from inside the plugin. They can help me to debug when things goes wrong. As the code gets more mature I will remove them. For now, just ignore them.

Regards, Otávio Ribeiro

mane-wt commented 4 years ago

Thank you very much for the help :-)

I will try to use my Samsung Airconditioner and see how that works with your nodes next.

BR Magnus