diff --git a/docs/cookbook/images/using-date-and-time-entities-to-trigger-flows_03.png b/docs/cookbook/images/using-date-and-time-entities-to-trigger-flows_03.png new file mode 100644 index 0000000000..808d2b141d Binary files /dev/null and b/docs/cookbook/images/using-date-and-time-entities-to-trigger-flows_03.png differ diff --git a/docs/cookbook/using-date-and-time-entities-to-trigger-flows.md b/docs/cookbook/using-date-and-time-entities-to-trigger-flows.md index af8361b568..8fe5f98a92 100644 --- a/docs/cookbook/using-date-and-time-entities-to-trigger-flows.md +++ b/docs/cookbook/using-date-and-time-entities-to-trigger-flows.md @@ -1,6 +1,6 @@ # Using Date and Time entities to trigger flows -## Using the Home Assistant Companion app next alarm sensor +## Home Assistant Companion app next alarm sensor Here's a basic example of using the Home Assistant Companion app next alarm sensor. @@ -8,9 +8,13 @@ Here's a basic example of using the Home Assistant Companion app next alarm sens <<< @/examples/cookbook/using-date-and-time-entities-to-trigger-flows/example1a.json -### Adding an offset and togglable on and off switch +### Adding an offset and on/off switch -Using the Helpers section under configuration in Home Assistant add an `input_number` and `input_boolean`. In this example they are `input_number.offset` and `input_boolean.next_alarm_enabled`. The offset will be plus or minus minutes to the alarm. The delay node will get updated when either the alarm sensor gets updated, the input boolean gets toggled, or the offset changes. +Using the Helpers section under Configuration in Home Assistant add an `input_boolean` and `input_number` with a min of `-90` and a max of `90`. + +In this example they are `input_number.offset` and `input_boolean.next_alarm_enabled`. The offset will be plus or minus minutes to the alarm. The delay node will get updated when either the alarm sensor gets updated, the input boolean gets toggled, or the offset changes. + +If the [Node-RED custom component](https://github.com/zachowj/hass-node-red) is installed in Home Assistant there is no need for the `input_boolean` as the event state node can be exposed to Home Assistant as the toggle switch. ![screenshot](./images/using-date-and-time-entities-to-trigger-flows_02.png) @@ -19,3 +23,11 @@ Using the Helpers section under configuration in Home Assistant add an `input_nu ::: warning Delay nodes can have a max timeout of around 24.8 days greater than that and weird things will happen. ::: + +## Daily alarm using Datetime Entity + +![screenshot](./images/using-date-and-time-entities-to-trigger-flows_03.png) + +<<< @/examples/cookbook/using-date-and-time-entities-to-trigger-flows/example2.json + +An offset can also be added as shown in the next alarm sensor example. diff --git a/examples/cookbook/using-date-and-time-entities-to-trigger-flows/example2.json b/examples/cookbook/using-date-and-time-entities-to-trigger-flows/example2.json new file mode 100644 index 0000000000..dae8a647a4 --- /dev/null +++ b/examples/cookbook/using-date-and-time-entities-to-trigger-flows/example2.json @@ -0,0 +1 @@ +[{"id":"2672831b.1236ac","type":"inject","z":"56b1c979.b2c618","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":326,"y":1744,"wires":[["ef533324.d135d"]]},{"id":"8b6ea5bc.5f2478","type":"api-current-state","z":"56b1c979.b2c618","name":"alarm","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_datetime.alarm","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":false,"x":612,"y":1744,"wires":[["aedf33ed.0ca28"]]},{"id":"d3ec7afe.0c2968","type":"debug","z":"56b1c979.b2c618","name":"do stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":894,"y":1744,"wires":[]},{"id":"aedf33ed.0ca28","type":"function","z":"56b1c979.b2c618","name":"now?","func":"const now = new Date();\nconst hours = now.getHours();\nconst minutes = now.getMinutes().toString().padStart(2,'0');\nconst time = `${hours}:${minutes}`;\n// Remove seconds\nconst alarm = msg.payload.split(\":\").splice(0,2).join(\":\");\n\nif(time === alarm) {\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":1744,"wires":[["d3ec7afe.0c2968"]]},{"id":"ef533324.d135d","type":"api-current-state","z":"56b1c979.b2c618","name":"enabled?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.alarm_enabled","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":476,"y":1744,"wires":[["8b6ea5bc.5f2478"],[]]}]