Simplification et amélioration du code NR

Bonjour à tous
Et bonne fête à tous les « PAPA » :grin:

Je souhaite savoir comment modifier le code suivant
Idéalement je souhaite avoir des variables pour les heures le matin et le soir, mais je seches ou dois-je passer par un noeud fonction mais @golfvert disait qu’il était pas fait pour ce type de flow (plus lent)

[{"id":"fc23c5de6e8a71c7","type":"comment","z":"1ca572c6b1d47669","name":"Couloir Entrée - Allumage Mvt","info":"","x":200,"y":880,"wires":[]},{"id":"285085a952d4d5a0","type":"trigger-state","z":"1ca572c6b1d47669","name":"Détection Oeil Couloir","server":"4066b510aa00d654","version":4,"inputs":1,"outputs":4,"exposeAsEntityConfig":"","entityId":"binary_sensor.capt_couloir_occupancy","entityIdType":"exact","debugEnabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"prevEntity","comparatorValue":"state"}],"customOutputs":[{"messageType":"default","messageValue":"","messageValueType":"json","comparatorPropertyType":"current_state","comparatorPropertyValue":"new_state.state","comparatorType":"is","comparatorValue":"on","comparatorValueDataType":"str"},{"messageType":"default","messageValue":"","messageValueType":"json","comparatorPropertyType":"current_state","comparatorPropertyValue":"new_state.state","comparatorType":"is","comparatorValue":"off","comparatorValueDataType":"str"}],"outputInitially":false,"stateType":"str","enableInput":true,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":200,"y":980,"wires":[[],[],["744a1b7cd98e4bd3"],["4c9513ae5550f830"]]},{"id":"744a1b7cd98e4bd3","type":"chronos-filter","z":"1ca572c6b1d47669","name":"06:40 - 07:30 / sunset - 22:30","config":"a36028443f503b53","baseTime":"","baseTimeType":"msgIngress","evaluation":"","evaluationType":"or","conditions":[{"operator":"between","operands":[{"type":"time","value":"06:40","offset":0,"random":false},{"type":"time","value":"07:30","offset":0,"random":false}]},{"operator":"between","operands":[{"type":"sun","value":"sunsetStart","offset":0,"random":false},{"type":"time","value":"22:30","offset":0,"random":false}]}],"x":500,"y":920,"wires":[["e5c19ca414b5a70c"]]},{"id":"2f496fee79ab0553","type":"api-call-service","z":"1ca572c6b1d47669","name":"Couloir spot on","server":"4066b510aa00d654","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.couloir_entree"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":980,"y":920,"wires":[[]]},{"id":"e5c19ca414b5a70c","type":"function","z":"1ca572c6b1d47669","name":"de juin à sept rien le matin","func":"const now = new Date();\nconst day = now.getDay();\nconst month = now.getMonth();\n\n// Les mois sont de 0 (janvier) à 11 (décembre)\nconst isJuneToSeptember = month >= 5 && month <= 8;\nconst isWeekend = day === 0 || day === 6; // 0 pour dimanche, 6 pour samedi\n\nif (isJuneToSeptember && isWeekend && now.getHours() >= 6 && now.getHours() < 12) {\n    // Ne rien faire le matin (entre 06:00 et 12:00) les week-ends de juin à septembre\n    return null;\n}\n\n// Continuer le flux normalement\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":920,"wires":[["2f496fee79ab0553"]]},{"id":"4c9513ae5550f830","type":"api-call-service","z":"1ca572c6b1d47669","name":"Couloir spot off","server":"4066b510aa00d654","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.couloir_entree"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":980,"y":1000,"wires":[[]]},{"id":"4066b510aa00d654","type":"server","name":"HA","version":5,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":": ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"default","statusTimeFormat":"h:m","enableGlobalContextStore":false},{"id":"a36028443f503b53","type":"chronos-config","name":"timecontrol","timezone":"","sunPositions":[]}]

Merci d’avance

1 « J'aime »

Bonjour, si j’ai bien compris pour certains mois à certaines heures ?
Donc le noeud « within time » devrait faire le job.

[https://github.com/rdmtc/node-red-contrib-sun-position/wiki/within-time]

Merci @Ludoc oui il peut faire le job mais question dans ton image, mon souhait serait d’avoir des input.datetime pour le start time et end time

ou une variable sur les offset à voir

Ok, voila comment je récupère des infos dans une fonction, après il faut adapter le traitement suivant ce que tu en fais.

var jardin_t = global.get('homeassistant').homeAssistant.states["sensor.tdegc_h_jardin_temperature"].state;
var salon_t_int = global.get('homeassistant').homeAssistant.states["sensor.tdegc_h_salon_temperature"].state;
var bresser_t_ext = global.get('homeassistant').homeAssistant.states["sensor.bresser_station_meteo_bresser_temperature_exterieure"].state;
var bresser_lux = global.get('homeassistant').homeAssistant.states["sensor.bresser_station_meteo_bresser_luminosite"].state;
var resultat = false;
var azimuth_min = global.get('homeassistant').homeAssistant.states["input_number.azimuth_facade_min"].state;
var azimuth_max = global.get('homeassistant').homeAssistant.states["input_number.azimuth_facade_max"].state;
var azimuth = global.get('homeassistant').homeAssistant.states["sun.sun"].attributes.azimuth;
var seuil_luminosite = global.get('homeassistant').homeAssistant.states["input_number.seuil_luminosite"].state;
var seuil_temperature_salon = global.get('homeassistant').homeAssistant.states["input_number.seuil_temperature_salon"].state;
var seuil_temperature_jardin = global.get('homeassistant').homeAssistant.states["input_number.seuil_temperature_jardin"].state;
var seuil_temperature_jardin_bresser = global.get('homeassistant').homeAssistant.states["input_number.seuil_temperature_jardin_bresser"].state;


if ((azimuth < azimuth_max) 
&& (azimuth > azimuth_min) 
&& (bresser_lux > seuil_luminosite) 
&&  (jardin_t > seuil_temperature_jardin) 
&& (bresser_t_ext > seuil_temperature_jardin_bresser)) {
  resultat = true;
}
else {
  resultat = false;
}

return [{ payload: resultat },
        {payload: seuil_luminosite},
        {payload: seuil_temperature_salon},
        {payload: seuil_temperature_jardin},
        {payload: seuil_temperature_jardin_bresser},
        {payload: resultat},
        {payload: salon_t_int},
        {payload: jardin_t},
        {payload: bresser_t_ext},
        {payload: bresser_lux}];