Node-Red schedulers control more then one topic

Hello
I have a home assistant here, ESPhome, Node-Red, mqtt installation.
I’m a complete beginner and just learning how to use it.
My first Node-Red steps where I can switch LEDs via mqtt on the ESPhome device works.
I have 3 different LEDs there, all of which can be dimmed via PWM.
I would now like to switch all 3 of them on/off automatically and dim each one later.
I wanted to use a scheduler like the light-scheduler or BigTimer for time-controlled ON/OFF switching.

but I only find 1 topic in it… I can only switch 1 LED with a scheduler.

What else do I need? or what is best suited for this?

a function node?

Example: Node Red
3x different switches (on, off, auto) ====> Scheduler ===> Dispatcher or function send 3 different topics to the ESP ===> mqtt-out

have you any good tip for me?

best regards
Achim

With NodeRed it is easy to have multiple output by just dragging more flow lines.
This will send a msg to each of the nodes that will then run as separate flows.

The important thing to remember then is that merging flows is a lot harder, because the flows is separate, so even if two or more flow lines go into the same input of a node, then it will be treated as separate flows one after each other.
There is a merge node to merge then again, but there are so many pitfalls that you need to avoid, so be careful with that node.

Take a look at the function node. In this you can write a javascript function to generate as many mqtt messages as you like. They can all exit via the same flow path or you can have multiple outputs. You can have a different topic for each or all the same.

2 Likes

sorry maybe i describe it wrong.
I need exactly this ==> cron-plus
because i need different topics…
and sometimes i have for all different the same on/off time, but sometimes i need different on/off times für any topic.
In cron-plus is that perfect… i test it now and works exactly what i looking for
BUT… a Card like from Lovelace or any oother … i think is not possible to get this
or?
Because if i have to change any time or any date then i have to use Node-red… but later i would like change the on/off Time on my dashboard in HA

Yes, like a function
is this possible in a function

  1. if come ID7 then use the payload from this ID7 and send all to the ID7_Topic

now i install in Node-Red already cron-plus and test it… that is exactly what i need
i can use any sek, min, hour, day, month, year and add this to any topic
i can add the xx different topics with xx diferent ON/Off times , with different payloads

The reason is.
I would like to have a system later in which I
can say
Turn on lamp 1, at 70% brightness on June 01, 2023 at 12:00 p.m. and off at 2:00 a.m. Repeat until September 3rd.
Exactly that, for example, but then for 10 different lamps. So far I’ve only seen cron-plus which can do this 80% of the time. That’s very good.
but I can’t find a card for this, e.g. from Lovelace, like a scheduler where I can later change the times or something else comfortably on the dashboard. I always have to go to Node-red for this

is this possible in a function

  1. if come ID7 then use the payload from this ID7 and send all to the ID7_Topic

Yes. For example, here is a function which sends 3 mqtt messages, each to a separate output connector. There are three different topics and payloads, and all are specified within the node.

It also logs a message to the HA Node-RED log so I can trace the event.

function randomInt(min, max) { 
  return Math.floor(Math.random() * (max - min + 1) + min)
}

var altmsgs = [
    "Warm living room climate",
    "Nice and warm",
    "Warm all day"
]
const voicemsg = altmsgs[randomInt(0, altmsgs.length-1)]
const voicelang = "en"
var speech = {
    "say": voicemsg,
    "language": voicelang,
    "targets": msg.payload.targets
}

node.log("Living room: " + voicemsg + " (" + voicelang + ")")

let devSettings = global.get("devSettings");
let valveName1 = 'valve/tuya/unit3'; // TRV by wall
let topic1 = `z2m/${valveName1}/set`;
let valveName2 = 'valve/tuya/unit4'; // TRV by window
let topic2 = `z2m/${valveName2}/set`;
var radSettings1 = {
    "local_temperature_calibration": devSettings[valveName1]['calibration'] || 0,
    "window_detection": "OFF",
    "preset": "programming",
    "programming_mode":
        "07:00/22°C  12:30/22°C  16:30/22°C  21:00/7°C  " + /* Weekdays */
        "07:00/22°C  12:30/22°C  16:30/22°C  21:00/7°C  " + /* Saturday */
        "07:00/22°C  12:30/22°C  16:30/22°C  21:00/7°C"     /* Sunday */
}
var radSettings2 = {
    "local_temperature_calibration": devSettings[valveName2]['calibration'] || 0,
    "window_detection": "OFF",
    "preset": "programming",
    "programming_mode":
        "07:00/22°C  12:30/22°C  16:30/22°C  21:00/7°C  " + /* Weekdays */
        "07:00/22°C  12:30/22°C  16:30/22°C  21:00/7°C  " + /* Saturday */
        "07:00/22°C  12:30/22°C  16:30/22°C  21:00/7°C"     /* Sunday */
}

return [
    { topic: 'vmsg/speak', payload: speech },
    { topic: topic1, payload: radSettings1 },
    { topic: topic2, payload: radSettings2 },
];
1 Like

Thank’s a lot for the perfect sample. Thats help me to understand much more about node-red.

Best regards
Achim