2-way Whatsapp Messaging with webCoRE


#1

Getting an integration between WhatsApp and SmartThings/webCoRe was something i have been looking for. The main purpose for this was to get a message whenever the last person leaves the home, to get a whatsapp message notifying if there are any lights or switches left on and with a reply, it can then turn it off.

Another main use was to send a “Status” message and get feedback about my house that i feel is important like the current weather at home, light and switches that were on, who was at home, etc. This integration helps me with this.

This was always doable on the ST app…but for me, the app is just so laggy hence messaging is so much more easier - that way i don’t have to stare at the phone while the app refreshes.

The steps are generally very simple to follow. And if you have been using webCoRe, this gets even more simpler. There are quite a few steps, but pretty easy and straight forward. The best part is that there is no SmartApp or DTH to install!

I’ve written a detailed walk through on how to get this done over on my blog (it has got basic piston sample on how to receive and send messages, if the below piston is a little ‘long’!):-

Here’s a sample of my piston (once all the twilio stuff has been done). The piston also sends a message to whoever leaves the house about the lights/switches that are still on. I can also send a message with the below commands to do stuff…
Off - will turn all lights and switches off.
Status - weather over at my house and who is at home
Sleeping - check who is sleeping (working with webCoRe presence sensor)
Wake up $name - wakes the sleeping person up (as sometimes my son forgets to activate his wake up automation).

What great pistons can you build with this?


Text yes to run a routine or piston
#2

I missed out something important in my post - the URL that was needed to do the POST, i have added that now. The URL btw is https://api.twilio.com/2010-04-01/Accounts/twilioAccountSID/Messages.json

You can get your Twilio Account SID over on your Twilio dashboard under Settings.


#3

as i wrote on your blog:

excellent tutorial…but i have a comment about exercise #3 (the one where you check the status of lamp)

i think you need first to set To = From before assign variable From = Twilio sandbox number…

i was trying on with your piston with no luck but if i change that order it works…

you would need to change the variable assingation for both conditions

anyway this is awesome…its a new world of possibilities using both whatsapp and webcore!!


#4

this the way it works for me (where the number is the twilio sandbox number)
image


#5

Thanks for highligting that. Have updated the screenshot with the correct squence.

Cheers.


#6

hey btw, im having problems with this piston. In the part where piston sends notification via whataapp of who is leaving…

i mean…how do i need to assing who’s number need to send whatapp message? in your piston i dont understand the sentence …thanks


#7

I’m assuming you mean

{whosAway} == 'Kevin' ? 'whatsapp:+123456789' : 'whatsapp:+132456789'

On the first IF statement, whichever presences sensor changes to not present, it saves the matching entry to a variable “whosAway”.

So let’s say you have 2 presence sensors called Adam and Eve. Lets say Adam’s number is 123456789 and Eve’s number is 987654321. The statement would look like this

{whosAway} == 'Adam' ? 'whatsapp:+123456789' : 'whatsapp:+987654321'

So if Adam leave, he will get a message and if Eve leaves, Eve will get a message.

I’m using a ternary operator as explained in the wiki -
Ternary operator ( c ? t : f )
A great tool to simplifying expressions, the ternary operator evaluates c as a boolean, then if that evaluation is true, returns t, otherwise returns f.


#8

done! but i have a issue: im receiving twice the same WA meessage when i leave my house and one lamp is remainig on…its weird because i received only one if its off before i leave…any ideas?


#9

It could be that when you tested, both parties present was changed to not present, hence firing it twice and you getting the message twice? To avoid this, and only send the message to the last person that leaves you can add an AND statement after the IF -

and
Location mode changes to Away

or you can do it in this way -

and
ALL presence sensor is NOT present

On the bulb not turning off, not too sure. Can you check on the ST app, go to the bulb in question and check the ‘Recently’ tab if the piston sent the off command or not.


#10

thanks! it works well. so, i added some more stuff like “On” (the opposite of Off case), “temperature” and “battery” …this last is very useful to know in a quick way battery reamining on sensors


#11

Was working fine but when it stopped working spontaneously and I checked the log to find “Error executing external web request: groovyx.net.http.HttpResponseException: BAD REQUEST” error.
Any ideas/help how to resolve it.


#12

Mine is still going along fine. The error you received, was it for sending or receiving a message?


#13

While the piston sends the message. Maybe quota problem as I am still using trial account?


#14

I don’t think that is the issue. I am now only as of a couple of hours ago - having the same problem. Can’t send and receive messages. Had a look at the logs from Twilio and twilio is registering an internal error. It could be an issue on their end. Will try and reach out to them to see if it is.


#15

The problem looks to be resolved now. Can you check and see if you can now send and receive messages?


#16

No, no luck, still the same.