How To: Node Red – Control the WhatsApp(*) lamp

In the article NodeRed/Tasmota - Building a WhatsApp(*) Icon Lamp explains how to build your own WhatsApp (*) lamp. The goal is to link these later with your SmartHome and, for example, to light up as soon as new notifications are available for you.

With the following NodeCode you can now test your own WhatsApp (*) lamp.

(*) GRADE: WhatsApp® and the WhatsApp logo are trademarks of WhatsApp, Inc., registered in the US and other countries.

Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section. 
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂


Safety instructions

I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/

Affiliate links / advertising links

The links to online stores listed here are so-called affiliate links. If you click on such an affiliate link and store via this link, Nerdiy.de receives a commission from the online store or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂


Requirements

Helpful Articles:
Of course NodeRed should already be installed so that you can take over this configuration.
How to prepare a RaspberryPi and then NodeRed installed on it is described in the following articles.

The following articles describe what to do to prepare the RaspberryPi:
RaspberryPi - Setting up for Nerdiys!
RaspberryPi - The First Configuration!
RaspberryPi - Control the RaspberryPi via SSH
NodeRed - Installing NodeRed on the RaspberryPi
NodeRed - install new nodes

Required tools:
-none-

Required material:

In the following list you will find all the parts you need to implement this article.


Log in to the NodeRed configuration interface

Before you can edit your NodeRed configuration you must - if activated - first log in to the NodeRed configuration interface.

View of the login screen. Here you have to enter the login details that you entered during the configuration of the login. Information about this can be found in the article NodeRed - User Login Setup.

Import node code

With the following NodeCode you can control your WhatsApp (*) – lamp. You may need to change the name of your lamp (if it is not "whatsApplamp").

To test this code you can easily import it into your NodeRed installation. Tips can be found in the article NodeRed - Import and Export Node Code.

 

Structure of the NodeCode.

Here is the actual node code:

[{"id":"d2257647.527f38","type":"comment","z":"73482476.7e376c","name":"whatsAppLampe","info":"","x":180,"y":80,"wires":[]},{"id":"43faa0fa.f5215","type":"function","z":"73482476.7e376c","name":"","func":"if(msg.payload==\"on\")\n    msg.payload=true;\nelse\n    msg.payload=false;\n\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":160,"wires":[["cea5363d.3ac848"]]},{"id":"8da7a0d5.d8df1","type":"link in","z":"73482476.7e376c","name":"","links":["1c0fd2a8.9119ad"],"x":415,"y":120,"wires":[["cea5363d.3ac848"]]},{"id":"1d6f002c.17d81","type":"function","z":"73482476.7e376c","name":"","func":"msg.payload=\"#\"+msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":280,"wires":[["36b79394.d5f8dc"]]},{"id":"986fc0d1.bb7a7","type":"inject","z":"73482476.7e376c","name":"","topic":"","payload":"#ff9900","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":410,"y":320,"wires":[["36b79394.d5f8dc"]]},{"id":"36b79394.d5f8dc","type":"mqtt out","z":"73482476.7e376c","name":"","topic":"cmnd/whatsAppLampe/Color","qos":"","retain":"","broker":"c94e86db.dfcde8","x":640,"y":280,"wires":[]},{"id":"bd4379c0.b53908","type":"link in","z":"73482476.7e376c","name":"","links":[],"x":435,"y":360,"wires":[["36b79394.d5f8dc"]]},{"id":"95cfffe0.781bb","type":"ui_colour_picker","z":"73482476.7e376c","name":"","label":"whatsAppLampe","group":"9efc6f05.1b9a2","format":"hex","outformat":"string","showSwatch":true,"showPicker":true,"showValue":true,"showHue":false,"showAlpha":true,"showLightness":true,"dynOutput":"false","order":27,"width":0,"height":0,"passthru":true,"topic":"","x":210,"y":280,"wires":[["1d6f002c.17d81"]]},{"id":"897fb059.a7a5c","type":"ui_switch","z":"73482476.7e376c","name":"","label":"whatsAppLampe","group":"5303eeb6.d88a3","order":22,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":650,"y":220,"wires":[["cea5363d.3ac848"]]},{"id":"cea5363d.3ac848","type":"Sonoff device","z":"73482476.7e376c","mode":"0","broker":"c94e86db.dfcde8","device":"whatsAppLampe","name":"","onValue":"ON","offValue":"OFF","cmdPrefix":"cmnd","statPrefix":"stat","telePrefix":"tele","x":630,"y":160,"wires":[["897fb059.a7a5c"]]},{"id":"7f0d7652.2d8a18","type":"alexa-local","z":"73482476.7e376c","devicename":"whatsAppLampe","inputtrigger":false,"x":210,"y":160,"wires":[["43faa0fa.f5215"]]},{"id":"33dc6f08.e3c04","type":"link in","z":"73482476.7e376c","name":"","links":["26a5b5ea.e3b65a"],"x":295,"y":200,"wires":[["7907aaef.b7a234"]]},{"id":"1ff908e8.669237","type":"link in","z":"73482476.7e376c","name":"","links":["d54aad83.530c2"],"x":295,"y":240,"wires":[["9353016f.ee0f8"]]},{"id":"7907aaef.b7a234","type":"change","z":"73482476.7e376c","name":"true","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":200,"wires":[["cea5363d.3ac848"]]},{"id":"9353016f.ee0f8","type":"change","z":"73482476.7e376c","name":"false","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":240,"wires":[["cea5363d.3ac848"]]},{"id":"c94e86db.dfcde8","type":"mqtt-broker","z":"","name":"Server-Mqtt","broker":"server.fritz.box","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"9efc6f05.1b9a2","type":"ui_group","z":"","name":"Licht-Farbe","tab":"b29a978f.019318","disp":true,"width":"6","collapse":false},{"id":"5303eeb6.d88a3","type":"ui_group","z":"","name":"Licht","tab":"b29a978f.019318","disp":true,"width":"6","collapse":false},{"id":"b29a978f.019318","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

Have fun with the project

I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂

P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate that I share this information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com   

2 comments

  1. Feedback: Too bad, I had expected more from the article. But one after anonther.

    I was looking for a way to send messages to WhatsApp (e.g. when my washing machine is finished or the window is still open,...). So rather the other direction. Nevertheless, I read your article and also checked the code in the hope of finding clues on how to communicate with WhatsApp. Unfortunately none:

    1) There's no explanation of how the code works
    2) 2 nodes (sonoff and alexa) fail during import. So there are probably 2 library functions/addons that are required – including the links to them

    Sonoff could be replaced. For example, I have the Tasmota AddOn. Which is probably from a different developer but has the same function!? So explanations of external library functions would be useful.

    I don't have Alexa and I don't want it. An alternative proposal or description would also be useful. I assume that Alexa is linked to WhatsApp and passes on the information when a message arrives!?

    Otherwise nice blog. And in German :-). The HW part is very well described and illustrated. Do you run the blog alone? Would certainly also be a nice community project to collect even more projects/examples.

    Do you have an idea for sending WhatsApp messages – without Alexa ;-). I once found something where you could register your landline phone and then send messages from NodeRed as normal. But don't find that anymore. There is probably a US server that also mediates. But what data they then collect again….

    1. Hi Konrad,
      first of all sorry for the late reply and thanks for your tips and hints. 🙂
      You're right. some information is missing here. It's been a while since I wrote this article and back then I didn't always pack all the information in such detail. But I will catch up when I revise this article. I plan to have this type of lamp supported by the pxlBlck plugin soon. Then I would write another article about it.
      Regarding the WhatsApp problem:
      Unfortunately, WhatsApp does not allow external clients and is also very strict when it comes to blocking all attempts in the direction. In order to still be able to be notified about new WhatAapp messages, I used Tasker (today I would use Automate) to create an automation on my cell phone. This ensured that a signal was sent to my MQTT server for every incoming Whatsapp message. This signal can then be further processed as desired.
      Unfortunately, I've never done it the other way around. I've been using Pushbullet for years (to have messages sent to my cell phone). You can find information about this here, for example: https://nerdiy.de/howto-nodered-pushbullet-benachrichtigung-bei-ssh-login/
      As for triggering phone calls:
      If you have a FritzBox you can also use it to register external SIP clients. Such SIP clients can also be installed on a RaspberryPi. This could then be registered with the Fritzbox and make a call on command and play an mp3/wav, for example. But that's just theory. It's still on my "must try" list. 😀

      To the blog:
      Yes, I run it alone. Thank you for the praise. 🙂
      Best regards
      Fabian

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert