Time for Bed MotherF*****s! Automate your bedtime routine with Node-Red & Home-Assistant

Bedtime Node-red flow

Today I want to run you through our bedroom routine using node-red and home-assistant. After reading this post you should be able to create your own routines quickly and easily.

My girlfriend and I live together and like all couples we kind of have a routine that rarely changes, so I set about automating this part of our lifestyle to make things quick and easy. We use a voice assistant and whilst I can set this up on google home via webhooks and IFTTT, I prefer to use Alexa as it’s easy to create an entity and manipulate this in node-red. I’ll quickly describe the routine and then I’ll show you the flow and how it’s broken down (including the code).

Bedtime:

We have a projector connected to an Nvidia Shield which we use as our media source. On the shield we have Plex, Emby, Netflix, Amazon, Iplayer, Google Videos as well as a host of other video apps which serve up our content. When it’s time for bed, we shout to Alexa to “turn on bedtime.” As sexy as this sounds, Alexa proceeds do the following:

Turns off the projector

Send the Nvidia shield to sleep

Turns on the lounge lamp for 5mins

Turns on underbed lighting for 30mins

Turns on the Bedside lights for 10mins

Turns on the bedroom Humidifier for 20mins on full power before switching it to nightmode.

oh and for good measure, we have Google Home “Announce time for bed you mother&^%$£$!s”  (a personal favourite of mine)

 

Now it sounds super regimented, but this just works. If at any time we want one of the lights to stay on for any longer, we just ask Alexa to turn the light on separately, freeing it from it’s routine but allowing us the freedom to switch it off when we want. Most of the time we end up just leaving it as standard. The bedside lights are probably the thing we delay the most, but we specifically kept them on a shorter time frame to try and force us to put away our ipads before bed!

The flow in Node-red looks like this:

Bedtime Node-red flow
Bedtime Node-red flow

As you can see it’s a relatively simple flow, consisting of mainly Home-Assistant service calls, some delay nodes, a switch node to keep everything neat, and a function node to send a power off command to our projector.

I set up the bedtime node via the Alexa bridge which you can read more about here in the second half of this post. Alexa is able to switch the node on or off. At present I have only set the switch mode to output ON. We don’t really have a need to for a morning routine yet, but potentially we could ask Alexa to turn off the bedtime node and then I could easily add an OFF output to the (yellow) bedroom switch node and continue the flow from there.

So proceeding from top to bottom, the function node at the top sends the following command to my projector via a broadlink RM Mini 3.

The actual code I am sending is specific to an Epson TW6100W projector and you can read more  about how I send info via broadlink here

This is what the function code looks like with the corresponding format:

Broadlink Function Node

Broadlink Function Node 

The next line down is a simple Lamp switch on. This command enters via Home-Assistant. An example of the code is here:

Home-Assistant Lamp Turn ON Command
Home-Assistant Lamp Turn ON Command

 

This then goes into a timer before essentially switching the lamp back off. On all the timers there are several options. What to do at the end of the timer is always the top output.

Here’s an example of the 30 minute timer:

30 Second Timer Node
30 Second Timer Node

 

Below is how I put the Nvidia Shield to sleep. You can read more about full control of that here.

Nvidia Shield Sleep Command
Nvidia Shield Sleep Command

 

I’ve already shown you how to switch something on via Home-Assistant. I’ve attached for good measure how I switched the humidifier over to Night Mode via an input_boolean. You can read about this in more detail here.

night mode on input_boolean
night mode on input_boolean

 

Last but not least, the “piece de resistance” – the google announcement. I know am mixing Alexa with Google here, but firing off Google TTS commands in Home-Assistant is so easy, I couldn’t help myself. At some point I will randomise the list of abusive phrases she can holler at us, but for now, this simple but cheerful phrase makes us smile 🙂

Google TTS Bedtime
Google TTS Bedtime

 

That in essence is how we set up our bedtime routine. You can see that the coding is not particularly difficult. Should we wish to add or turn off another lamp or object in the home it would literally be a case of just copying and pasting a couple of the nodes and joining the dots. Coming from other platforms where I’ve had to use coding, or IFTTT and all the issues that come with the latency, I am so happy I found Node-red.

I also want to point out that the majority of these commands in the flow are going via Home-Assistant. Should I not want to use home-asssitant I could cut it out completely. I would be able to send commands directly to all the smart plugs via MQTT (this is a huge benefit and one of the biggest reasons for flashing cheap tuya sockets with Tasmota or Esphome. I know Shelly is offering MQTT out of the box which is brilliant). The projector isn’t using home-assistant in this flow, although I could do if I wanted (it’s set up in there). The Alexa input doesn’t go via HA. The TTS can be done directly with Google Home in Node-red if need be. I just find it easier to use HA in this instance. It’s important for me to have backup options. Should I fall out of love with Home-Assistant and want to move to something else (Hubitat, Homeseer, Smartthings etc), I should be able to move my flows and my automations with me.

Let me know in the comments if there’s anything else you’d like to know or if you have any questions.

Cheers.

 

Comments

Leave a Reply