In this video I'm going to show you how to create some lighting effects in Node
Red, similar to Hue Labs. Make sure you stick around, and if you like what you
see hit subscribe below so you don't miss out on future videos!
Hi I'm Will from Will Surridge Tech, and in this video we're going to look at how we
can use node-red to replace some Hue Labs effects. We're going to talk about what
Hue Labs is, and then we'll pick out a few which we can recreate using node-red.
So let's get going! So what is Hue Labs? Well Hue Labs is a place where you can
do extra things with your Hue light bulbs - it's inside the Hue app and it was
designed by Philips to effectively beta test some features that they might want
to implement later down the line. Well I haven't really seen any of the formulas
implemented later down the line, that being said they might have done I might
have missed them! A formula is what they call an effect, or an automation, or
routine, or whatever you want to call it! If we head over to the Hue Labs website
we can see all the formulas available to choose. Some of these, you can see, require
motion sensors or switches to work. If we're recreating in node-red and using
Home Assistant we can use any switch or motion sensor irrelevant of the brand
which is a great little bonus. So let's have a look at some of these examples.
This is meditation breathing - where your breathing fades the lights, no it doesn't,
your lights fade to the breathing, no, you breathe as the lights fade! There we go!
We've got briefly bright, which is where it goes briefly bright and then returns
to the same scene afterwards. We've got sensing the weekend, where it'll choose a
different scene based on your button press if it's the weekend instead of it
being the week. As you can see some of these are going to be really easy to
recreate in node-red, and some of them are going to be more difficult but all
of them are possible! So let's try recreating that first one in node-red.
For all these examples I'm just going to trigger them using an inject node, but
you could also trigger them using a motion sensor, or switch a boolean, or whatever
you want depending on what you're trying to achieve with the effect. So this is
guided breathing. The point in it is that you breathe as the lights fade in, and
you breathe out as the lights fade out. It's a very simple one to recreate. For
this we're going to need an inject node to trigger it,
a couple of call service nodes, and a couple of delay nodes, and we're just
going to create a simple loop with them. So our first call service node, we're
going to set the light that we want, and then in the data we're going to set it
to be a full brightness, at colour of white, and with a transition of six
seconds. This means it will slowly fade along with your breathing. We're then
going to set the delay to be seven seconds. The delay will actually trigger
at the start of the transition and not after it's finished fading. We're then, in
the second call service node, we're going to drop the brightness right down and
we're going to change the colour slightly so it's got a bit more of a blue tint to
it. Again we have a delay of seven seconds which will start at the start of
the transition, and then we'll loop back to the beginning. And there we have a
slowly pulsing light. Next up we're going to try and recreate the briefly bright
scene. So this one is where you have a state on and then you suddenly want it
to go bright, and then return back to that original state after a period of
time. You might find this useful for your outside lighting if you have a nice
ambient set up outside for while you're inside, but then if you wanted to take
the bins out for example, you need you're going to need a bit more light so you
make the lights go bright, and then after a couple of minutes they dim back down
again back to what it was. So for this to work we're going to need an inject node
to trigger it (or whatever else you want to trigger it with), current state node, a
call service node. Then we're going to want a delay node, a function node, and a
call service node to return it. In our current state node we're going to grab
the information of our current lighting state from the light and save it in the
message data section. We then trigger the call service node which is going to make
our lights go bright and white. And then in a separate path we have a delay. I'm
just going to set this for five seconds for the purpose of this but obviously
once it's up and running you want to set it for a couple of minutes or so,
depending on what you're using it for. We then use the function node to extract
the data from the message data, and input it in the data section of the
message payload. This means that our final call service note will read that
data and input that into what it's going to call as the service, so it will
extract our brightness and our RGB colour value, and then it will input that into
our call service node, so we can read trigger that original light, and it'll go
back to the state that it was originally. You can expand this function as you see
fit - from just being one light to a whole number of lights, or even expand it
further and use it on a media player for example. For example if you wanted to,
I don't know, pause the music , announce a text-to-speech announcement and then
return to the music that was playing. Now the last routine I'm going to show you
today is going to be a little bit more complicated. We're going to create a
guided workout with our lights. So to do this we're going to need our inject node,
a small delay node (this is just so we can link back to one node rather than
having to link back to two), then we have a longer delay node, and then we can
start the workout section. So we're going to have a loop node, and then we can have
a function node to call the colour, a couple of call state nodes, and a couple
of delay nodes. In the loop node we set the max number of loops to the number of
times we want to repeat this exercise. Then in the function node we're going to
set the message payload to recall the colour that we want to be using. This
means that we only have to do it once and it'll apply to this whole section of
flow rather than having to do it repeatedly. We're then going to, in the
first call service node, change our light to full brightness and then I have a
couple of seconds delay, and then we're going to change our light to dim, and
have another couple of seconds delay. The point in this is for an exercise
such as a pushup where you go up when the light is bright and down when the
light is dim for example. Once that's repeated the max number of loops times
then it will move on to the second section or the second output from your
loop node. Here we're going to have a call service node to turn our light off
and add a ten-second delay. When the light is off we know we can
rest, so we're just going to our 10 second rest here before moving on to the
next exercise. We can copy all of this and paste it below, but this time we're
going to change the colour to blue - that means we know it's a new exercise. We
copy and paste again changing the colour to red, and that's our three exercises! So
at the end we want another turning the light off in a call service node, and
another ten-second delay. And then we're going to add a counter, and a switch. This
is going to tell us how many sets of these three exercises we're going to do.
If the counter is less than three, then it will go back to the start and repeat
the set. However when it gets more than three it'll jump off and do a separate
thing entirely. Now let's take this one step further - it's not really a guided
workout if we're not told what to do, so we're going to use the Alexa media
player to do a text-to-speech to tell us what exercise we're going to do. So we're
going to use the notify Alexa media player for the echo that we want to
display on, and then we're going to use the JSON which i've copied directly from
the github for the Alexa media player, and just replace the message with the
exercise. We copy and paste this for all three exercises and changing the message,
and then at the end for a well-done message to tell us that we're done. And
then for a bit of fun let's add some disco lights at the end. To do this we're
going to use the hue magic node, and use the strobo animation on a hue bulb.
We're also going to want to set a delay, and then change our payload to an input
boolean to false to stop that animation happening. Just so they flash for a
little bit and then go off. So that's three hue labs formulas recreated in
node red. I'll leave a link below to where you can find the full JSON for
all of the flows that I've created today. Obviously the flows I've made it have
been quite specific, but you can tweak them, and tweak the timings, tweak the
lights, tweak the settings to whatever you want - or you can just use it some
inspiration to create your own flows. It goes to show how easy and how versatile
node-red can be. Thank you to GrimRoper for the
idea. If anyone else has any ideas and videos
you'd like me to make, please let me know in the comments below or in a message on
my social media. And there we go - who needs the Hue app! Make sure you hit
subscribe and click the bell icon below to find out more about my smart tech, and
how you can build yourself the ultimate smart home!