-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add another example flow in the cookbook (#504)
* 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
Showing
3 changed files
with
17 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+24.9 KB
docs/cookbook/images/using-date-and-time-entities-to-trigger-flows_04.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
examples/cookbook/using-date-and-time-entities-to-trigger-flows/example1c.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]]}] |