I have a number of flows that use the state of some global variables to decide what to do when certain triggering events happen. For example I have a flow that sets my slack status to "waiting on the bus" when the garage door opens in the morning (because I always retrieve my bike from the garage to take with me on the bus). But I only want it to do that when I am home, so I maintain a boolean global variable that shows whether I'm home or not, which is controlled via a geofence. That way, if my wife opens the garage in the morning after I've already arrived at work, it doesn't change my slack status. If my webhook fails when I cross the geofence boundary on my way to work, then my wife opening the garage door will change my status to waiting on the bus.
Another example: sometimes my vacation timer node doesn't turn off like it should when I arrive home from vacation (via geofence - I have Sprint, so webhook calls fail if I'm on the phone when I cross the geofence boundary). This results in a surprise when sometimes the lights turn out on me randomly. The vacation time I use doesn't seem to show when it's on or off, so I created a global variable to show when vacation mode is on or off.
The problem is that I don't know what the status of my global variables are unless I intentionally go in and check it. I'd like some passive cue that's there for me to notice or check easily, like an LED status indicator or something. E.g. a vacation mode LED that shows if my vacation mode is on or off. It would be ideal if there was something on my phone I could use to check these statuses as well. Are there any devices, tricks, or (iOS) apps anyone uses to be able to check out node/global var status?
One way I would solve this by polling the values you are interested in by a repeating inject node trigger a switch or function node. I donât know of a callback you can place to avoid polling.
For notifications I would use a messenger of your choice to get the information on your favorite device.
Another way is to keep them in Retained topics in MQTT, then whenever they change they automatically tell any nodes that need to know that they need to do something. If the retained value is needed in conjunction with another value or event then you can use a Join node (probably in key/value pair mode) to merge the retained value in with the other data.
Hmmm... I'm not sure I understand. Perhaps I've not described what I need very well and you're solving a different problem than the one I'm asking about? I don't need notifications. The global variables are doing their job correctly. I just want an easier and more accessible way to see the states of my global variables. I envision an array of LED lights, each one representing the boolean state of one of my global variables. E.g. a vacation mode LED - when lit, it means vacation mode is on. Or, some app that could display statuses like that that I could update via webhook calls.
If you configure the telegram node correctly you should get a message lastes one minute after your global variable is <0°C. This is only a simple example
OK you will get a message every minute, with this simple flow so I would use a function node reading the global variable, comparing it with a stored value in the node context and trigger a message if the two values differ and store the new value in the node context for next trigger.
Not tested code for a simple function node:
var lastReading=node.get("lastReading") || 0;
var currentReading=global.get("variableName"); // insert your variable here
if (lastReading!=currentReading) {
msg.payload="New state of variableName="+currentReading; // or any message you like to send
node.set("lastReading",currentReading);
return msg;
}
This is not working for objects only for boolean, number and text.
trigger a led depends on the hardware you are planning to use (raspberry, arduino, ESP8266 ....)
OK, then my confusion (I believe) is perhaps regarding an assumption. Such as, an assumption that I know how LEDs work? Thinking back to a year or so ago, when I first got my Pi, I did write and run a sample LED python program to give my breadboard a whirl. So... what is telegram sender sending messages to? A gpio pin? Some LED array device? Perhaps you should start from the beginning...
You can find a lot of instructables how to connect them to a raspberry but perhaps you like to have them on a remote location then I would use a esp8266 microcontroller. The wemos d1 mini is cheap and easy to use.
3 patch (5v, ground and data) wires and a usb charger and the hardware is done. The raspberry is perhaps not the best choice because the serial timing of these leds and the one wire protocol is tricky for a multi tasking computer.
Install a universal firmware (my favorite is ESPEasy with the homie mqtt protocol and the neopixel plugin) and you can control the rgb or rgbw value depending on the led chips of all leds individualy.
Or are you running on a Pi and just want to light LEDs attached to GPIO pins? In which case you can send a 1 or a 0 to the pin to drive the led directly.
Indeed - I've no idea what Telegram is doing here... If you use the inject to feed several change nodes - each set to move global.{your_variable} to msg.payload then feed a node-red-contrib-ui-led node for each... you should be able to configure the ui_led node to indicate a colour based on on and off etc...
The advantage of node-red is that, once you have a triggering flow set up, you can make it update lots of things. Including both an LED and Telegram.
So breaking this down, you need two parts.
Firstly a flow that monitors the state of the global variable and kicks out a message when the status changes.
Then secondly, one or more flows that take that message and update an LED and/or notify you on your phone via a bot connected to a messaging app (of which Telegram is about the easiest to work with).
Honestly, MQTT would still be the easiest way to deal with this. All you need to do is trigger an MQTT output each time you change the value of your global variable. Then you can have an mqtt-in (actually you could have several) that subscribes to the appropriate topic - that's the part 1 of your flow. You will get an output msg every time the variable changes.
To update an LED, grab any old LED, solder on a resistor to limit the current and wire it between a GPIO pin and ground on the Pi. Set the GPIO pin as an output and use the gpio node to set high or low accordingly.
Telegram is slightly more complex - not on the node-red side but simply on setting up your bot in the first place. There are plenty of tutorials for that. Then use a telegram send node.
You could also update a Dashboard of course and you could get creative and put an LED (or multiple RGB ones) onto an ESP8266. Configure the ESP to subscribe to the same MQTT topic and drive the LED(s) accordingly. All driven from the initial flows.
Great tutorial. I always use sk6812 rgbww chips. For all my pcbs they where happy with 3.3v on the data line. I donât think that a level shifter is needed but perhaps Iâm wrong for the ws2812. I would give it a try without because you canât do any harm. Either the signal is unreliable or everything is nice and simple. A few of month ago my pull request was merged so you can send hsv values to rgb or rgbw neopixel to adress the full color spectrum and features even with the limitations before due to only 5 parameters per command. And have a human readable format too.