Newbie: where to start, auto turn off after x time

Hi all,

I’ve finally taken the step and have setup HA and am slowly adding all the separated components I have to the system. Time to start with node-red!

Can somebody point me in the right direction, what approach should I choose for this:

We have an espresso machine, connected via a Sonoff (tasmota) switch so we can easily turn it on and of remotely (while still in bed!). In practice we often forget to turn the machine off, wasting a lot of electricity.

I would like to notify all the users after the machine has been on for a certain amount of time (2 hours?). Ideally this would be in the form of a question: “hey man, you left the coffee on! planning to get another cup, of can I shut it down? (you have 5 minutes to respond, else I am shutting it down!)”
If the users choose to keep the machine on, this routine should run again after x time.

  • What kind trigger can I use for this?
  • how do I find how long the machine has been in the ‘on’ state? Do I track with my own variables? Do I query the history of the switch?
  • how do I interact with my users? (please tell me there is an app for that…!)

I’ve not done anything with node-red before, but I’m a very experienced programmer and I did the youtube, so am confidant that I’ll understand the programming part.

Thank you for your time!!

Use the on state?

If you debug the state event, you’ll find lots of information, or you could keep it simple and just do a timer, then check state again.

You can use any method you want. I use Telegram (chatbot node red), to send information

The following automation will trigger when switch.coffee_maker is on for 2 hours. It then sends a notification via pushbullet (it assumes you are using the pushbullet component for notifications).

- alias: 'Coffee Maker Monitor'
    platform: state
    entity_id: switch.coffee_maker
    for: '02:00:00'
    service: notify.pushbullet
      title: "Coffee Maker left on."
      message: "Coffee maker left on for over 2 hours."

There’s another example here:

The OP is specifically asking about node red. Not yaml automations. :wink:

Oops! My mistake!

… yet so easily achieved with YAML. :slight_smile:

1 Like

I almost kept the super simple automations in yaml, but decided for cleanliness that it was going to be all or nothing. I love using node red for my automations. I have much more flexibility than what home assistant gives me.

Hi there!

thank you both for your comments!

I think I am suffering ignorance here (my own). I’m sure 2 days from now I won’t think twice about what you mean but:

Use the on state?
Which of all these funky node-red boxes (is block the correct term) do I drag to my flow? which is “the on state”? I have a test working based on a MQTT input block that tells me my machine switched on. but that is instant, not after an x amount of time

If you debug the state event
again, I’m trying to catch up, what do you refer to exactly when you say “state event”?

Interaction: I get telegram, but I’m never going to get my girlfriend on telegram, ‘she doesn’t need another chat app’ :wink: I think I saw something about a companion app? but guessing that’s not a very common solution. So, harnessing the communication tools of an existing chat system makes sense…

None of them are the “on state”. You use the event state node as a trigger. You point it to your switch in HA and when the switch in HA goes “on” you do something with the output.

Literally the event state node. You installed the home assistant node red websocket palette right?

What do you mean?

The chatbot node red palette will connect with nearly any messaging app out there.


Chatbot/RedBot available platforms

thank you! This is starting to make sense now.

I don’t have chatbot installed yet, but the state trigger and the date i get from it are clear!

You don’t have to use the trigger:state node. I use the EVENTS: STATE node.

You don’t have to do anything with that timestamp either. Just throw a timer after the event.

Ok, I thought I looked at that but was missing data (only current state, not how long, etc). but this way that won’t matter.

I app I was talking about is mentioned in this video at this point:
it’s called a companion app (see What ‘Rob’ does in the video is send an ‘actionable notification’. It’s some type of popup on IOS that has a button that will do something on HA. Cool, but if only IOS, than I’m out…

Thanks for all the input!

OK. You could have just said the iOS app. I know that app. You can do this in Node Red, using the ‘call service’ to send your message to the iOS app.

It is. If you are on Android, there are a host of other ways to do it. HTML5 notifications kind of work, you can use Ariela, etc. Personally I use Telegram. I have my wife and kid using Telegram and we use it for Home Assistant.

OK. You could have just said the iOS app. I know that app. You can do this in Node Red, using the ‘call service’ to send your message to the iOS app.

sorry :innocent:

I’ll look at the android options. The notion of having an immediate response button in your notification seems like a valuable addition: “Hey, do you want this? if so press this button and I will start doing things!”

There is nothing “official” at this time, so keep that in mind when looking. I think Ariela is the most up to date app there is. @Ionut puts out updates daily.

1 Like