Please advise what I am doing wrong?
In the accompanying flow, the intention is that a scene is started depending on the lux value. If the lux value is between 30-300, wk_schemer should be selected. However, wk_avond is selected first and only wk_schemer at the next trigger.
// Initialize messages to null
var msg1 = null;
var msg2 = null;
var msg3 = null;
var msg4 = null;
// Initialize context variables if not already defined
context.lux = context.lux || 0;
if (msg.topic == 'lux') {
context.lux = msg.payload; // Store the payload in context.lux
}
var L = context.lux;
// Determine the setup value based on the lux value
if (L >= 600) {
msg1 = { payload: { entity_id: "wk_uit" } };
} else if (L >= 300) {
msg2 = { payload: { entity_id: "wk_dag" } };
} else if (L >= 30) {
msg3 = { payload: { entity_id: "wk_schemer" } };
} else if (L >= 0 ) {
msg4 = { payload: { entity_id: "wk_avond" } };
}
// Return the output messages
return [msg1, msg2, msg3, msg4];