Skip to content

Commit

Permalink
docs: Add another example to using datetime entities to trigger flows
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Aug 18, 2020
1 parent 2b5f228 commit e6ca74e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 15 additions & 3 deletions docs/cookbook/using-date-and-time-entities-to-trigger-flows.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# 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.

![screenshot](./images/using-date-and-time-entities-to-trigger-flows_01.png)

<<< @/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)

Expand All @@ -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.
Original file line number Diff line number Diff line change
@@ -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"],[]]}]

0 comments on commit e6ca74e

Please sign in to comment.