Skip to content

Instantly share code, notes, and snippets.

@DoubtfulTurnip
Last active February 12, 2023 03:23
Show Gist options
  • Save DoubtfulTurnip/4953d814e57326515f610848d885efe9 to your computer and use it in GitHub Desktop.
Save DoubtfulTurnip/4953d814e57326515f610848d885efe9 to your computer and use it in GitHub Desktop.
A Node-Red node export from Home Assistant that will send notifications whenever there is an earthquake over 4MMI. Uses the NZ Geonet Earthquake integration.
[{"id":"9f7c7f5aa64abe9c","type":"server-state-changed","z":"34eed97721e5c14c","name":"","server":"32589209.0c3ffe","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"geo_location.*","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"0","halt_if_type":"str","halt_if_compare":"is_not","outputs":2,"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":"payload","propertyType":"msg","value":"","valueType":"eventData"}],"x":190,"y":120,"wires":[["fbfc98cb9e3b4dee"],[]]},{"id":"6506c4e17c55df7f","type":"function","z":"34eed97721e5c14c","name":"Create message","func":"var region = msg.payload.new_state.attributes.locality;\nvar mmi = msg.payload.new_state.attributes.mmi;\nvar magnitude = msg.payload.new_state.attributes.magnitude;\nvar depth = msg.payload.new_state.attributes.depth;\nvar time = msg.payload.new_state.attributes.time;\nvar timeconv = new Date(time);\nmsg.payload = \"A earthquake with an MMI of \" + mmi + \" has been dectected in a location \" + region + \"\\n\\n\" + \"Magnitude: \" + magnitude + \"\\n\" + \"Depth: \" + depth + \"KM\" + \"\\n\" + \"This occured: \" + timeconv;\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":240,"wires":[["18e474ef8ae839d9"]]},{"id":"18e474ef8ae839d9","type":"switch","z":"34eed97721e5c14c","name":"Only mmi 4 and over","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"MMI of 4","vt":"str"},{"t":"cont","v":"MMI of 5","vt":"str"},{"t":"cont","v":"MMI of 6","vt":"str"},{"t":"cont","v":"MMI of 7","vt":"str"},{"t":"cont","v":"MMI of 8","vt":"str"},{"t":"cont","v":"MMI of 9","vt":"str"},{"t":"cont","v":"MMI of 10","vt":"str"}],"checkall":"true","repair":false,"outputs":7,"x":770,"y":240,"wires":[["10b0f4108f8d9228"],["10b0f4108f8d9228"],["10b0f4108f8d9228"],["10b0f4108f8d9228"],["10b0f4108f8d9228"],["10b0f4108f8d9228"],["10b0f4108f8d9228"]]},{"id":"fbfc98cb9e3b4dee","type":"string","z":"34eed97721e5c14c","name":"Trim Depth","methods":[{"name":"left","params":[{"type":"num","value":"4"}]}],"prop":"msg.payload.new_state.attributes.depth","propout":"msg.payload.new_state.attributes.depth","object":"msg","objectout":"msg","x":180,"y":200,"wires":[["fd0bd61f41dc93e7"]]},{"id":"fd0bd61f41dc93e7","type":"string","z":"34eed97721e5c14c","name":"Trim Magnitude","methods":[{"name":"left","params":[{"type":"num","value":"4"}]}],"prop":"payload.new_state.attributes.magnitude","propout":"payload.new_state.attributes.magnitude","object":"msg","objectout":"msg","x":190,"y":280,"wires":[["6506c4e17c55df7f"]]},{"id":"8541b79aaf50a380","type":"api-call-service","z":"34eed97721e5c14c","name":"Notify","server":"32589209.0c3ffe","version":5,"debugenabled":true,"domain":"notify","service":"notify","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\":msg.payload,\"title\":\"⚠️ ⚠️ Earthquake!⚠️ ⚠️\",\"data\":{\"notification_icon\": \"mdi:alert\"}}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1120,"y":240,"wires":[[]]},{"id":"10b0f4108f8d9228","type":"junction","z":"34eed97721e5c14c","x":950,"y":240,"wires":[["8541b79aaf50a380"]]},{"id":"32589209.0c3ffe","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment