Subtract 5minuts from a time out of a state node

Hello,

This is my first post on this forum. I’m rather new to nodered and looked at severall youtube tutorials, but can’t find the answer on my problem.

I’m creating a flow in what has to do the following:

  • When i change my alarm on my mobile it has to get the wakeup time;
  • After this it has to subtract 5minuts of the set time;
  • On the time minus 5minuts i want to have my lights go on, on 40%;
  • On the set time the lights go brighter on 70%.

I catch the new alarm time with a state node, and it looks like:

How can i use the newly set time (“attributes”:{“Local Time”:“Sat Mar 06 05:10:00 GMT+01:00 2021”) and subtract the 5 minuts of of it, to turn the light on on the subtracted time?
Hoping someone could give me some plain and simpel examples.

Thanks in advance

Have you looked at the time node? https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/time.html

You could have two nodes one with an offset -5 that turns on the lights to 40% and one without an offset that turns the lights on to 70%.

Im using this flow for years now, and works fine:

[
    {
        "id": "5fd4bf94.3d203",
        "type": "join",
        "z": "1de400c0.5ce76f",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 810,
        "y": 180,
        "wires": [
            [
                "3baa06b3.7b18fa"
            ]
        ]
    },
    {
        "id": "3baa06b3.7b18fa",
        "type": "function",
        "z": "1de400c0.5ce76f",
        "name": "Compare Times",
        "func": "newmsg = {};\nif (msg.payload[0] == msg.payload[1]) {\n    newmsg.payload = \"True\";\n} else {\n    newmsg.payload = \"False\";\n}\n\nreturn newmsg;",
        "outputs": 1,
        "noerr": 0,
        "x": 960,
        "y": 180,
        "wires": [
            [
                "69f8941b.a2457c"
            ]
        ]
    },
    {
        "id": "69f8941b.a2457c",
        "type": "switch",
        "z": "1de400c0.5ce76f",
        "name": "Is it Time?",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "True",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 1120,
        "y": 180,
        "wires": [
            [
                "1123ea0c.e5c056"
            ]
        ]
    },
    {
        "id": "cb3ff133.0f556",
        "type": "api-current-state",
        "z": "1de400c0.5ce76f",
        "name": "Get Alarm Time",
        "server": "2fba4297.e4145e",
        "version": 1,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": true,
        "entity_id": "input_datetime.alarm",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 460,
        "y": 120,
        "wires": [
            [
                "ed1570d4.2671d"
            ]
        ]
    },
    {
        "id": "ed1570d4.2671d",
        "type": "moment",
        "z": "1de400c0.5ce76f",
        "name": "Alarm - 10min",
        "topic": "",
        "input": "payload",
        "inputType": "msg",
        "inTz": "Europe/Berlin",
        "adjAmount": "10",
        "adjType": "minutes",
        "adjDir": "subtract",
        "format": "YYYY-MM-DD HH:mm",
        "locale": "C",
        "output": "payload",
        "outputType": "msg",
        "outTz": "Europe/Berlin",
        "x": 640,
        "y": 120,
        "wires": [
            [
                "5fd4bf94.3d203"
            ]
        ]
    },
    {
        "id": "c2b4d347.fde2",
        "type": "moment",
        "z": "1de400c0.5ce76f",
        "name": "Current Time",
        "topic": "",
        "input": "payload",
        "inputType": "msg",
        "inTz": "Europe/Berlin",
        "adjAmount": "0",
        "adjType": "minutes",
        "adjDir": "subtract",
        "format": "YYYY-MM-DD HH:mm",
        "locale": "C",
        "output": "payload",
        "outputType": "msg",
        "outTz": "Europe/Berlin",
        "x": 630,
        "y": 180,
        "wires": [
            [
                "5fd4bf94.3d203"
            ]
        ]
    },
    {
        "id": "2fba4297.e4145e",
        "type": "server",
        "name": "Home Assistant",
        "legacy": false,
        "addon": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true
    }
]