Hi folks,
I would like to read the status of TEMPO option from the French electricity provider EDF.
The standard way to do it is to call the API with this link :
https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant=2023-03-24
My browser returns the status and JSON parse is ok.
But I can't get an answer with my Shelly Plus 1PM via this script:
Code
let splash = "Start Reading Tempo";
print (splash);
let CONFIG = {
api_endpoint: "https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant=2023-03-24",
switchId: 0, // ID of the switch to control
update_time: 60000, // 1 minute. Update interval in milliseconds
};
let state = null;
let couleur_tempo = null;
function getCouleurTempo() {
Shelly.call(
"http.get",
{
url: CONFIG.api_endpoint,
},
function (response, error_code, error_message) {
if (error_code !== 0) {
print ("getCouleurTempo:", error_message);
return;
}
couleur_tempo = JSON.parse(response.body).data[0]["couleurJourJ"];
print("couleur_tempo:", couleur_tempo);
}
);
}
function changeSwitchState(state) {
if(state === false) {
print("Relay Off!");
} else {
print("Relay On!");
}
Shelly.call(
"Switch.Set",
{
id: CONFIG.switchId,
on: state,
},
function(response, error_code, error_message) {
if (error_code !== 0) {
print("changeSwitchState:", error_message);
return;
}
}
);
}
Timer.set(CONFIG.update_time, true, function (userdata) {
Shelly.call("Sys.GetStatus", {}, function (resp, error_code, error_message) {
if (error_code !== 0) {
print ("Timer:", error_message);
return;
} else {
let hour = resp.time[0] + resp.time[1];
let sep = resp.time[2];
let minute = resp.time[3] + resp.time[4];
let time = hour + sep + minute;
getCouleurTempo();
print(time, couleur_tempo);
if (couleur_tempo === "TEMPO_ROUGE") {
//swith relay on
changeSwitchState(true);
} else {
//swith relay off
changeSwitchState(false);
}
}
});
});
Alles anzeigen
Help welcome