[Tutoriel 4] Création basique d’une interface Node-Red

Problème résolu! Voir le post original: Node Red: A widget based dashboard working with Homey trough MQTT

We can connect the already placed MQTT receiver to the switch. But… the switch needs a Boolean, and everything MQTT sends are strings. (some nodes convert these automatically, like gauges) So it needs an extra step to convert a string Boolean to a real Boolean.
Connect the MQTT receiver to a function node (this is a node where you can add a piece of javascript) double click and add:
if(msg.payload === "true"){ msg.payload = true; }else{ msg.payload = false; } return msg;

This converts a string to a Boolean (I know there are shorter smarter ways to do this, but this is more understandable)
Now connect the function node to the switch and it should switch on and of with the light outside of node red. (You might want to uncheck the pass through, otherwise you get a continuous loop).

1 Like