Quick and easy unofficial data endpoints for fetching NEMS (National Electricity Market of Singapore) data
fetch('https://nems.sn.sg/api/status.json')
.then(function(response) { return response.json(); })
.then(function(json) {
console.log(json); // do stuff with the data here
});
import paho.mqtt.subscribe as subscribe
import json
def on_message_print(client, userdata, message):
payload = json.loads(message.payload.decode("utf-8"))
print(payload)
subscribe.callback(on_message_print, "nems/json", hostname="nems.sn.sg")
Most households in Singapore can purchase electricity at wholesale prices from SP, where rates vary every 30 minutes. Wholesale rates are often much cheaper than regular tariffs, but they can occasionally spike due to demand.
This API endpoint provides the price for the current 30-minute block ("USEP"), helping you to understand and make decisions based on how much you are currently paying.
You can build useful automations around this API, for example to charge your vehicles only when the rates are within a favourable threshold, or a load shedding program to turn off non-essential devices during periods of unusually high demand.
The Energy Market Company Singapore is the steward of NEMS data, and this data is sourced from them. For reasons unknown, their official API for USEP data is gated behind Cloudflare, which makes it unusable for most applications.
My two chief concerns with their current arrangement are (1) essential utility data should have already been made public, e.g. via the competent folks at data.gov.sg, and (2) gating data for our critical national infrastructure using foreign services (Cloudflare) raises questions about our sovereignty.
Send a GET request to https://nems.sn.sg/api/status.json, and get a JSON response that looks like this
{"updated": 1776225660, "usep": 171.97, "demand": 6940.0, "vcp": 198.17}Access control origin headers are automatically inserted to make integration easier.
Connect to nems.sn.sg and subscribe to the nems/json topic. The JSON layout is identical to the above HTTP response.
The USEP value can be directly retrieved from the nems/usep topic, which should make it easier to consume this API on embedded devices (e.g. esp32, arduinos) without having to bring along a JSON parser.
All topics have persistence enabled, so your client will automatically receive the last published values when connecting to a topic.
This is a free, scrappy side project, so expect the availability to be around nine fives. I endeavour to keep it up since I'm using this endpoint myself, but bear in mind that it can go down anytime for any reason.
There are no rate limits, and no authentication is required. Please try to be nice as this API endpoint runs off a "cheap" US$4/month digitalocean server.
The API data is provided as-is. If you are planning to build a commercial product using this service, I strongly recommend mirroring this service in case it goes down.
The best way to reach me is probably though mastodon (twitter for nerds)