nlannuzel.sgrain


Namenlannuzel.sgrain JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryTells if, and how hard, it's raining at any location in Singapore
upload_time2025-10-14 09:14:38
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords weather rain radar singapore
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
```shell
pip3 install nlannuzel.sgrain
```

## Package usage
### With the built-in script:
```shell
rain-intensity-at -a 1.313383 -o 103.815203
```

### With a custom script:
```python
#!/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)

# 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](https://www.home-assistant.io/)
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:
```shell
docker exec -ti homeassistant bash
```

You are now inside the homeassistant container. Create a new venv under /config.
```shell
cd /config
python3 -m venv python_venv
```

Install this package inside the venv
```shell
cd python_venv
./bin/pip3 install nlannuzel.sgrain
```

Verify that the module works, this command should display between 0 and 31:
```shell
./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:
```yaml
command_line:
  sensor:
    command: /config/venv/bin/rain-intensity-at -a LATITUDE -o LONGITUDE -p 1
    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/

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "nlannuzel.sgrain",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "weather, rain, radar, singapore",
    "author": null,
    "author_email": "Nicolas Lannuzel <nlannuzel@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/57/3c/c3d9f99f2c2449c2cac2103725acd8a7f02de33daa671b48c03b920dca70/nlannuzel_sgrain-1.0.1.tar.gz",
    "platform": null,
    "description": "# sgrain\n\nTells if it's currently raining at a given latitude and longitude in\nSingapore. The data comes from rain radar images at\nhttps://www.weather.gov.sg/weather-rain-area-50km/. The image are\nupdated every 5 minutes.\n\n\n**Link to project:** https://github.com/nlannuzel/sgrain\n\n## Package installation\nFrom PyPI\n```shell\npip3 install nlannuzel.sgrain\n```\n\n## Package usage\n### With the built-in script:\n```shell\nrain-intensity-at -a 1.313383 -o 103.815203\n```\n\n### With a custom script:\n```python\n#!/usr/bin/env python3\n\nfrom nlannuzel.sgrain.rain import RainAreas\nfrom nlannuzel.sgrain.geo import Location\n\nrain = RainAreas()\n\n# Download the latest radar image from https://www.weather.gov.sg/weather-rain-area-50km/\nrain.load_image()\n\n# https://maps.app.goo.gl/9aA7i8chryYwuhUT8\npicnic_spot = Location(1.313383, 103.815203)\n\n# Returns a number from 0 to 31\nintensity = rain.intensity_at(picnic_spot)\n\nmessage = f\"At location {picnic_spot}, time {rain.rounded_dt}: \"\nif intensity == 0:\n\tmessage += \"it's not raining.\"\nelif intensity < 10:\n\tmsg += \"it's raining a little bit ({intensity}), bring a umbrella.\"\nelse:\n\tmsg += \"it's raining a lot ({intensity}), cancel the picnic.\"\nprint(message)\n```\n\n### In [home-assistant](https://www.home-assistant.io/)\nLog 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:\n```shell\ndocker exec -ti homeassistant bash\n```\n\nYou are now inside the homeassistant container. Create a new venv under /config.\n```shell\ncd /config\npython3 -m venv python_venv\n```\n\nInstall this package inside the venv\n```shell\ncd python_venv\n./bin/pip3 install nlannuzel.sgrain\n```\n\nVerify that the module works, this command should display between 0 and 31:\n```shell\n./bin/rain-intensity-at -a 1.313383 -o 103.815203 -p 1\n```\n\nOpen 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:\n```yaml\ncommand_line:\n  sensor:\n    command: /config/venv/bin/rain-intensity-at -a LATITUDE -o LONGITUDE -p 1\n    name: rain-sensor\n    unique_id: rain\n    scan_interval: 300\n    icon: mdi:weather-pouring\n    availability: 1\n    #device_class: None\n    state_class: MEASUREMENT\n    value_template: '{{ value | float | round(2) }}'\n```\nBe 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.\n\nCommand line sensors are explained in HA website: https://www.home-assistant.io/integrations/command_line/\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Tells if, and how hard, it's raining at any location in Singapore",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/nlannuzel/sgrain"
    },
    "split_keywords": [
        "weather",
        " rain",
        " radar",
        " singapore"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "27e766ce876139ca828a75613a7740befb65f949c48bcc83a52af72011be14d3",
                "md5": "236d8848e5945d51a73b20b146c26a40",
                "sha256": "9efa613816965f879b4449a48a4afc9568b65df7775fbf0b96478f1f83d50e2c"
            },
            "downloads": -1,
            "filename": "nlannuzel_sgrain-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "236d8848e5945d51a73b20b146c26a40",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 21706,
            "upload_time": "2025-10-14T09:14:36",
            "upload_time_iso_8601": "2025-10-14T09:14:36.342873Z",
            "url": "https://files.pythonhosted.org/packages/27/e7/66ce876139ca828a75613a7740befb65f949c48bcc83a52af72011be14d3/nlannuzel_sgrain-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "573cc3d9f99f2c2449c2cac2103725acd8a7f02de33daa671b48c03b920dca70",
                "md5": "a51f93356bd13f8287b20558e0ed590a",
                "sha256": "77e4034fdcb58146051f0cc4f8b4293161f6fda98d029e7fea8595b455198b1e"
            },
            "downloads": -1,
            "filename": "nlannuzel_sgrain-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a51f93356bd13f8287b20558e0ed590a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 22632,
            "upload_time": "2025-10-14T09:14:38",
            "upload_time_iso_8601": "2025-10-14T09:14:38.210937Z",
            "url": "https://files.pythonhosted.org/packages/57/3c/c3d9f99f2c2449c2cac2103725acd8a7f02de33daa671b48c03b920dca70/nlannuzel_sgrain-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-14 09:14:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nlannuzel",
    "github_project": "sgrain",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "nlannuzel.sgrain"
}
        
Elapsed time: 0.57648s