Skip to content

Commit

Permalink
docs: Add another example flow in the cookbook (#504)
Browse files Browse the repository at this point in the history
* docs: Add another example flow in the cookbook

* Update docs/cookbook/using-date-and-time-entities-to-trigger-flows.md

Co-authored-by: Jason <37859597+zachowj@users.noreply.github.com>

Co-authored-by: Jason <37859597+zachowj@users.noreply.github.com>
  • Loading branch information
Edo78 and zachowj committed Oct 30, 2021
1 parent f6904c4 commit 76c5987
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions docs/cookbook/using-date-and-time-entities-to-trigger-flows.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ There is now a [time](../node/time.md) node that simplifies the example flows be

## Home Assistant Companion app next alarm sensor

::: warning
Home Assistant Companion app sets the entity's name based on its selected language. Eg. `next_alarm` must be changed in `prossimo_allarme` if the app is used in Italian (and vice versa)
:::

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)
Expand All @@ -40,6 +44,18 @@ If the [Node-RED custom component](https://github.com/zachowj/hass-node-red) is
Delay nodes can have a max timeout of around 24.8 days greater than that and weird things will happen.
:::

### Managing alarm from multiple phones

If more than on phone in the house has the app installed and you want to be triggered by all of them alarms this is the way to go and is't working perfectly even with just one phone.

It needs the same couple of helper for each phone and the same consideration made above for the `input_boolen` is still valid.

This flow was developed and tested with a Pixel 2 XL and the companion app in Italian so you have to change all the references to the phone and to the entities.

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

<<< @/examples/cookbook/using-date-and-time-entities-to-trigger-flows/example1c.json

## Daily alarm using Datetime Entity

![screenshot](./images/using-date-and-time-entities-to-trigger-flows_03.png)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":"c68594981cf4df93","type":"server-state-changed","z":"e1f44cc40f36d3a0","name":"Update Alarm","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"_prossimo_allarme_offset, _prossimo_allarme_enabled, _prossimo_allarme","entityidfiltertype":"substring","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":130,"y":1000,"wires":[["bd2261de4c7422c2"]]},{"id":"bd2261de4c7422c2","type":"function","z":"e1f44cc40f36d3a0","name":"Save values","func":"const [, phone] = msg.topic.match(/\\.(.+)_prossimo_allarme/);\nconst key = `alarm['${phone}']`;\nconst fullKey = `alarm['${phone}']['${msg.topic}']`\nflow.set(fullKey, msg.payload);\nconst alarmPhone = flow.get(key);\nif (Object.keys(alarmPhone).length === 3) {\n const alarmRaw = alarmPhone[`sensor.${phone}_prossimo_allarme`];\n const enabled = alarmPhone[`input_boolean.${phone}_prossimo_allarme_enabled`] === 'on';\n if ( enabled && alarmRaw !== \"unavailable\") {\n const now = Date.now();\n const alarm = new Date(alarmRaw);\n const offset = alarmPhone[`input_number.${phone}_prossimo_allarme_offset`] * 60000;\n const timeDifference = alarm.getTime() + offset;\n const delay = timeDifference - now;\n\n if (delay < 0) {\n node.status({ fill: 'red', text: 'Offset put alarm in the past' });\n node.warn(\"Offset put alarm in the past.\");\n return { reset: true };\n }\n\n node.status({});\n msg = {\n topic: phone,\n delay,\n payload: alarm\n };\n\n // Reset the delay node before setting the new delay\n return [[{ reset: true }, msg]];\n } else {\n return { reset: true };\n }\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":1000,"wires":[["31a1b9a97061185e"]]},{"id":"31a1b9a97061185e","type":"delay","z":"e1f44cc40f36d3a0","name":"wait until time","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":520,"y":1000,"wires":[["35675e2e29e54de6"]]},{"id":"764b91777c83fd57","type":"debug","z":"e1f44cc40f36d3a0","name":"do stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":320,"y":1080,"wires":[]},{"id":"35675e2e29e54de6","type":"switch","z":"e1f44cc40f36d3a0","name":"Phone","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"pixel_2_xl","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":690,"y":1000,"wires":[["b2992c1a93db3836"]]},{"id":"b2992c1a93db3836","type":"link out","z":"e1f44cc40f36d3a0","name":"Pixel 2 XL","mode":"link","links":["2a280002119b6339"],"x":795,"y":1000,"wires":[]},{"id":"2a280002119b6339","type":"link in","z":"e1f44cc40f36d3a0","name":"Alarm Pixel 2 XL","links":["b2992c1a93db3836"],"x":175,"y":1080,"wires":[["764b91777c83fd57"]]}]

0 comments on commit 76c5987

Please sign in to comment.