Get notified when an earthquake takes place nearby

  • eGeoffrey is capable of handling a number of diverse information among those, positions on a map. Let's work on a earthquake use case today. As always, let's search the marketplace first:

    $ sudo egeoffrey-cli search earthquake
    egeoffrey-service-earthquake: Retrieve earthquake information

    Install the package:

    $ sudo egeoffrey-cli install egeoffrey-service-earthquake
    egeoffrey-service-earthquake:master installed successfully

    and start it:

    $ egeoffrey-cli start
    Pulling egeoffrey-service-earthquake (egeoffrey/egeoffrey-service-earthquake:master-amd64)...
    master-amd64: Pulling from egeoffrey/egeoffrey-service-earthquake
    bdf0201b3a05: Already exists
    782863018686: Already exists
    56c01527c728: Already exists
    63dd63c63810: Already exists
    ba2bf76730ce: Already exists
    dd9f70d76614: Already exists
    f58009fcf6d2: Already exists
    baa7b01968c0: Already exists
    eebefd015bd8: Pull complete
    Digest: sha256:f322688151336a2e083da3e35933aaebb2f681cbd6082b98fd88559ce787996c
    Status: Downloaded newer image for egeoffrey/egeoffrey-service-earthquake:master-amd64
    demo_egeoffrey-database_1 is up-to-date
    demo_egeoffrey-service-fcc_weather_1 is up-to-date
    demo_egeoffrey-controller_1 is up-to-date
    demo_egeoffrey-gateway_1 is up-to-date
    demo_egeoffrey-service-system_1 is up-to-date
    demo_egeoffrey-gui_1 is up-to-date
    Creating demo_egeoffrey-service-earthquake_1 ... done

    If we now connect back to eGeoffrey web interface, we notice a menu item called "Earthquake Service" under the section "Examples". If we click on it, we get a map with a "Ops something went wrong error message". This is because we need a Google Maps API key for making this map (and any other map in eGeofrey working fine.

    To do so, let's go to and get an API key. Once done, go back to eGeoffrey, go to "House" / "Settings" and under the "Web Interface" tab let's paste in the field "Map API Key" the API key and click on "Save". If you now go back to the "Earthquake Service" page, the map should load (if not, try refreshing the entire page).

    How does this map get populated? If you go in "House" / "Sensors" you will notice a new sensor created by the package upon installation which is polling periodically earthquake information from the service:

    Screenshot 2020-06-29 at 10.13.39.png

    In case the earthquake has magnitude more than 5, it will be displayed in the map:

    Screenshot 2020-06-29 at 10.15.59.png

    But how can we be alerted whenever a new earthquake took place? Let's create a brand new rule for this. Let's to to "House" / "Rules" and create a new rule.

    • In the "General" tab, give the rule an identifier of your choice, in the rule text write down the alert text using the placeholders from the variables defined later, set "alert" as severity, "realtime" as rule type (the rule will be evaluated as a new earthquake is stored in the sensor data store.
      Screenshot 2020-06-29 at 10.31.27.png

    • In the "Triggers" tab, add the sensor identifier the rule will monitor to trigger whenever a new value is set:
      Screenshot 2020-06-29 at 10.32.02.png

    • In the "Constants" tab set the threshold you want to set for the alert to trigger. E.g. even if the map is displaying any earthquake with a magnitude greater than 5, we want to be alerted with magnitude 7 or above:
      Screenshot 2020-06-29 at 10.32.54.png

    • In the "Variables" tab, we need to get from the sensor the information we need for then articulating our conditions and/or for our alert message. Specifically we need the magnitude of the latest earthquake, the distance from our house and the location where it took place. For this we are leveraging the special function DISTANCE, POSITION_LABEL and POSITION_TEXT which are extracting out of a location data type the required data:
      Screenshot 2020-06-29 at 10.34.06.png

    • In the "Conditions" tab, we add a single condition, e.g. when the magnitude of the earthquake is above the given threshold:
      Screenshot 2020-06-29 at 10.36.40.png

    If we want to be alerted if the earthquake only took place nearby our house, we can define a new constant called e.g. max_distance and then set an additional condition like distance < max_distance. Remember any distance is calculated from the location of your house set in "House" / "Settings".

Log in to reply