How to make a configurable time and day scheduler in Home-Assistant with Node-Red

·

·

Have you ever wanted to make a scheduler for something in your Home-Assistant interface? I wanted to make one for my robot vacuum, so I found a way to do it.
I will present two ways of doing this: Method 1 includes one “time” and 7 “day” entities, method 2 includes 7 “days” and a time for each “day”. I am using a modified version of Method 1 myself, but I clearly see the value of method 2 in some cases so I made it for this guide.
No custom integrations is used in this guide, but basic Node-Red knowledge is required.

Before starting the guides, here are some information which can be useful to include for both methods:

How to Create a input_datetime time-sensor:

  • Go to Settings -> Devices & Services -> Helpers
  • Click “+ CREATE HELPER”
  • Select “Date and/or time”
  • Write a name in the “Name” field and select “Time” under “What do you want to input:”
  • Click “CREATE”

How to Create a input_boolean switch:

  • Go to Settings -> Devices & Services -> Helpers
  • Click “+ CREATE HELPER”
  • Select “Toggle”
  • Write a name in the “Name” field
  • Click “CREATE”

How to Create the Day of Week node in Node-Red:

  • The “Day of Week” node is a “Render template” node filled with the following template:
{{ ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'][now().weekday()] }}

Can also be imported using this JSON code:

[{"id":"5e973809664a2669","type":"api-render-template","z":"8cae7cb9a2c3ae36","name":"Day of Week","server":"19e1c0e4.b3625f","version":0,"template":"{{ ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'][now().weekday()] }}","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":710,"y":960,"wires":[[]]},{"id":"19e1c0e4.b3625f","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Method 1: “7 days, same time”

First create the following helpers in Home-Assistant:
input_boolean:

  • input_boolean.vacuum_schedule_monday
  • input_boolean.vacuum_schedule_tuesday
  • input_boolean.vacuum_schedule_wednesday
  • input_boolean.vacuum_schedule_thursday
  • input_boolean.vacuum_schedule_friday
  • input_boolean.vacuum_schedule_saturday
  • input_boolean.vacuum_schedule_sunday

input_datetime:

  • input_datetime.vacuum_schedule

Re-Create the Node-Red flow:

From the left:

  • A “time” mode with the entity input_datetime.vacuum_schedule, this will trigger the flow.
  • The “Day of Week” node described before
  • A Switch node containing the following value rules:
    == (string) Monday
    == (string) Tuesday
    == (string) Wednesday
    == (string) Thursday
    == (string) Friday
    == (string) Saturday
    == (string) Sunday
    This one will pass the payload just out the correct channel (day)
  • 7 “current state” nodes with entity input_boolean.vacuum_schedule_<day> and “If state” has the following rule:
    is (string) on. This one will only pass the payload if the day is checked.
  • A “call service” node that is calling the services that is going to start (in this case, a robot vacuum)

If you want to import it I have pasted the JSON code here: https://pastebin.com/fHVRmzPU

Re-Create the Home-Assistant card:

The code blow is a entities card including each day’s input_boolean and the input_datetime.

type: entities
title: Robot Vacuum Schedule
entities:
  - entity: input_boolean.vacuum_schedule_monday
    name: Monday
  - entity: input_boolean.vacuum_schedule_tuesday
    name: Tuesday
  - entity: input_boolean.vacuum_schedule_wednesday
    name: Wednesday
  - entity: input_boolean.vacuum_schedule_thursday
    name: Thursday
  - entity: input_boolean.vacuum_schedule_friday
    name: Friday
  - entity: input_boolean.vacuum_schedule_saturday
    name: Saturday
  - entity: input_boolean.vacuum_schedule_sunday
    name: Sunday
  - entity: input_datetime.vacuum_schedule
    name: Time
show_header_toggle: false
state_color: false

Method 2: “7 days, individual time”

First create the following helpers in Home-Assistant:
input_boolean:

  • input_boolean.vacuum_schedule_monday
  • input_boolean.vacuum_schedule_tuesday
  • input_boolean.vacuum_schedule_wednesday
  • input_boolean.vacuum_schedule_thursday
  • input_boolean.vacuum_schedule_friday
  • input_boolean.vacuum_schedule_saturday
  • input_boolean.vacuum_schedule_sunday

input_datetime:

  • input_datetime.vacuum_schedule_monday
  • input_datetime.vacuum_schedule_tuesday
  • input_datetime.vacuum_schedule_wednesday
  • input_datetime.vacuum_schedule_thursday
  • input_datetime.vacuum_schedule_friday
  • input_datetime.vacuum_schedule_saturday
  • input_datetime.vacuum_schedule_sunday

Re-Create the Node-Red flow:

From the left:

  • 7 “time” nodes with the entity input_datetime.vacuum_schedule_<day>, all of these will trigger a flow.
  • 7 “current state” nodes with entity input_boolean.vacuum_schedule_<day> and “If state” has the following rule:
    is (string) on.
    This one will only pass the payload if the day is checked.
  • The “Day of Week” node described before.
  • A Switch node containing the following value rule:
    == (string) <day>
    Will pass the payload just if the day is today.
  • A “call service” node that is calling the services that is going to start (in this case, a robot vacuum)

If you want to import it I have pasted the JSON code here: https://pastebin.com/dN2iaVcW

Re-Create the Home-Assistant card:

The code blow is a vertical-stack where each day has a horizontal-stack containing both the input_boolean and input_datetime in there own entities card.

type: vertical-stack
title: Robot Valcuum Schedule
cards:
  - type: horizontal-stack
    cards:
      - type: entities
        entities:
          - entity: input_boolean.vacuum_schedule_monday
            icon: blanc
            name: Monday
      - type: entities
        entities:
          - entity: input_datetime.vacuum_schedule_monday
            icon: blanc
            name: Time
  - type: horizontal-stack
    cards:
      - type: entities
        entities:
          - entity: input_boolean.vacuum_schedule_tuesday
            icon: blanc
            name: Tuesday
      - type: entities
        entities:
          - entity: input_datetime.vacuum_schedule_tuesday
            icon: blanc
            name: Time
  - type: horizontal-stack
    cards:
      - type: entities
        entities:
          - entity: input_boolean.vacuum_schedule_wednesday
            icon: blanc
            name: Wednesday
      - type: entities
        entities:
          - entity: input_datetime.vacuum_schedule_wednesday
            icon: blanc
            name: Time
  - type: horizontal-stack
    cards:
      - type: entities
        entities:
          - entity: input_boolean.vacuum_schedule_thursday
            icon: blanc
            name: Thursday
      - type: entities
        entities:
          - entity: input_datetime.vacuum_schedule_thursday
            icon: blanc
            name: Time
  - type: horizontal-stack
    cards:
      - type: entities
        entities:
          - entity: input_boolean.vacuum_schedule_friday
            icon: blanc
            name: Friday
      - type: entities
        entities:
          - entity: input_datetime.vacuum_schedule_friday
            icon: blanc
            name: Time
  - type: horizontal-stack
    cards:
      - type: entities
        entities:
          - entity: input_boolean.vacuum_schedule_saturday
            icon: blanc
            name: Saturday
      - type: entities
        entities:
          - entity: input_datetime.vacuum_schedule_saturday
            icon: blanc
            name: Time
  - type: horizontal-stack
    cards:
      - type: entities
        entities:
          - entity: input_boolean.vacuum_schedule_sunday
            icon: blanc
            name: Sunday
      - type: entities
        entities:
          - entity: input_datetime.vacuum_schedule_sunday
            icon: blanc
            name: Time

Extra features (Method 1)

As mentioned in the start of this post I am using the first method, so I wanted to also include my “modification” to it.
Because I don’t always want to run the vacuum if I am home, even if it is scheduled i is set: I made a switch to cancel the operation under these circumstances.
if is including two “current state” nodes for input_boolean.vacuum_schedule_someone_home_condition and binary_sensor.someone_home (this one is not part of this guide, ut it is on it someone is home, off else).

If you want to import it I have pasted the JSON code here: https://pastebin.com/0SVHcDsu

Sources

Share