[dzVents] EDF Tempo (France): today/tomorrow colour, red-day risk at D+2, red days left – free JSON API, no key

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

Post Reply
JeanPierreTempo
Posts: 2
Joined: Friday 16 October 2026 16:19
Target OS: Linux
Domoticz version:
Contact:

[dzVents] EDF Tempo (France): today/tomorrow colour, red-day risk at D+2, red days left – free JSON API, no key

Post by JeanPierreTempo »

Hi all,

For those of you in France on the EDF Tempo tariff, here is a dzVents script that keeps the Tempo colour in Domoticz and warns you when a red day is coming. In full transparency: calendrier-tempo.fr is an independent project I run, a free site (not affiliated with EDF or RTE), and the script uses its API. No account, no token, no API key.

What it does:
  • 2 Alert sensors: today's and tomorrow's official colour (green = BLEU, yellow = BLANC, red = ROUGE, grey while tomorrow is not published yet)
  • 1 Percentage sensor: probability of a red day at D+2 (forecast)
  • 1 Custom sensor: red days left in the season
  • A Domoticz notification (once per date) when the D+2 red risk reaches 50 % (adjustable)
Endpoints used (all JSON, GET):
  • /api/today and /api/tomorrow: {"status":"ok","date":"2026-10-17","couleur":"BLEU","code":1}; status is "unavailable" until tomorrow's colour is published
  • /api/predictions: day-by-day forecast up to D+15, with probabilite_bleu / probabilite_blanc / probabilite_rouge
  • /api/remaining: days left per colour in the season
Today's and tomorrow's colours are the official ones, as soon as EDF/RTE confirm them. What the API adds is the D+2 to D+15 forecast, and it is only a forecast: the published colour is what counts.

Code: Select all

-- EDF Tempo (France): today's and tomorrow's colour, red-day risk at D+2,
-- red days left. Source: free JSON API of calendrier-tempo.fr (no key)
-- Put the name (or idx) of your devices, or nil to skip one.
local DEVICES = {
	today    = 'Tempo today',             -- Alert sensor
	tomorrow = 'Tempo tomorrow',           -- Alert sensor
	redRiskD2 = 'Tempo red risk D+2', -- Percentage sensor
	redLeft  = 'Tempo red days left',  -- Custom sensor
}
local NOTIFY_THRESHOLD = 50 -- notify if red risk at D+2 >= 50 % (nil = never)

local API = 'https://www.calendrier-tempo.fr/api/'
local LEVEL = { BLEU = 'ALERTLEVEL_GREEN', BLANC = 'ALERTLEVEL_YELLOW', ROUGE = 'ALERTLEVEL_RED' }

return {
	on = {
		timer = { 'every 30 minutes' },
		httpResponses = { 'tempo_today', 'tempo_tomorrow', 'tempo_remaining', 'tempo_predictions' },
	},
	data = { lastNotified = { initial = '' } },
	logging = { marker = 'Tempo' },
	execute = function(domoticz, item)

		local function device(key)
			if DEVICES[key] then return domoticz.devices(DEVICES[key]) end
		end

		-- Update an Alert sensor only when the value changes
		local function setAlert(d, level, text)
			if d and (d.text ~= text or d.color ~= level) then
				d.updateAlertSensor(level, text)
			end
		end

		if item.isTimer then
			for _, route in ipairs({ 'today', 'tomorrow', 'remaining', 'predictions' }) do
				domoticz.openURL({ url = API .. route, callback = 'tempo_' .. route })
			end
			return
		end

		if not (item.ok and item.isJSON and item.json and item.json.status) then
			domoticz.log('No usable response for ' .. item.trigger ..
				' (HTTP ' .. tostring(item.statusCode) .. ')', domoticz.LOG_ERROR)
			return
		end
		local j = item.json

		if item.trigger == 'tempo_today' or item.trigger == 'tempo_tomorrow' then
			local isTomorrow = (item.trigger == 'tempo_tomorrow')
			local d = device(isTomorrow and 'tomorrow' or 'today')
			if j.status == 'ok' and LEVEL[j.couleur] then
				setAlert(d, domoticz[LEVEL[j.couleur]], j.couleur)
			else
				-- /api/tomorrow returns "unavailable" until the colour is published
				setAlert(d, domoticz.ALERTLEVEL_GREY, isTomorrow and 'Not published yet' or 'Unknown')
			end

		elseif item.trigger == 'tempo_remaining' then
			local d = device('redLeft')
			if d and j.status == 'ok' and j.remaining then
				d.updateCustomSensor(j.remaining.ROUGE)
			end

		elseif item.trigger == 'tempo_predictions' and j.status == 'ok' then
			-- The list starts today; look for the D+2 date
			local t = os.date('*t')
			local dateD2 = os.date('%Y-%m-%d', os.time({ year = t.year, month = t.month, day = t.day + 2, hour = 12 }))
			for _, p in ipairs(j.predictions or {}) do
				if p.date == dateD2 and tonumber(p.probabilite_rouge) then
					local risk = math.floor(100 * p.probabilite_rouge + 0.5)
					local d = device('redRiskD2')
					if d then d.updatePercentage(risk) end
					if NOTIFY_THRESHOLD and risk >= NOTIFY_THRESHOLD and domoticz.data.lastNotified ~= dateD2 then
						domoticz.notify('Tempo', 'Red day likely on ' .. dateD2 ..
							' (risk ' .. risk .. ' %, forecast)', domoticz.PRIORITY_HIGH)
						domoticz.data.lastNotified = dateD2
					end
				end
			end
		end
	end
}
Setup:
  1. Setup > Hardware: add a "Dummy (Does nothing, use for virtual switches only)" hardware, e.g. named Tempo.
  2. Click "Create Virtual Sensors" on it: two Alert sensors ("Tempo today", "Tempo tomorrow"), one Percentage ("Tempo red risk D+2") and one Custom sensor ("Tempo red days left", axis label: days).
  3. Setup > More Options > Events: new dzVents script, paste the code, check the device names at the top (idx works too, or nil to skip one), tick "Event active" and save.
The Alert sensor text stays BLEU, BLANC or ROUGE, so other scripts can simply test domoticz.devices('Tempo tomorrow').text == 'ROUGE' (e.g. to lower the heating set point). The notification uses whatever notification systems you already configured in Domoticz. One request every 30 minutes is plenty: responses are cached for 2 minutes on our side.

All fields are documented here: https://calendrier-tempo.fr/api-tempo
Data is CC BY 4.0, and every past forecast is published next to the real colour, errors included: https://calendrier-tempo.fr/historique-previsions

Feedback, bug reports or ideas for other fields are very welcome.

Jean-Pierre
https://calendrier-tempo.fr
User avatar
JeanBonnot
Posts: 13
Joined: Tuesday 22 October 2019 17:22
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.2
Location: France
Contact:

Re: [dzVents] EDF Tempo (France): today/tomorrow colour, red-day risk at D+2, red days left – free JSON API, no key

Post by JeanBonnot »

Bonjour Jean-Pierre et merci pour ton travail. Tu écris utiliser les données météo, utilises-tu l'historique tempo (données depuis sa création) croisé avec les archives météo pour déterminer ton d+x ?
User avatar
jvdz
Posts: 2482
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: [dzVents] EDF Tempo (France): today/tomorrow colour, red-day risk at D+2, red days left – free JSON API, no key

Post by jvdz »

@JeanBonnot, could you please post in English?
Tnx.
Post Reply