Un tuto non car ca depand bcp de ton niveau de node red et javascript, hacf etc et selon il y aurait trop de trucs a mettre
Mais je peux te filer la function de NR que j’ai mise et le bout de javascript que j’ai changé dans le js de la carte et je te previens je suis pas un developpeur fou donc le code n’est surement pas optimisé ni bien ecrit lol
Sous NR voila la fonction
Tu recupere le sensor et tu en crée un nouveau comme cela
Attention c’est valable uniquement pour 24h sur le principe car je n’ai pas les infos de levé et couché du soleil a plus de 24h
Et pour mon besoin j’ai fait que sur les 9h glissante a toi d’adapter si tu veux plus
Pour les icones nuit j’en ai que 3 au final avec une lune qui est nuit clair, partiellement nuageux et venteux
Les autres il y avait pas de diff entre le jour et la nuit
var forecast = msg.payload.attributes.forecast;
var contextHA = global.get('homeassistant');
var sunrise = new Date(contextHA.homeAssistant.states["sun.sun"].attributes.next_rising);
var sunset = new Date(contextHA.homeAssistant.states["sun.sun"].attributes.next_setting);
var nuit = contextHA.homeAssistant.states["sun.sun"].state;
var datetime0 = new Date(forecast[0].datetime);
var datetime1 = new Date(forecast[1].datetime);
var datetime2 = new Date(forecast[2].datetime);
var datetime3 = new Date(forecast[3].datetime);
var datetime4 = new Date(forecast[4].datetime);
var datetime5 = new Date(forecast[5].datetime);
var datetime6 = new Date(forecast[6].datetime);
var datetime7 = new Date(forecast[7].datetime);
var datetime8 = new Date(forecast[8].datetime);
var datetime9 = new Date(forecast[9].datetime);
if(nuit === "below_horizon"){
if(datetime0 < sunrise) {
if(msg.payload.attributes.forecast[0].condition === "partlycloudy"){
msg.payload.attributes.forecast[0].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[0].condition === "windy-variant"){
msg.payload.attributes.forecast[0].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[0].condition === "sunny"){
msg.payload.attributes.forecast[0].condition = "sunnynight";
}
}
if(datetime1 < sunrise) {
if(msg.payload.attributes.forecast[1].condition === "partlycloudy"){
msg.payload.attributes.forecast[1].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[1].condition === "windy-variant"){
msg.payload.attributes.forecast[1].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[1].condition === "sunny"){
msg.payload.attributes.forecast[1].condition = "sunnynight";
}
}
if(datetime2 < sunrise) {
if(msg.payload.attributes.forecast[2].condition === "partlycloudy"){
msg.payload.attributes.forecast[2].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[2].condition === "windy-variant"){
msg.payload.attributes.forecast[2].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[2].condition === "sunny"){
msg.payload.attributes.forecast[2].condition = "sunnynight";
}
}
if(datetime3 < sunrise) {
if(msg.payload.attributes.forecast[3].condition === "partlycloudy"){
msg.payload.attributes.forecast[3].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[3].condition === "windy-variant"){
msg.payload.attributes.forecast[3].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[3].condition === "sunny"){
msg.payload.attributes.forecast[3].condition = "sunnynight";
}
}
if(datetime4 < sunrise) {
if(msg.payload.attributes.forecast[4].condition === "partlycloudy"){
msg.payload.attributes.forecast[4].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[4].condition === "windy-variant"){
msg.payload.attributes.forecast[4].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[4].condition === "sunny"){
msg.payload.attributes.forecast[4].condition = "sunnynight";
}
}
if(datetime5 < sunrise) {
if(msg.payload.attributes.forecast[5].condition === "partlycloudy"){
msg.payload.attributes.forecast[5].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[5].condition === "windy-variant"){
msg.payload.attributes.forecast[5].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[5].condition === "sunny"){
msg.payload.attributes.forecast[5].condition = "sunnynight";
}
}
if(datetime6 < sunrise) {
if(msg.payload.attributes.forecast[6].condition === "partlycloudy"){
msg.payload.attributes.forecast[6].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[6].condition === "windy-variant"){
msg.payload.attributes.forecast[6].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[6].condition === "sunny"){
msg.payload.attributes.forecast[6].condition = "sunnynight";
}
}
if(datetime7 < sunrise) {
if(msg.payload.attributes.forecast[7].condition === "partlycloudy"){
msg.payload.attributes.forecast[7].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[7].condition === "windy-variant"){
msg.payload.attributes.forecast[7].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[7].condition === "sunny"){
msg.payload.attributes.forecast[7].condition = "sunnynight";
}
}
if(datetime8 < sunrise) {
if(msg.payload.attributes.forecast[8].condition === "partlycloudy"){
msg.payload.attributes.forecast[8].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[8].condition === "windy-variant"){
msg.payload.attributes.forecast[8].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[8].condition === "sunny"){
msg.payload.attributes.forecast[8].condition = "sunnynight";
}
}
if(datetime9 < sunrise) {
if(msg.payload.attributes.forecast[9].condition === "partlycloudy"){
msg.payload.attributes.forecast[9].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[9].condition === "windy-variant"){
msg.payload.attributes.forecast[9].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[9].condition === "sunny"){
msg.payload.attributes.forecast[9].condition = "sunnynight";
}
}
}else{
if(datetime0 > sunset) {
if(msg.payload.attributes.forecast[0].condition === "partlycloudy"){
msg.payload.attributes.forecast[0].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[0].condition === "windy-variant"){
msg.payload.attributes.forecast[0].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[0].condition === "sunny"){
msg.payload.attributes.forecast[0].condition = "sunnynight";
}
}
if(datetime1 > sunset) {
if(msg.payload.attributes.forecast[1].condition === "partlycloudy"){
msg.payload.attributes.forecast[1].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[1].condition === "windy-variant"){
msg.payload.attributes.forecast[1].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[1].condition === "sunny"){
msg.payload.attributes.forecast[1].condition = "sunnynight";
}
}
if(datetime2 > sunset) {
if(msg.payload.attributes.forecast[2].condition === "partlycloudy"){
msg.payload.attributes.forecast[2].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[2].condition === "windy-variant"){
msg.payload.attributes.forecast[2].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[2].condition === "sunny"){
msg.payload.attributes.forecast[2].condition = "sunnynight";
}
}
if(datetime3 > sunset) {
if(msg.payload.attributes.forecast[3].condition === "partlycloudy"){
msg.payload.attributes.forecast[3].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[3].condition === "windy-variant"){
msg.payload.attributes.forecast[3].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[3].condition === "sunny"){
msg.payload.attributes.forecast[3].condition = "sunnynight";
}
}
if(datetime4 > sunset) {
if(msg.payload.attributes.forecast[4].condition === "partlycloudy"){
msg.payload.attributes.forecast[4].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[4].condition === "windy-variant"){
msg.payload.attributes.forecast[4].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[4].condition === "sunny"){
msg.payload.attributes.forecast[4].condition = "sunnynight";
}
}
if(datetime5 > sunset) {
if(msg.payload.attributes.forecast[5].condition === "partlycloudy"){
msg.payload.attributes.forecast[5].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[5].condition === "windy-variant"){
msg.payload.attributes.forecast[5].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[5].condition === "sunny"){
msg.payload.attributes.forecast[5].condition = "sunnynight";
}
}
if(datetime6 > sunset) {
if(msg.payload.attributes.forecast[6].condition === "partlycloudy"){
msg.payload.attributes.forecast[6].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[6].condition === "windy-variant"){
msg.payload.attributes.forecast[6].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[6].condition === "sunny"){
msg.payload.attributes.forecast[6].condition = "sunnynight";
}
}
if(datetime7 > sunset) {
if(msg.payload.attributes.forecast[7].condition === "partlycloudy"){
msg.payload.attributes.forecast[7].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[7].condition === "windy-variant"){
msg.payload.attributes.forecast[7].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[7].condition === "sunny"){
msg.payload.attributes.forecast[7].condition = "sunnynight";
}
}
if(datetime8 > sunset) {
if(msg.payload.attributes.forecast[8].condition === "partlycloudy"){
msg.payload.attributes.forecast[8].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[8].condition === "windy-variant"){
msg.payload.attributes.forecast[8].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[8].condition === "sunny"){
msg.payload.attributes.forecast[8].condition = "sunnynight";
}
}
if(datetime9 > sunset) {
if(msg.payload.attributes.forecast[9].condition === "partlycloudy"){
msg.payload.attributes.forecast[9].condition = "partlycloudynight";
}
if(msg.payload.attributes.forecast[9].condition === "windy-variant"){
msg.payload.attributes.forecast[9].condition = "windy-variantnight";
}
if(msg.payload.attributes.forecast[9].condition === "sunny"){
msg.payload.attributes.forecast[9].condition = "sunnynight";
}
}
}
return msg;
Le bout de javascript que j’ai changé
ce qu’il y a entre quote doit correspondre au nom de ton fichier icon sans l’extension
donc tu adapte selon les icones que tu as
Pour que ca marche tu dois enlever aussi le js.gz sinon il est loadé par defaut dans le repertoire de la carte
Attention si tu y touche et que tu reinstalle la carte tes modifs seront perdu
const weatherIconsDay = {
clear: "CLEAR_DAY",
"clear-night": "CLEAR_NIGHT",
sunnynight: "CLEAR_NIGHT",
cloudy: "CLOUDY_2",
fog: "FOG_2",
hail: "HEAVY_RAIN",
lightning: "LIGHT_HAZE",
"lightning-rainy": "LIGHT_RAIN",
partlycloudy: "PARTLY_CLOUDY_DAY",
partlycloudynight: "PARTLY_CLOUDY_NIGHT",
"windy-variantnight": "PARTLY_CLOUDY_NIGHT",
pouring: "MODERATE_RAIN",
rainy: "LIGHT_RAIN",
snowy: "HEAVY_SNOW",
"snowy-rainy": "MODERATE_SNOW",
sunny: "CLEAR_DAY",
windy: "WIND",
"windy-variant": "WIND",
exceptional: "!!",
};
const weatherIconsNight = {
...weatherIconsDay,
clear: "CLEAR_NIGHT",
sunny: "CLEAR_NIGHT",
partlycloudy: "PARTLY_CLOUDY_NIGHT",
"windy-variant": "PARTLY_CLOUDY_NIGHT",
};