Aks a 'is it bedtime?' question via push notification android

So, this flow is made so, when I walk up the stairs late in the evening, the sensor publishes to MQTT. This flow is triggered, checks if TV and lights are off, and then asks me on my Android phone if I'm going to bed via notification.

Mind you:This flow DOES NOT handle the 'callback' received when using the 'actionable notification'. Check out this flow: https://flows.nodered.org/flow/971995e2c21acfa5d1daaf62bf2d6774

[{"id":"c410a60f.be26f8","type":"subflow","name":"Notify Devices(s)","info":"stuur notification met filters op device","category":"","in":[{"x":60,"y":100,"wires":[{"id":"eec84c44.e05e4"}]}],"out":[],"inputLabels":["msg.data filled with JSON"],"icon":"node-red/comment.png"},{"id":"96608345.8c627","type":"api-call-service","z":"c410a60f.be26f8","name":"notify sam","server":"181266bf.748f49","service_domain":"notify","service":"android_pixel2","data":"","render_data":false,"mergecontext":"","output_location":"","output_location_type":"none","x":450,"y":40,"wires":[[]]},{"id":"4469ce76.7214b","type":"api-call-service","z":"c410a60f.be26f8","name":"notify Willeke","server":"181266bf.748f49","service_domain":"notify","service":"android_p10","data":"","render_data":false,"mergecontext":"","output_location":"","output_location_type":"none","x":450,"y":140,"wires":[[]]},{"id":"eec84c44.e05e4","type":"switch","z":"c410a60f.be26f8","name":"switch topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"P10","vt":"str"},{"t":"eq","v":"Pixel2","vt":"str"},{"t":"null"}],"checkall":"true","repair":false,"outputs":3,"x":230,"y":100,"wires":[["4469ce76.7214b"],["96608345.8c627"],["4469ce76.7214b","96608345.8c627"]]},{"id":"271afaed.88a9f6","type":"tab","label":"Trapsensor","disabled":false,"info":""},{"id":"7a4d528f.e841dc","type":"mqtt in","z":"271afaed.88a9f6","name":"TrapBeneden","topic":"home/0x00158d0002c65fa3","qos":"0","broker":"c128a9a5.055948","x":90,"y":60,"wires":[["c69d6f8.e07579"]]},{"id":"1d32fd86.c48e72","type":"switch","z":"271afaed.88a9f6","name":"occupancy?","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"\"occupancy\":true","vt":"str"},{"t":"cont","v":"\"occupancy\":false","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":250,"y":220,"wires":[["4819aed7.8f76a"],[]]},{"id":"4819aed7.8f76a","type":"api-current-state","z":"271afaed.88a9f6","name":"hanglamp state","server":"181266bf.748f49","halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"override_payload":true,"override_data":true,"entity_id":"light.color_hanglamp_tv","state_type":"habool","outputs":1,"x":380,"y":300,"wires":[["eacc2e11.322b5"]]},{"id":"eacc2e11.322b5","type":"switch","z":"271afaed.88a9f6","name":"lamp aan/uit?","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":220,"wires":[[],["d60472b8.e87cf"]]},{"id":"a96182b1.8170d","type":"switch","z":"271afaed.88a9f6","name":"is TV standby","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"standby","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":860,"y":220,"wires":[["36b79e74.2dba02"],[]]},{"id":"c69d6f8.e07579","type":"time-range-switch","z":"271afaed.88a9f6","name":"Savonds","lat":"","lon":"","startTime":"22:00","endTime":"02:00","startOffset":0,"endOffset":0,"x":200,"y":100,"wires":[["f6e7a04f.35bf5"],[]]},{"id":"f6e7a04f.35bf5","type":"json","z":"271afaed.88a9f6","name":"","property":"payload","action":"str","pretty":false,"x":270,"y":60,"wires":[["1d32fd86.c48e72"]]},{"id":"91046ec5.56ba4","type":"comment","z":"271afaed.88a9f6","name":"If moment on stairs and some devices are off","info":"","x":450,"y":160,"wires":[]},{"id":"36b79e74.2dba02","type":"function","z":"271afaed.88a9f6","name":"is BedtimeConfirmedDate recent?","func":"// outputs: 2\nvar keuzemoment = global.get('BedtimeConfirmedDate');\nvar keuze = new Date(keuzemoment).getTime();\nvar nuMinTienUur = new Date(\n        (new Date() - (10*60*60*1000))).getTime();\n\n// nog nooit gekozen\nif(keuzemoment === null)\n{\n   msg.payload = false;\n}\n//recente keuze gemaakt\nelse if (keuze >= nuMinTienUur)\n {\n   msg.payload = true;\n }\nelse\n {\n   msg.payload = false;\n }\n \n return msg;","outputs":2,"noerr":0,"x":980,"y":120,"wires":[["c5376aec.fdbf08"],[]]},{"id":"c5376aec.fdbf08","type":"change","z":"271afaed.88a9f6","name":"set topic Pixel2 en send bedtime question","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"data\":{\"title\":\"Bedtijd\",\"message\":\"Is het bedtijd?\",\"data\":{\"actions\":[{\"action\":\"ConfirmBedtime\",\"title\":\"Ja, bedtijd\"},{\"action\":\"RejectBedtime\",\"title\":\"Nee, geen bedtijd\"}]}}}","tot":"json"},{"t":"set","p":"topic","pt":"msg","to":"Pixel2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":160,"wires":[["6d6eb89c.2731b8"]]},{"id":"6d6eb89c.2731b8","type":"subflow:c410a60f.be26f8","z":"271afaed.88a9f6","name":"","x":1350,"y":200,"wires":[]},{"id":"d60472b8.e87cf","type":"bravia-api","z":"271afaed.88a9f6","tv":"7f8068a6.2e0648","method":"system:1.0:getPowerStatus","payload":"","name":"","x":680,"y":220,"wires":[["899df8b0.894648"]]},{"id":"899df8b0.894648","type":"json","z":"271afaed.88a9f6","name":"","property":"payload","action":"str","pretty":false,"x":770,"y":260,"wires":[["a96182b1.8170d"]]},{"id":"c128a9a5.055948","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"NodeRed","usetls":false,"compatmode":true,"keepalive":"60","cleansession":false,"birthTopic":"","birthQos":"2","birthRetain":"true","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"181266bf.748f49","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"},{"id":"7f8068a6.2e0648","type":"bravia-tv","z":"","name":"","host":"192.168.1.8","port":"80","psk":"0000"}]

Flow Info

Created 6 years, 9 months ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • change (x1)
  • comment (x1)
  • function (x1)
  • json (x2)
  • mqtt in (x1)
  • mqtt-broker (x1)
  • switch (x4)
Other

Tags

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