Stuck on a Node-Red Flow for Coffee Maker - Input Numbers and Timers

Hey everybody, so I am wanting to use input_number(s) and timer(s) in a node-red flow, but I honestly have no idea how to do that.

What I am wanting to do: I created an Input Boolean for my coffee maker. When I turn this boolean on, I want the coffee pot to come on at a certain time set by Input Numbers. Once the coffee pot turns on, I want it to start a timer (I have a 30 minute coffee timer in my timers.yaml file), and then turn off the coffee pot once the timer is finished.

What I have so far:

  • input_boolean.coffee_pot
  • input_number.coffee_hour
  • input_number.coffee minutes
  • timer.coffee_timer

My flow so far:

Start Timer Node:

Timer is Finished Node:

Here is my yaml for everything:
Coffee Sensor Template

coffee_time:
  friendly_name: 'Coffee Time'
  icon: mdi:clock-outline
  value_template: '{{ "%0.02d:%0.02d" | format(states("input_slider.coffe_hour") | int, states("input_slider.coffee_minutes") | int) }}'

Input Numbers

coffee_hour:
  name: Hour
  icon: mdi:clock-outline
  initial: 6
  min: 0
  max: 23
  step: 1
  
coffee_minutes:
  name: Minutes
  icon: mdi:clock-outline
  initial: 30
  min: 0
  max: 59
  step: 5

Input Booleans

  coffee_pot:
    name: Coffee Pot Automation
    icon: mdi:coffee-maker

Coffee Timers:

coffee_pot:
  name: Time Remaining
  duration: 1800
1 Like

IGNORE THIS. I reckon I have found a better way below!

There might be a better way of doing it but off the top of my head I reckon you could combine the payloads of the input numbers (maybe make them msg.minute and msg.hour) and then send that off to a Big Timer node with a msg.payload of on_overide msg.minute:msg.hour using a function node.

So you have your on command.

Then once big timer sends its on command call the timer.start service and turn on your coffee maker.

either have a delay node for 30 minutes of read the timer.finished event from HA and make that turn the coffee maker off.

Might not be the best way to do it but its a start.

Just had a go at this and it wasn’t as easy as I thought. However, if you set up a sensor.time

and then make an input_datetime for your coffee maker then you can send that value to a wait until node in home assistant which is watching the sensor.time.

So you flick the coffee maker boolean on, it sends the input_datetime.coffee_maker as a value to the wait until node.
When sensor.time and input_datetime.coffee_maker match then it will turn on the coffee maker and start the timer.
When the timer.finished event happens then it will turn off the coffee maker.

[{"id":"990c8728.f4a848","type":"inject","z":"ffbd7f06.4a014","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":848,"wires":[["66c0e770.63f008"]]},{"id":"66c0e770.63f008","type":"function","z":"ffbd7f06.4a014","name":"Right time?","func":"const haStates = global.get(\"homeassistant\").homeAssistant.states;\nconst hour = Number(haStates[\"input_number.coffee_hour\"].state);\nconst minute = Number(haStates[\"input_number.coffee_minutes\"].state);\nconst active = haStates[\"input_number.coffee_pot\"].state === \"off\";\nconst d = new Date();\n\nnode.warn(active);\nif(active && d.getHours() === hour && d.getMinutes() === minute) {\n    return msg;    \n}\n\n","outputs":1,"noerr":0,"x":326,"y":848,"wires":[["920dac3a.72a31"]]},{"id":"920dac3a.72a31","type":"api-call-service","z":"ffbd7f06.4a014","name":"Turn On Coffee Pot","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.coffee_pot","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":506,"y":848,"wires":[["15de3db3.e49442"]]},{"id":"4f406330.b3da2c","type":"api-call-service","z":"ffbd7f06.4a014","name":"Turn Off Coffee Pot","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.coffee_pot","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":874,"y":848,"wires":[[]]},{"id":"15de3db3.e49442","type":"delay","z":"ffbd7f06.4a014","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":694,"y":848,"wires":[["4f406330.b3da2c"]]}]

This is almost perfect! Do you happen to know how to replace the 30 minute delay node with my yaml timer that I have set up? This reason for this is so I can see how much time is left before the coffee pot will turn off.

[{"id":"ec7dc29e.f0854","type":"inject","z":"ffbd7f06.4a014","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"onceDelay":0.1,"x":198,"y":1088,"wires":[["cfe4e11c.05a4e"]]},{"id":"cfe4e11c.05a4e","type":"function","z":"ffbd7f06.4a014","name":"Right time?","func":"const haStates = global.get(\"homeassistant\").homeAssistant.states;\nconst hour = Number(haStates[\"input_number.coffee_hour\"].state);\nconst minute = Number(haStates[\"input_number.coffee_minutes\"].state);\nconst active = haStates[\"input_number.coffee_pot\"].state === \"off\";\nconst d = new Date();\n\nnode.warn(active);\nif(active && d.getHours() === hour && d.getMinutes() === minute) {\n    return msg;    \n}\n\n","outputs":1,"noerr":0,"x":406,"y":1088,"wires":[["f1cd35a4.b64278"]]},{"id":"f1cd35a4.b64278","type":"api-call-service","z":"ffbd7f06.4a014","name":"Turn On Coffee Pot","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.coffee_pot","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":602,"y":1088,"wires":[["ce59f918.bbb7b8"]]},{"id":"ce764be0.f08a98","type":"api-call-service","z":"ffbd7f06.4a014","name":"Turn Off Coffee Pot","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.coffee_pot","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":602,"y":1136,"wires":[[]]},{"id":"c72ec5f1.6419e8","type":"server-events","z":"ffbd7f06.4a014","name":"Timer Finished","event_type":"timer.finished","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":208,"y":1136,"wires":[["79000065.5e93c"]]},{"id":"85321519.500d08","type":"server-events","z":"ffbd7f06.4a014","name":"Timer Cancelled","event_type":"timer.cancelled","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":208,"y":1184,"wires":[["79000065.5e93c"]]},{"id":"ce59f918.bbb7b8","type":"api-call-service","z":"ffbd7f06.4a014","name":"Start Timer","version":1,"debugenabled":false,"service_domain":"timer","service":"start","entityId":"timer.coffee_pot","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":806,"y":1088,"wires":[["91b3104e.43b1f"]]},{"id":"79000065.5e93c","type":"switch","z":"ffbd7f06.4a014","name":"","property":"payload.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"timer.coffee_pot","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":386,"y":1136,"wires":[["ce764be0.f08a98"]]},{"id":"91b3104e.43b1f","type":"ha-wait-until","z":"ffbd7f06.4a014","name":"Safety Switch","outputs":2,"entityId":"switch.coffee_pot","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"1","timeoutUnits":"hours","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":1024,"y":1088,"wires":[[],["ce764be0.f08a98"]]}]

Thank you so much for your help! It is almost perfect, however, for whatever reason, the switch stays on? Regardless of time or input_boolean status. Even when I turn it off, it just comes right back on. Have any idea why? I wish I had more of an understanding about functions nodes so I dont have to bother you.

You sure it’s this flow that’s turning the coffee pot back on? Try dropping a debug node after the function node and see if it’s outputting more than once.

I see the error in the function node.
Change
const active = haStates["input_number.coffee_pot"].state === "off";
to
const active = haStates["input_boolean.coffee_pot"].state === "on";

Here’s a version that doesn’t use a function node if it’s easier to follow for you.

[{"id":"1a1b0bb2.371cd4","type":"api-call-service","z":"d2b1e400.0eb0f","name":"Turn On Coffee Pot","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.coffee_pot","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":570,"y":96,"wires":[["790a1052.429e9"]]},{"id":"3205e12d.350fae","type":"api-call-service","z":"d2b1e400.0eb0f","name":"Turn Off Coffee Pot","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.coffee_pot","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":570,"y":144,"wires":[[]]},{"id":"33357437.23dfdc","type":"server-events","z":"d2b1e400.0eb0f","name":"Timer Finished","event_type":"timer.finished","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":176,"y":144,"wires":[["ae0d016c.1cfb2"]]},{"id":"62e298c8.4137f8","type":"server-events","z":"d2b1e400.0eb0f","name":"Timer Cancelled","event_type":"timer.cancelled","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":176,"y":96,"wires":[["ae0d016c.1cfb2"]]},{"id":"790a1052.429e9","type":"api-call-service","z":"d2b1e400.0eb0f","name":"Start Timer","version":1,"debugenabled":false,"service_domain":"timer","service":"start","entityId":"timer.coffee_pot","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":774,"y":96,"wires":[["e32aee68.77ff"]]},{"id":"ae0d016c.1cfb2","type":"switch","z":"d2b1e400.0eb0f","name":"","property":"payload.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"timer.coffee_pot","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":354,"y":144,"wires":[["3205e12d.350fae"]]},{"id":"e32aee68.77ff","type":"ha-wait-until","z":"d2b1e400.0eb0f","name":"Safety Switch","outputs":2,"entityId":"switch.coffee_pot","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"1","timeoutUnits":"hours","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":992,"y":96,"wires":[[],["3205e12d.350fae"]]},{"id":"1c5345c4.3fa49a","type":"moment","z":"d2b1e400.0eb0f","name":"set hours","topic":"","input":"","inputType":"msg","inTz":"America/Los_Angeles","adjAmount":0,"adjType":"days","adjDir":"add","format":"H","locale":"en_US","output":"hours","outputType":"msg","outTz":"America/Los_Angeles","x":316,"y":48,"wires":[["30a95665.2bcf2a"]]},{"id":"30a95665.2bcf2a","type":"moment","z":"d2b1e400.0eb0f","name":"set minutes","topic":"","input":"","inputType":"msg","inTz":"America/Los_Angeles","adjAmount":0,"adjType":"days","adjDir":"add","format":"m","locale":"en_US","output":"minutes","outputType":"msg","outTz":"America/Los_Angeles","x":470,"y":48,"wires":[["199302a3.5b654d"]]},{"id":"329548fe.7b4a58","type":"inject","z":"d2b1e400.0eb0f","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"onceDelay":0.1,"x":166,"y":48,"wires":[["1c5345c4.3fa49a"]]},{"id":"199302a3.5b654d","type":"api-current-state","z":"d2b1e400.0eb0f","name":"Check Hours","version":1,"outputs":2,"halt_if":"hours","halt_if_type":"msg","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.coffee_hour","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":630,"y":48,"wires":[["e0fa6173.89659"],[]]},{"id":"e0fa6173.89659","type":"api-current-state","z":"d2b1e400.0eb0f","name":"Check Minutes","version":1,"outputs":2,"halt_if":"minutes","halt_if_type":"msg","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.coffee_minutes","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":800,"y":48,"wires":[["22b2b9ab.03b6e6"],[]]},{"id":"22b2b9ab.03b6e6","type":"api-current-state","z":"d2b1e400.0eb0f","name":"Enabled?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.coffee_pot","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":956,"y":48,"wires":[["1a1b0bb2.371cd4"],[]]}]