Skip to main content

Tells if, and how hard, it's raining at any location in Singapore

Project description

sgrain

Tells if it's currently raining at a given latitude and longitude in Singapore. The data comes from rain radar images at https://www.weather.gov.sg/weather-rain-area-50km/. The image are updated every 5 minutes.

Link to project: https://github.com/nlannuzel/sgrain

Package installation

From PyPI

pip3 install nlannuzel.sgrain

Package usage

With the built-in script:

rain-intensity-at -a 1.313383 -o 103.815203 -n

With a custom script:

#!/usr/bin/env python3

from nlannuzel.sgrain.rain import RainAreas
from nlannuzel.sgrain.geo import Location

rain = RainAreas()

# Download the latest radar image from https://www.weather.gov.sg/weather-rain-area-50km/
rain.load_image()

# https://maps.app.goo.gl/9aA7i8chryYwuhUT8
picnic_spot = Location(1.313383, 103.815203)

# Remove noise (isolated pixels that often exist in the raw image)
rain.remove_noise()

# Returns a number from 0 to 31
intensity = rain.intensity_at(picnic_spot)

message = f"At location {picnic_spot}, time {rain.rounded_dt}: "
if intensity == 0:
	message += "it's not raining."
elif intensity < 10:
	msg += "it's raining a little bit ({intensity}), bring a umbrella."
else:
	msg += "it's raining a lot ({intensity}), cancel the picnic."
print(message)

In home-assistant

Log into the home-assistant box, for example by connecting to the console of the VM where HA is installed and running. Then, attach the the homeasistant container:

docker exec -ti homeassistant bash

You are now inside the homeassistant container. Create a new venv under /config.

cd /config
python3 -m venv python_venv

Install this package inside the venv

cd python_venv
./bin/pip3 install nlannuzel.sgrain

Verify that the module works, this command should display between 0 and 31:

./bin/rain-intensity-at -a 1.313383 -o 103.815203 -p 1

Open the home-assistant GUI in a browser. If not already done, install the File Editor add-on. Open the configuration.yaml file (/homeassistant/configuration.yaml), and add a section like below:

command_line:
  sensor:
    command: /config/venv/bin/rain-intensity-at -a LATITUDE -o LONGITUDE -p 1 -n
    name: rain-sensor
    unique_id: rain
    scan_interval: 300
    icon: mdi:weather-pouring
    availability: 1
    #device_class: None
    state_class: MEASUREMENT
    value_template: '{{ value | float | round(2) }}'

Be sure to replace LATITUDE and LONGITUDE by the the actual coordinates. Finally, in the "developer tools", validate and then reload the config. You should have a new sensor available in Home Assistant.

Command line sensors are explained in HA website: https://www.home-assistant.io/integrations/command_line/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nlannuzel_sgrain-1.0.3.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nlannuzel_sgrain-1.0.3-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file nlannuzel_sgrain-1.0.3.tar.gz.

File metadata

  • Download URL: nlannuzel_sgrain-1.0.3.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for nlannuzel_sgrain-1.0.3.tar.gz
Algorithm Hash digest
SHA256 51b72380b114bf823b6c9e98aefb0d4fbbd00c8148c1b9adf37f29b022f46212
MD5 77d2751130ff3f03ab527e422ca3340b
BLAKE2b-256 84581acdc562195f87c3491b6e315efde89dc2c7813a4eb5a0a9d01044b372b4

See more details on using hashes here.

File details

Details for the file nlannuzel_sgrain-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for nlannuzel_sgrain-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1884c6f41849fbcd5f863bde5bc280fc36e1349bb618fd1084b2648f5d9e08e3
MD5 fe6cbe984363535a061900ac7792867c
BLAKE2b-256 d265f0d03b7481ad75810eac40db7ad4f161437de432bc79e159423419a2dc69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page