Logical AND of multi timer outputs?

I have 8 timers each with different topics 1-8. I would like to select either 1 to 8 of them to an MQTT output.

Why? you ask. It's a flow that extracts the cheapest 1-8 of Octopus Agile's half hour tariff prices and would like to select from 1 to 8 of the half hour slots.

It's basically a 'selector' switch I need with 1 to 8 AND inputs (eg payload = 4 would select outputs from 1,2,3 and 4 timers)

Any ideas ?

I have a flow like this I use to read agile rates and progromatically select the times I want to charge the car:

chrome_YPGRSPFRig

It uses the dynamic features of node-red-contrib-cron-plus + Dashboard 2 (the new dashboard) to set dynamic schedules that will "fire" then the times arrives. It also withstands node-red restarting (since cron-plus has a persistence option)

Could easily be adapted to send MQTT events.

Like wise, here is a more basic dashboard-1 demo using cron plus to schedule as many timers as your heart desires: Dynamic cron schedules / timers via dashboard control (flow) - Node-RED

Thanks, The flow I have is below I cheated with ChatGPT.
I have flows for below zero and 1-8 concurrent slots but not 'pick & mix'. I don't have an EV or battery BTW.

[
    {
        "id": "4edd8a32df48bde5",
        "type": "http request",
        "z": "fb5d1b09bd1d48f7",
        "name": "Fetch Octopus Agile Rates",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "https://api.octopus.energy/v1/products/AGILE-FLEX-22-11-25/electricity-tariffs/E-1R-AGILE-FLEX-22-11-25-L/standard-unit-rates/",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 160,
        "y": 160,
        "wires": [
            [
                "27b594f07da3e4b0"
            ]
        ]
    },
    {
        "id": "27b594f07da3e4b0",
        "type": "function",
        "z": "fb5d1b09bd1d48f7",
        "name": "Extract, Filter, and Sort Rates",
        "func": "let rates = msg.payload.results;\n\n// Get today's date in ISO format (YYYY-MM-DD)\nlet today = new Date().toISOString().split('T')[0];\n\n// Filter rates to include only today's data\nlet todayRates = rates.filter(item => {\n    return item.valid_from.startsWith(today);\n});\n\n// Extract date, time, and rate information\nlet extractedRates = todayRates.map(item => {\n    return {\n        start: item.valid_from,\n        end: item.valid_to,\n        price: item.value_inc_vat\n    };\n});\n\n// Sort by price ascending\nextractedRates.sort((a, b) => a.price - b.price);\n\n// Select the cheapest 8 slots\nlet cheapestSlots = extractedRates.slice(0, 8);\n\nmsg.payload = { cheapestSlots };\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 160,
        "y": 200,
        "wires": [
            [
                "6eb0647a1423c752",
                "e5339d3b84a35d3f",
                "3a221bf4d367eed1",
                "7a881d4cdf467081",
                "4db46119da30f8bc",
                "7cbfefd0ac2f9c78",
                "0f54e1e4ca44e6d0",
                "4e9571b3c493f61e",
                "58da76b61fb8ba05"
            ]
        ]
    },
    {
        "id": "a7d8e3db27d611a8",
        "type": "inject",
        "z": "fb5d1b09bd1d48f7",
        "name": "Fetch Data",
        "props": [],
        "repeat": "",
        "crontab": "00 00 * * *",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 110,
        "y": 120,
        "wires": [
            [
                "4edd8a32df48bde5"
            ]
        ]
    }
]

Can you share that flow @Steve-Mcl?

My Octopus smart meter just landed, now I have to see what I can do with the available data.

I'll need to clean it up and I'm afk for the evening. I'll try to remember to respond tomorrow.

Don't be afraid to prod me for a response if I don't respond within 24h

1 Like

Not cleaned up as much as I'd like but it is usable (I think)

agile-dynamic-cron-plus.json (79.4 KB)

1 Like

@Steve-Mcl Did you use AI for any of the flow ?

No, I dont think so. Certainly not for the node generation since it often generates bad flow configs. May have asked GPT for help with the vuetify template but I dont think I used AI at all for this.

Why do you ask?

FYI

If you generate node-red flows using AI, they often have wrong or old or bad props in the JSON that well behaved/well written nodes wont mind, but you can get funky behaviour.

My 2¢

If you do often use AI, please only use it to help you write JS/JSON/HTML/VUE etc, NOT to generate FLOWS. and if you do, please dont share them on here (since AI will be reinforced with bad JSON flow data - and so begins the downfall of LLMs :wink: )

Just some of your flow looked AI ish. I just use to get an idea then mod it as needed. Agreed, some AI is appalling bad and some is well written but you need be able to tell the difference. I try to keep everything in a single function but that approach can make it difficult to remember/edit what and how I did it !

I'm just that good :joy:

(or that bad :wink: )

FWIW, Node-RED is my day job and hobby (I work for Flowfuse.com) and i have written several well known/well used Node-RED nodes - so I am fairly well versed :wink:

A human LLM :wink:

1 Like

In that case don't do it. The two most important things in IT development are

  1. It works
  2. It is understandable and maintainable (OK, the three most important things ...)

Run time efficiency (if that is what you are worried about) is almost always way, way down the list of priorities.

I come from a Z80 and 6502 assembler days with <1k of memory so size mattered or lack of.

I come from even before that, and then it did matter, but now it rarely rarely does.