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.

(*) NOTE: 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 shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop 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 “whatsAppLampe”).

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 NodeCode:

[{"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"}]

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. 🙂

Fab

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 it that I share these 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: Schade, ich hatte mir von dem Artikel mehr versprochen. Aber der Reihe nach.

    Gesucht hatte ich nach einer Möglichkeit Nachrichten an WhatsApp zu senden (z.B. wenn meine Waschmaschine fertig ist, oder das Fenster immer noch offen ist,…). Also eher die andere Richtung. Deinen Artikel habe ich trotzdem gelesen und mir auch den Code reingezogen in der Hoffnung Anhaltspunkte zu finden, wie man mit WhatsApp kommuniziert. Leider Fehlanzeige:

    1) Gibt’s keinerlei Erklärungen zur Funktion des Codes
    2) Beim Import fehlern 2 nodes (sonoff und alexa). Da gehören also wohl noch 2 Bibliotheksfunktionen/AddOns zu den Vorraussetzungen – inkl. der Links dazu

    Sonoff liese sich ersetzen. Ich habe z.B. das Tasmota AddOn. Was vermutlich von einem anderen Entwickler ist, aber die gleiche Funktion hat!? Erläuterungen zu externen Bibliotheksfunktionen wären also sinnvoll.

    Alexa habe ich nicht und will ich nicht. Auch daz wäre ein Alternativvorschlag bzw. Beschreibung sinnvoll. Ich vermute, dass Alexa mit WhatsApp verknüpft ist und die Info bei einer eintreffenden Nachricht weitergibt!?

    Ansonsten schönes Blog. Und in deutsch :-). Der HW-Teil sehr gut beschrieben und bebildert. Betreibst Du den Blog allein? Wäre sicher auch ein schönes Communityprojekt um noch mehr Projekte/Beispiele zu sammeln.

    Hast Du eine Idee für senden von WhatsApp- Nachrichten – ohne Alexa ;-). Ich hatte mal was gefunden, wo man sein Festnetztelefon registrieren konnte und dann von NodeRed aus Nachrichten ganz normal darüber senden konnte. Finde das aber nicht mehr. Es gibt wohl einen US-Server der das auch vermittelt. Aber was die dann wieder an Daten sammeln….

    1. Hi Konrad,
      erst mal sorry für die späte Antwort und danke für deine Tipps und Hinweise. 🙂
      Du hast recht. hier fehlen noch ein paar Infos. Ist schon eine Weile her, dass ich diesen Artikel geschrieben habe und damals habe ich noch nicht immer alle Infos so ausführlich dazu gepackt. Werde ich aber nachholen, wenn ich diesen Artikel überarbeite. Ich plane diese Art Lampen bald auch mit von dem pxlBlck Plugin unterstützen zu lassen. Dann würde ich dazu nochmal einen Artikel schreiben.
      Zu der whatsApp Problematik:
      Leider lässt WhatsApp keine externen Clienten zu und ist auch sehr streng wenn es darum geht alle Versuche in der Richtung zu blocken. Um trotzdem über neue WhatAapp Nachrichten benachrichtig werden zu können habe ich damals mit Tasker (heute wurde ich Automate nutzen) eine Automatisierung auf meinem Handy erstellt. Diese hat dafür gesorgt, dass bei jeder eingehenden Whatsapp-Nachricht ein Signal an meinen MQTT Server gesendet wurde. Dieses Signal kann man dann nach belieben weiterverarbeiten.
      Den umgekehrten Weg habe ich leider nie umgesetzt. Benutze dafür (um mir Nachrichten aufs Handy schicken zu lassen) aber seit Jahren Pushbullet. Infos dazu findest du zum Beispiel hier: https://nerdiy.de/howto-nodered-pushbullet-benachrichtigung-bei-ssh-login/
      Was das auslösen von Telefongesprächen angeht:
      Falls du eine FritzBox hast kannst du daran auch externe SIP clienten anmelden. Solche SIP clienten lassen sich auch auf einem RaspberryPi installieren. Dieser könnte dann an die Fritzbox angemeldet werden und auf Befehl einen Anruf tätigen und zum Beispiel eine mp3/wav abspielen. Ist aber erst mal nur theorie. Ist noch auf meiner “muss ich mal ausprobieren” Liste. 😀

      Zum Blog:
      Ja, den betreibe ich alleine. Vielen Dank für das Lob. 🙂
      Beste Grüße
      Fabian

Leave a Reply

Your email address will not be published. Required fields are marked *