Countdown timer with Home Assistant counter

Frosenlind.se - Countdown

This countdown timer updates a Home Assistant counter of your choice to visualize time left on a trigger node.

Configuration

Counter Entity ID

Full entity ID of counter to use as timer, eg. counter.my_counter

Counter

Counter time


Input

Reset timer send msg.payload = reset to stop timer

Output

Output 1 sends an output every second.

  • msg.counter = the time set to the counter
  • msg.duration = time left on the timer
  • msg.entity = the counter entity ID

Output 2 send two outputs

  • sends msg.payload = timer_triggered when the timer starts
  • sends msg.payload = timer_finished when the timer is done

By sending a new message to the flow you "reset" the timer to the initial value, just like a normal trigger-node.

[{"id":"e998b419.ec6ec8","type":"subflow","name":"Frosenlind.se - Countdown","info":"# **Frosenlind.se - Countdown**\nThis countdown timer updates a Home Assistant counter of your choice to visualize time left on a trigger node.\n\nYou find more guides and flows at https://www.frosenlind.se\n---\n\n\n# **Configuration**\n\n## Counter Entity ID\n**Full entity ID** of counter to use as timer, eg. counter.my_counter\n\n## Counter\nCounter time\n\n---\n\n\n## Input\n**Reset timer**\nsend msg.payload = reset to stop timer\n\n## Output\nOutput 1 sends an output every second.\n - msg.counter = the time set to the counter\n - msg.duration = time left on the timer\n - msg.entity = the counter entity ID\n\nOutput 2 send two outputs\n - sends msg.payload = timer_triggered when the timer starts\n - sends msg.payload = timer_finished when the timer is done\n\n---\n\nBy sending a new message to the flow you \"reset\" the timer to the initial value, just like a normal trigger-node.\n\n\n\n","category":"","in":[{"x":80,"y":400,"wires":[{"id":"221b152.fba2eea"}]}],"out":[{"x":1760,"y":400,"wires":[{"id":"c70bce5f.ea726","port":0}]},{"x":1760,"y":500,"wires":[{"id":"466dd202.4c355c","port":0}]}],"env":[{"name":"entity","type":"str","value":"","ui":{"icon":"font-awesome/fa-id-card-o","label":{"en-US":"Counter Entity ID"},"type":"input","opts":{"types":["str","env"]}}},{"name":"counter","type":"str","value":"1800","ui":{"icon":"font-awesome/fa-clock-o","label":{"en-US":"Counter"},"type":"select","opts":{"opts":[{"l":{"en-US":"2 min"},"v":"120"},{"l":{"en-US":"5 minuter"},"v":"300"},{"l":{"en-US":"15 min"},"v":"900"},{"l":{"en-US":"30 min"},"v":"1800"},{"l":{"en-US":"1 hour"},"v":"3600"}]}}}],"color":"#C0DEED","icon":"font-awesome/fa-clock-o"},{"id":"d889e9b9.2ebd98","type":"trigger","z":"e998b419.ec6ec8","name":"heartbeat","op1":"count","op2":"fail","op1type":"str","op2type":"str","duration":"-1","extend":true,"overrideDelay":false,"units":"s","reset":"timer_finished","bytopic":"all","topic":"topic","outputs":1,"x":1260,"y":400,"wires":[["5397364e.bb3cd8"]],"outputLabels":["send \"fail\" if not feeded"]},{"id":"83c9e76e.220678","type":"change","z":"e998b419.ec6ec8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"},{"t":"set","p":"entity","pt":"msg","to":"entity","tot":"env"},{"t":"set","p":"counter","pt":"msg","to":"counter","tot":"env"},{"t":"set","p":"time","pt":"msg","to":"time","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":480,"wires":[["c6af92c4.fc3fb"]]},{"id":"5397364e.bb3cd8","type":"api-call-service","z":"e998b419.ec6ec8","name":"Count down","server":"b6162a50.c4af78","version":1,"debugenabled":false,"service_domain":"counter","service":"decrement","entityId":"{{entity}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1410,"y":400,"wires":[["c70bce5f.ea726"]]},{"id":"c6af92c4.fc3fb","type":"api-call-service","z":"e998b419.ec6ec8","name":"Configure counter","server":"b6162a50.c4af78","version":1,"debugenabled":false,"service_domain":"counter","service":"configure","entityId":"{{entity}}","data":"{\"initial\":{{counter}}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":550,"y":480,"wires":[["cfb19505.4df708"]]},{"id":"466dd202.4c355c","type":"trigger","z":"e998b419.ec6ec8","name":"delay","op1":"timer_triggered","op2":"timer_finished","op1type":"str","op2type":"str","duration":"2","extend":true,"overrideDelay":true,"units":"min","reset":"reset","bytopic":"all","topic":"topic","outputs":1,"x":1110,"y":400,"wires":[["d889e9b9.2ebd98"]]},{"id":"221b152.fba2eea","type":"switch","z":"e998b419.ec6ec8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"reset","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":190,"y":400,"wires":[["466dd202.4c355c","82e3965e.49e018"],["83c9e76e.220678"]]},{"id":"cfb19505.4df708","type":"api-call-service","z":"e998b419.ec6ec8","name":"Reset counter","server":"b6162a50.c4af78","version":1,"debugenabled":false,"service_domain":"counter","service":"reset","entityId":"{{entity}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":760,"y":480,"wires":[["d2dd100b.ab4d1"]]},{"id":"7cfc2413.18f83c","type":"api-call-service","z":"e998b419.ec6ec8","name":"Configure counter","server":"b6162a50.c4af78","version":1,"debugenabled":false,"service_domain":"counter","service":"configure","entityId":"{{entity}}","data":"{\"initial\":0}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":570,"y":300,"wires":[["d487010f.a5ed6"]]},{"id":"d487010f.a5ed6","type":"api-call-service","z":"e998b419.ec6ec8","name":"Reset counter","server":"b6162a50.c4af78","version":1,"debugenabled":false,"service_domain":"counter","service":"reset","entityId":"{{entity}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":780,"y":300,"wires":[[]]},{"id":"82e3965e.49e018","type":"change","z":"e998b419.ec6ec8","name":"","rules":[{"t":"set","p":"entity","pt":"msg","to":"entity","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":300,"wires":[["7cfc2413.18f83c"]]},{"id":"d2dd100b.ab4d1","type":"function","z":"e998b419.ec6ec8","name":"","func":"var delay_ms = msg.counter;\ndelay_ms = delay_ms * 1000;\n\n\n// make it part of the outgoing msg object\nmsg.delay = delay_ms;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":960,"y":480,"wires":[["466dd202.4c355c"]]},{"id":"a3c20f67.c0d34","type":"comment","z":"e998b419.ec6ec8","name":"If reset, set counter to 0 and reset.","info":"If reset, set counter to 0 and reset.\nThis is so the counter shows 0 seconds left.","x":420,"y":260,"wires":[]},{"id":"9922ca05.ef0d78","type":"comment","z":"e998b419.ec6ec8","name":"Set vaiabels and configure counter, then reset and make milliseconds.","info":"Set vaiabels and configure counter, then reset and make milliseconds.","x":510,"y":440,"wires":[]},{"id":"2ad2dbff.b24ac4","type":"comment","z":"e998b419.ec6ec8","name":"\"timer and heartbeat\"","info":"","x":1160,"y":360,"wires":[]},{"id":"c70bce5f.ea726","type":"api-current-state","z":"e998b419.ec6ec8","name":"","server":"b6162a50.c4af78","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"{{entity}}","state_type":"str","state_location":"duration","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":false,"x":1620,"y":400,"wires":[[]]},{"id":"b6162a50.c4af78","type":"server","name":"Home Assistant - New","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"1758f49f.b9c7bb","type":"subflow:e998b419.ec6ec8","z":"760faf65.70c2b","name":"","x":1170,"y":940,"wires":[[],[]]}]

Flow Info

Created 3 years, 3 months ago
Rating: 5 1

Owner

Actions

Rate:

Node Types

Core
  • change (x2)
  • comment (x3)
  • function (x1)
  • switch (x1)
  • trigger (x2)
Other

Tags

  • counter
  • homeassistant
  • timer
  • countdown
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option